cgrothaus
Mix/Ecto equivalent of `rails db:prepare`? (migrate db OR create and seed it)
Ruby on Rails has a rails db:prepare command. It migrates the database, if it exists, else it creates it, migrates it (or loads the schema, but that’s only a subtle difference) and seeds it. See Rails 6 adds rails db:prepare to migrate or setup a database - BigBinary Blog for more info.
I am wondering: does Phoenix have a similar command?
I know that a freshly generated Phoenix 1.7 app defines a mix alias ecto.setup in the mix.exs file, which does "ecto.create", "ecto.migrate", "run priv/repo/seeds.exs", that it is the latter part of what Rails does. But this is neither checking for db existence first, nor is it idempotent.
Marked As Solved
cgrothaus
FTR: my solution Patterns for making seeds idempotent? - #5 by cgrothaus.
Also Liked
hauleth
ecto.create is idempotent, ecto.migrate is also idempotent. To make seeding script idempotent you need to do it on your own, for Ecto it is just a simple script that you run within your application context, so it will be as idempotent as you write it to be.







