Batch op: rename column then create index on it #1255
-
I am trying to use batch ops to get some degree of atomicity in my migrations on a sqlite db Should this work? def upgrade() -> None:
with op.batch_alter_table("turn") as batch_op:
batch_op.drop_index("turn_game_id")
batch_op.alter_column("game_id", new_column_name="gamesession_id")
batch_op.create_index("turn_gamesession_id", ["gamesession_id"]) Currently I get an error on the last op:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
and then the temp table gets left behind so next attempt to migrate gives:
|
Beta Was this translation helpful? Give feedback.
-
probably not, because the existing table being reflected does not have the "gamesession_id" column yet. it should have a nicer error message. I would do the index drop/add stuff outside of the batch op because SQLite supports CREATE INDEX and DROP INDEX directly. re: "atomiticy", SQLite supports transactional DDL. Follow the steps at https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#pysqlite-serializable to work around driver issues. |
Beta Was this translation helpful? Give feedback.
-
Oh, great! So if I add those event handlers to my And I then only need to use batch ops for the alter column stuff that SQLite doesn't support directly |
Beta Was this translation helpful? Give feedback.
probably not, because the existing table being reflected does not have the "gamesession_id" column yet. it should have a nicer error message.
I would do the index drop/add stuff outside of the batch op because SQLite supports CREATE INDEX and DROP INDEX directly.
re: "atomiticy", SQLite supports transactional DDL. Follow the steps at https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#pysqlite-serializable to work around driver issues.