graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

Maybe provide an option so reset does not run migrations? #157

Closed lodi-g closed 2 years ago

lodi-g commented 2 years ago

Feature description

I'd like a way to run a reset (with the post reset actions) without running the commited migrations. It could be a command line flag, e.g. graphile-migrate reset --erase --without-migrations.

Motivating example

My workflow for deploying on pre-production is

  1. Reset the database (with a post action that sets an initial schema)
  2. Fill the database with mocked, old data (that is only valid with the initial schema of the database)
  3. Run migrations

Using graphile-migrate this workflow is not possible because running graphile-migrate reset will also run the migrations. Therefore, when I try to populate the db using my old data, the data does not adhere to the schema and fails to be populated.

Supporting development

I:

It looks like I'd just need to add a CLI flag in the resetCommand variable and use it to condition the run of _migrate (https://github.com/graphile/migrate/blob/main/src/commands/reset.ts#L63). That doesn't look super hard, so if you think this feature request is interesting, I can do it.

benjie commented 2 years ago

Just to challenge the need a little - why can the mocked old data not also be supplied via an afterReset hook? You can configure it to only run under certain circumstances (e.g. call out to a shell script with whatever logic you need).

lodi-g commented 2 years ago

Hey @benjie, thanks for your insight and challenging the idea. For some reason, I did not think about that. So I guess the issue is closed, unless there's a use case I didn't think of.