node-pg-migrate icon indicating copy to clipboard operation
node-pg-migrate copied to clipboard

Reveal and document pgm.enableReverseMode()

Open osdiab opened this issue 4 months ago • 3 comments

Internally, this library appears to use an enableReverseMode() function to reverse the commands of a migration when inferring a down() migration.

At my company when we revert a change we want to just make a new migration that does the inverse of what a reverted migration does. For migrations with a down() migration, this is easy - just call it in the up() migration.

But for migrations where it is inferred, it is not obvious how you would call the automatic down() migration for a given up() migration. But! Internally this library's enableReverseMode() function would do the trick, just call it first before calling the up() migration.

But, the TypeScript interface doesn't say it exists, nor is it mentioned in the docs. But I'm pretty sure this should generally work.

So my suggestion is to not hide this and actually make it be a documented part of this library. Even further, it would potentially make sense to even have a CLI command to generate a "revert" migration for a given migration.

osdiab avatar Feb 15 '24 05:02 osdiab