Onor.io

Onor.io

Windows Powershell Script To Reset An Ecto DB

For those few of us that work on Elixir on Windows, here’s a little utility powershell script I hacked together to reset my database. I constantly had to reset both dev and test so I set up the script such that I could pass the environment to be reset on the command line. Hope others may find this helpful:

param([string]$environment="test") #default to test environment

if($environment -eq "prod"){
   Throw "You cannot run this script against the prod evironment. You must initialize prod manually"
}

$env:MIX_ENV = $environment
mix ecto.drop
mix ecto.create
mix ecto.migrate
Remove-Item Env:\MIX_ENV #Reset the environment setting.

You would use it like so: ./dbinit dev or ./dbinit test

First Post!

OvermindDL1

OvermindDL1

You can also do it all completely within mix by writing a little mix task that sets the mix environment even then you could have an alias set it to dev, reset, then set it to test and reset again if you want for a meta-resetter.

I would personally still just do:

mix ecto.reset
MIX_ENV=test mix ecto.reset

Maybe alias it like:

alias ecto-reset='mix ecto.reset; MIX_ENV=test mix ecto.reset'

Or via the New-Alias command in powershell however it works.

Yes I work on elixir on Windows at work (debian at home) too… >.>
I installed bash though.

Where Next?

Popular in Announcing Top

OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 12560 134
New
cjen07
parameterized pipe in elixir: |n> edit: negative index in |n> and mixed usage with |> are supported example: use ParamPipe ...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement