jackc / tern

The SQL Fan's Migrator
MIT License
925 stars 68 forks source link

Run Migration not in a transaction #36

Closed davidmdm closed 2 years ago

davidmdm commented 2 years ago

I can see in package migrate that there is an option to DisableTx, However I can't figure out how to disable them when simply calling the tern command line. If I have 5 migration files, and 1 of them should not be run inside of a transaction, how do I do this?

jackc commented 2 years ago

That setting isn't wired into the CLI. No reason not to, just no one ever did it. 🤷

davidmdm commented 2 years ago

Would there be a filename convention to disable running the Migration in a transaction that would be suitable for you? If so than I might make a PR for it. something like: 002_create_table_foo.no_tx.sql?

Other tools generally enable transactions with the .tx.sql suffix instead of disabling them, but doing that would break backwards compatability.

Is this a feature you would like to have?

jackc commented 2 years ago

The overall feature is fine, but I would probably lean toward a magic comment rather than something as part of the file name. That would allow conveniently adding more per migration behavior flags.

JosefWN commented 2 years ago

It's not just the CLI, it's a bit clunky to use in code too. This struct is not exported: https://github.com/jackc/tern/blob/0c8ea3965b420615f8d10286e290af94a4d8f87f/migrate/migrate.go#L107

So if I want to set DisableTx in the MigratorOptions passed to NewMigratorEx, I have to reimplement the default file system migrator. Regardless of https://github.com/jackc/tern/issues/43 it could be good to expose this struct for the future (unless MigratorFS will always be the only option).

jackc commented 2 years ago

This should be resolved on v2-dev with b23e02f669b806ba8ac09037893acd6aeab79b1e.