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

Add ability to run migrations outside of a transaction #277

Open
mschmo opened this issue May 15, 2023 · 3 comments
Open

Add ability to run migrations outside of a transaction #277

mschmo opened this issue May 15, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@mschmo
Copy link

mschmo commented May 15, 2023

This would be useful (and needed) for certain commands that cannot be ran within a transaction, such as CREATE INDEX CONCURRENTLY in postgres.

This would ideally be something that could configured per migration file, similar to how goose has the ability to mark migration files with a -- +goose NO TRANSACTION comment or how Flyway provides a executeInTransaction setting in script config files.

@jxs jxs added enhancement New feature or request help wanted Extra attention is needed labels May 20, 2023
@jxs
Copy link
Member

jxs commented May 20, 2023

Hi, and thanks for your interest!
I wasn't aware of that, interesting. Currently Transaction is one of the core traits. We can rename it to Execution and either have a boolean transaction flag for the execute message. Are you interested in tackling that?
thanks

@mschmo
Copy link
Author

mschmo commented May 23, 2023

Hey @jxs - I'd definitely be interested in that! Thank you for the starting points about the Transaction trait. That makes sense for the point where we can execute the migration either within or outside of a transaction and I'll start working on implementing that.

As far as how a user would configure that setting on a migration SQL file, do you have any preferences to the design/approach? I saw in the README that refinery's design is based on Flyway, so should we use the same approach via script config files? Such that each migration .sql file could have an optional .sql.conf file with an executeInTransaction setting (default to true).

@jxs
Copy link
Member

jxs commented May 23, 2023

I'd go for goose's way of doing it, and having special formatted comments like: -- +refinery NO TRANSACTION.

We can do it parsing the migration file. Ideally we could use Migration for that, thing is we should probably first split Migration into AppliedMigration and UnappliedMigration that we can there compare with the PartialEq. We can then when creating an UnappliedMigration that parses the input &str line by line.

As this will most likely decrease performance, I'd also add a flag on the UnappliedMigration constructor to disable this, that we can then leverage via Runner What do you think?

quasi-coherent pushed a commit to quasi-coherent/refinery that referenced this issue Sep 30, 2024
…#1)

- Required implementations to use `sqlx::PgPool` as the driver for
embedded Rust migrations.
- Addresses rust-db#277 by adding the
ability to annotate a SQL or Rust migration with
`refinery:noTransaction`, which will make the migration be applied
outside of a transaction when not grouping unapplied migrations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants