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"]

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.

1 Like

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:

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.

1 Like

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.