gabriel / musehub public
0037_widen_id_columns_repair.py python
50 lines 1.3 KB
Raw
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 121 days ago
1 """Widen varchar(36) ID columns to varchar(128) — idempotent repair.
2
3 Migration 0030 was stamped before it ran on staging (same stamp-and-retry
4 escape hatch issue as 0035/0036). This migration re-applies those ALTERs
5 using DO $$ conditional blocks that are no-ops when the column is already
6 the right size.
7
8 Also widens musehub_background_jobs.repo_id which 0030 missed.
9
10 Revision ID: 0037
11 Revises: 0036
12 """
13 from __future__ import annotations
14
15 from alembic import op
16 from sqlalchemy import text
17
18 revision = "0037"
19 down_revision = "0036"
20 branch_labels = None
21 depends_on = None
22
23 _WIDEN = [
24 ("musehub_background_jobs", "job_id"),
25 ("musehub_background_jobs", "repo_id"),
26 ("musehub_domain_installs", "install_id"),
27 ("musehub_issue_events", "event_id"),
28 ("musehub_webhook_deliveries", "delivery_id"),
29 ]
30
31
32 def upgrade() -> None:
33 for table, col in _WIDEN:
34 op.execute(text(f"""
35 DO $$
36 BEGIN
37 IF EXISTS (
38 SELECT 1 FROM information_schema.columns
39 WHERE table_name = '{table}'
40 AND column_name = '{col}'
41 AND character_maximum_length < 128
42 ) THEN
43 ALTER TABLE {table} ALTER COLUMN {col} TYPE VARCHAR(128);
44 END IF;
45 END $$
46 """))
47
48
49 def downgrade() -> None:
50 pass
File History 1 commit
sha256:a34090cc4a394a78bd72cbbe34b08cc59525141e19135b6c0ab154f10611b9ef debug(push/stream): instrument O-frame decode path with INF… Sonnet 4.6 patch 121 days ago