Wrapping migrations in transaction prevents use of certain DDL queries #2047
Replies: 3 comments
-
To add some relevant context:
E.g. you can add a value to an pg enum using Ignoring All in all I would in general recommend one-transaction per migration for postgress instead of one transaction over all migrations, with a way to opt out of transaction. The simplest short term fix would be to remove the pg transaction and let users do their transactions themself. I think it probably would be best to e.g. add something like a Alternative to returning a |
Beta Was this translation helpful? Give feedback.
-
Additionally I would argue it is necessary to take database specific steps to make sure only one migration process is run at the same time. (In addition to using transactions in pg.) For example if you have load balancing you need that to make sure only one of this instances tries to do the migration. Transactions are not enough for that as with that you still would have multiple instances trying, which can lead to a multitude of issues if migrations are not idempotent (it can even lead to lost or corrupted data, e.g. when doing transformations on a JSON column which can be done twice but shouldn't). In rust terms it's kinda like the difference between a fancy concurrent data-structure using a Importantly this is possible with all currently supported DBs AFIK.
It also would be convenient to have a way to let other code access this primitive as I have as I had used things like that in the past to somewhat synchronize updates to other sub-systems. But that would be a separate discussion. |
Beta Was this translation helpful? Give feedback.
-
Hello guys, is there any way to run concurrent index creation for postgresql at the moment on seaorm? |
Beta Was this translation helpful? Give feedback.
-
First off thanks for this package! ❤️
Context
Related discussions:
Examples in other ORM migrators:
Problem
Related to the "atomic migrations" change for postgres #1379
Some postgres DDL statements cannot be run from within a transaction and attempting to do so will result in a postgres error like:
STATEMENT cannot run inside a transaction block
Examples of queries not allowed in a transaction:
CREATE/DROP INDEX CONCURRENTLY
(it is recommended to create indexes on large tables concurrently to avoid blocking writes: https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY)ALTER TABLE
sub commandsALTER TYPE...ADD VALUE
CREATE DATABASE
Possible solutions
up, down, fresh, refresh
commands that allow skipping transaction (possibly a combination of this and the env var)Beta Was this translation helpful? Give feedback.
All reactions