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
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.
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









