data-migrate icon indicating copy to clipboard operation
data-migrate copied to clipboard

Possible bug around db:reset

Open etherbob opened this issue 3 years ago • 2 comments

Apologies in advance if I missed something in the docs, but I didn't see anything about this in the readme or an existing bug:

I would expect db:reset to run the data:schema:load task. When we do a reset the data:version task returns 0 and all our migrations show as down.

Is this intentional behavior (in which case I'd be happy to start a PR around some docs), or a bug?

etherbob avatar Oct 17 '22 15:10 etherbob

Unfortunately, the db:reset is part of the Rails tasks, so it only knows about Rails stuff. So it'll only run db:schema:load because it doesn't know about the data-migration gem. You would have to create a different rake task to include data:schema:load or maybe a way to alias them

josh-levinson avatar Jun 13 '23 19:06 josh-levinson

I think a viable solution is to enhance the db:setup task:

Rake::Task["db:setup"].enhance do
  Rake::Task["data:schema:load"].invoke
end

However I also found that the data:schema:load messes up the DB environment somehow, and it prevents running db:reset again afterwards. This can be fixed by also invoking db:environment:set after data:schema:load.

It would be nice if the library set this up out of the box though.

michalwa avatar Oct 04 '23 09:10 michalwa