Fix migration 034 failing on fresh DB: drop index not constraint
Migration 022 created a unique INDEX (ix_ntfy_sent_notification_key), not a named unique CONSTRAINT. Migration 034 was trying to drop a constraint name that only existed on upgraded DBs. Fixed to drop the index instead, which works on both fresh and upgrade paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
619e220622
commit
2438cdcf25
@ -24,10 +24,14 @@ def upgrade() -> None:
|
||||
"fk_ntfy_sent_user_id", "ntfy_sent", "users",
|
||||
["user_id"], ["id"], ondelete="CASCADE"
|
||||
)
|
||||
# On fresh DB ntfy_sent may be empty — clean up NULLs just in case
|
||||
op.execute("DELETE FROM ntfy_sent WHERE user_id IS NULL")
|
||||
op.alter_column("ntfy_sent", "user_id", nullable=False)
|
||||
|
||||
# Drop old unique constraint on notification_key alone
|
||||
op.drop_constraint("ntfy_sent_notification_key_key", "ntfy_sent", type_="unique")
|
||||
# Migration 022 created a unique INDEX (ix_ntfy_sent_notification_key), not a
|
||||
# named unique CONSTRAINT. Drop the index; the new composite unique constraint
|
||||
# below replaces it.
|
||||
op.drop_index("ix_ntfy_sent_notification_key", table_name="ntfy_sent")
|
||||
|
||||
# Create composite unique constraint (per-user dedup)
|
||||
op.create_unique_constraint(
|
||||
@ -39,8 +43,8 @@ def upgrade() -> None:
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_ntfy_sent_user_id", table_name="ntfy_sent")
|
||||
op.drop_constraint("uq_ntfy_sent_user_key", "ntfy_sent", type_="unique")
|
||||
op.create_unique_constraint(
|
||||
"ntfy_sent_notification_key_key", "ntfy_sent", ["notification_key"]
|
||||
op.create_index(
|
||||
"ix_ntfy_sent_notification_key", "ntfy_sent", ["notification_key"], unique=True
|
||||
)
|
||||
op.drop_constraint("fk_ntfy_sent_user_id", "ntfy_sent", type_="foreignkey")
|
||||
op.drop_column("ntfy_sent", "user_id")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user