fireproofsocks
Is it dangerous to drop/create your database during mix test?
In my mix.exs I have set up the following during development:
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.drop", "ecto.create", "ecto.migrate", "run priv/repo/test_seeds.exs", "test"]
]
end
2 things to notice: 1) I drop my test database and re-create it for test runs because 2) I have a set of seeds that I use only for the tests. I know, I could have used fixtures to do that, but it got really onerous with highly-interrelated data, so I thought it would be easier to just have a seed file with my “curated” boilerplate test data.
Then I had this horrible thought: what if I tried to run tests on production? How does mix know which environment you’re in when running the mix tasks? Is what I’ve done bad form?
Thanks as always for pointers/feedback.
Most Liked
benwilson512
As noted by @i-n-g-m-a-r it’s real easy to not worry about it if you don’t even have mix in production. It’s also a good idea to revoke your production database user’s ability to delete databases in general.
i-n-g-m-a-r
Probably you don’t want to run anything “manually” on production.
To minimize the risk of making a (critical) mistake,
it’s better to automize deployment which includes testing on a machine other than production.
Github, Gitlab and others (Wercker, …) provide tools to accomplish this (CI/CD).
Together with Docker and Distillery:
https://github.com/bitwalker/distillery
It’s a very real concern you have.
You’ll sleep a lot better when you have the right tooling set up for your application.
Popular in Questions
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
- #code-sync
- #javascript
- #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








