Skip to content

Commit 4485116

Browse files
committed
fix(migrations): revert 0014 idempotency guard
The guard was both unreachable and unsafe. For platforms.id to exist on a rerun, the first attempt must have already run the atomic ADD COLUMN id ... PRIMARY KEY, which means it passed the unguarded drop_constraint("fk_platform_roms") at the top of upgrade(). That FK drop has no IF EXISTS, so any rerun fails there before reaching the guard. And if it were reachable, the preceding primary-key drop would leave id unkeyed once the ADD COLUMN was skipped. Keep the genuinely correct fixes (0084, 0033); leave 0014 as-is. Generated-By: PostHog Code Task-Id: 87d70ab6-f915-48c0-afa7-55064c97d1a5
1 parent 8ce8449 commit 4485116

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

backend/alembic/versions/0014_asset_files.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,13 @@ def upgrade() -> None:
168168
batch_op.drop_constraint(constraint_name=pk_constraint_name, type_="primary")
169169
batch_op.drop_column("n_roms", if_exists=True)
170170

171-
# Switch to new id column as platform primary key. Raw DDL has no portable
172-
# "IF NOT EXISTS", so guard it to stay idempotent on a partial-failure rerun.
173-
platform_columns = {
174-
column["name"] for column in sa.inspect(connection).get_columns("platforms")
175-
}
176-
if "id" not in platform_columns:
177-
if is_postgresql(connection):
178-
op.execute("ALTER TABLE platforms ADD COLUMN id SERIAL PRIMARY KEY")
179-
else:
180-
op.execute(
181-
"ALTER TABLE platforms ADD COLUMN id INTEGER(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
182-
)
171+
# Switch to new id column as platform primary key
172+
if is_postgresql(connection):
173+
op.execute("ALTER TABLE platforms ADD COLUMN id SERIAL PRIMARY KEY")
174+
else:
175+
op.execute(
176+
"ALTER TABLE platforms ADD COLUMN id INTEGER(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
177+
)
183178

184179
# Add new columns to roms table
185180
with op.batch_alter_table("roms", schema=None) as batch_op:

0 commit comments

Comments
 (0)