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

Wrap all incoming migrations inside a single transaction #485

Open
mvgeny opened this issue Mar 27, 2023 · 1 comment
Open

Wrap all incoming migrations inside a single transaction #485

mvgeny opened this issue Mar 27, 2023 · 1 comment
Labels

Comments

@mvgeny
Copy link

mvgeny commented Mar 27, 2023

Every migration is wrapped in tx by default, but does it possible to wrap bunch of them? I had no success while implementing it by myself, because goose.Up accepts *sql.DB.

@mfridman
Copy link
Collaborator

mfridman commented Mar 27, 2023

It's not supported today, but it's something I'd like to add support for. Related #222

I'd like to call this "grouped migrations", where goose applies a group of separate migration files in a single transaction.

However, what should the behaviour be when one of those migration files cannot be executed within a transaction?

For example, say we have 6 new migrations: 11, 12, 13, 14, 15, 16 and migration 14 is marked with NO TRANSACTION. We cannot apply all 6 migrations in the same *sql.Tx.

The best we can do in this scenario (I think) is apply 11, 12, 13 in the same *sql.Tx and commit, then apply 14 with *sql.DB (or *sql.Conn) and then apply 15, 16 in another *sql.Tx and commit. It's a bit of an edge case, but it's something we have to account for.

Alternatively, we could do a look ahead and detect that you've opted in to "grouped migrations" and have a migration that cannot be applied in a transaction. I don't like this option though because it requires the user to modify goose.

@mfridman mfridman modified the milestones: Up next in v3, Up next in v4 Mar 27, 2023
@mfridman mfridman added the /v4 label Mar 29, 2023
@mfridman mfridman added up next and removed /v4 labels Nov 12, 2023
@mfridman mfridman removed this from the Up next in v4 milestone Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants