data-migrate
data-migrate copied to clipboard
Providing `db:prepare` integration
Hi and thanks for this beautiful library.
In our company we rely on db:prepare
task to maintain devs' databases state. This task basically migrates an existing database, or creates a database, migrates or loads its schema from a file and then seeds it if the database did not exist when the task was invoked.
I couldn't find db:prepare:with_data
, is there an equivalent task?
I'm also using this in a docker_entrypoint.sh
, so that if the container is new, the DB gets created, and if not, it's migrated. But, that doesn't run db:migrate:with_data
, it just runs db:migrate
. Then after that, I run data:migrate
. Unfortunately in some cases (like fixing up data before applying a unique index to a field, which is what I'm trying to do at the moment), this ordering doesn't work. Having db:prepare:with_data
would be the perfect solution to this.
Edit: I've just realised, db:prepare
is also used by the standard rails bin/setup
script, so having a db:prepare:with_data
option that could be dropped in there would make that work seamlessly too.
I have an idea... I think if we created a new prepare task, then override the default migrate task within it to run migrate with data, that might be a really light tough way of doing this. https://stackoverflow.com/a/8116584
I'll have a try later on.
That idea didn't pan out, unfortunately - the built in prepare task doesn't actually invoke the other Rake tasks, it's all done in Ruby code: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/tasks/database_tasks.rb#L176
I've opened a PR in #274 that adds this task - seems to work well for me, though I've only tested it with my own use case so far.
any news about this? it's really needed