Ability to run migrations without the transaction
Some commands (e.g. ALTER TYPE … ADD VALUE
in PostgreSQL) can not work inside transactions.
Comments (6)
-
repo owner -
I needed this feature as well since I'm using goose to manage database creation. I've put together a small prototype that does the following:
- It adds a new UnsafeNoTransaction annotation.
- Only one statement is allowed if this annotation is applied.
- The user is expected to make that statement idempotent.
- Version updates still happen inside a transaction.
This way if the version update fails, it prints a warning that the statement will be run again. Since the statement is idempotent it can be run again safely.
My prototype for .sql files can be found here:
https://bitbucket.org/surullabs/goose/commits/398815e71a9e2fd7acbf7407091643e32e1eeeed?at=master
Let me know if you think this approach is acceptable and I'll clean it up, add some tests and send you a pull request.
EDIT: grammar
-
repo owner thanks for looking into this! i hope to be able to take a look this weekend and provide some feedback.
-
Has there been any progress on this, by any chance?
-
reporter @liamstask, what are your plans about this one? It is almost a year since the original report.
-
FWIW - I've fixed this in my fork, by parsing to see if the query cannot be run in a transaction: https://github.com/kevinburke/goose/commit/7541cfa2ae0c4d4aab7b0c3f8405be079376339f
I worked around the problem by requiring - if your query cannot run in a transaction, you have to run it as the only migration in the statement.
- Log in to comment
Oof. Thanks for the report.
Will need to think about how best to handle the case in which migration succeeds, but the secondary operation to update the schema version number fails...