Skip to content
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

Wrapping in transaction(s) for DBs that support it / SQL templating #283

Closed
t3hmrman opened this issue May 5, 2021 · 2 comments
Closed

Comments

@t3hmrman
Copy link

t3hmrman commented May 5, 2021

Some databases support DDL in transactions, and for those it's almost strictly better for migrations to be all-or-nothing, as in:

BEGIN TRANSACTION;

CREATE TABLE some_table (...);

CREATE INDEX some_table_idx (...);

COMMIT TRANSACTION;

It would be nice to have the created files have BEGIN TRANSACTION at the top for Postgres.

While the quick fix might be just adding the lines (maybe having them commented out), a more general one might be allowing the specification of a static template for up/down migration migrations, then I can just add the file, make sure to point to it in my config and then when I make a migration it will have the bits I want in it.

@mmkal
Copy link
Owner

mmkal commented Jun 26, 2021

@t3hmrman this is now possible in v0.8 using singleTransaction. It's not yet documented, but it should do what you're suggesting.

This test shows an example usage.

@mmkal mmkal closed this as completed Jun 26, 2021
@t3hmrman
Copy link
Author

Thanks @mmkal -- I've been getting along just fine with migrator by using the BEGIN and COMMIT, and will switch to using singleTransaction -- have used migrator on a couple of projects now and it's fantastic, thanks for all the hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants