-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separating the partial-rollback from roll forward in migration scripts #133
Comments
This is already possible if you’re disciplined; use
GM’s migrations only run once on commit/migrate so the idempotency is only required for watch mode. You might be able to use a beforeCommit action to perform this procedure; if that action doesn’t already exist then a PR to add it would be welcome (with the associated afterCommit). |
Thanks for the pointers. There's a key part which I don't understand in this suggestion: how do we have I guess we could have our custom |
Oops, yes - I meant delete it. Another potential option is to have a rollback script we call via beforeCurrent and maybe blank that out or move it somewhere afterCommit? Basically I’m not sure currently how to best achieve this in the migrations themselves, I don’t like the idea of inline comments because our migration/current files should be runnable with psql without needing custom parsing (note the : placeholders we use are inspired by psql). However our lifecycle hooks should allow you to design a flow you’re happy with, and if they do not then we should enhance them. |
Yes that makes sense. The thing I don't love about deleting the rollback is that it becomes quite ephemeral; I'd prefer to have prior rollbacks as reference material when developing future migrations. Though with that in mind, maybe it makes sense to have the |
Of course, your beforeCommit could also figure out what the next commit number will be (we could even expose it in an envvar) and move rather than delete e.g. We could even have an |
True! I think this is the right idea. |
Problem statement / motivation
As a new user introducing graphile-migrate to a team, I've noticed that code review of migrations is complicated by the need to thoroughly check the
DROP
statements that are required for idempotency. This is a point of friction for introducing the tooling, as people responsible for operational databases are nervous about having migrations containing a lot ofDROP
statements. It seems we currently have the following tradeoffDROP
statement for a resource in the existing schema, data loss will occur in production.DROP
statements are a necessary part of idempotency and havinggraphile-migrate watch
work during development.Feature description
I find that it's often possible to separate migrations into two halves which seem like they could be treated differently in production and development:
DROP
(or other) statements which remove any resources previously created during development. This is like a partial rollback which is happy to destroy data, and only needs to get the DB in a state where the roll forward phase can reliably be reapplied.If
graphile-migrate
guaranteed to only apply (2) in production (and for the shadow db rollforward check phase) it would seem unnecessary for (1) to be thoroughly vetted in code review, and reduce overall risk of applying a migration.I'm not sure what this feature would look like. Could it be a comment which separates migration files into two sections? That seems a little fragile (eg, what if the comment is spelled wrong?), but it would be minimally breaking.
Supporting development
I could potentially help build this.
The text was updated successfully, but these errors were encountered: