0025_server_defaults_booleans_and_enums.py
python
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2
feat: add repair-commit wire endpoint (API parity with repa…
Opus 4.8
minor
⚠ breaking
1 day ago
| 1 | """Add server_default to boolean and string-enum columns. |
| 2 | |
| 3 | Every non-nullable column with a Python-side default should also have a |
| 4 | server_default so that raw SQL inserts (migrations, scripts, bulk loads) |
| 5 | produce a valid row without having to specify the value explicitly. |
| 6 | |
| 7 | This migration covers two categories: |
| 8 | - Booleans: SET DEFAULT false / true |
| 9 | - String enums / sentinel strings: SET DEFAULT 'value' |
| 10 | |
| 11 | Revision ID: 0025 |
| 12 | Revises: 0024 |
| 13 | """ |
| 14 | from __future__ import annotations |
| 15 | |
| 16 | from alembic import op |
| 17 | import sqlalchemy as sa |
| 18 | |
| 19 | revision = "0025" |
| 20 | down_revision = "0024" |
| 21 | branch_labels = None |
| 22 | depends_on = None |
| 23 | |
| 24 | # (table, column, default_value) |
| 25 | _BOOL_FALSE: list[tuple[str, str]] = [ |
| 26 | ("musehub_repos", "training_opt_out"), |
| 27 | ("musehub_identities", "is_verified"), |
| 28 | ("musehub_issue_comments", "is_deleted"), |
| 29 | ("musehub_releases", "is_draft"), |
| 30 | ("musehub_webhook_deliveries", "success"), |
| 31 | ("musehub_sessions", "is_active"), |
| 32 | ("musehub_intel_entangle", "structurally_linked"), |
| 33 | ("musehub_intel_stable", "since_start"), |
| 34 | ("musehub_intel_type", "return_is_any"), |
| 35 | ("musehub_bridge_mirrors", "auto_export"), |
| 36 | ("musehub_profile_snapshots", "is_stale"), |
| 37 | ("musehub_domains", "is_verified"), |
| 38 | ("musehub_domains", "is_deprecated"), |
| 39 | ] |
| 40 | |
| 41 | _BOOL_TRUE: list[tuple[str, str]] = [ |
| 42 | ("musehub_webhooks", "active"), |
| 43 | ] |
| 44 | |
| 45 | _STR_DEFAULTS: list[tuple[str, str, str]] = [ |
| 46 | ("musehub_repos", "visibility", "public"), |
| 47 | ("musehub_identities", "identity_type", "human"), |
| 48 | ("musehub_issues", "state", "open"), |
| 49 | ("musehub_proposals", "state", "open"), |
| 50 | ("musehub_proposal_reviews", "state", "pending"), |
| 51 | ("musehub_releases", "channel", "stable"), |
| 52 | ("musehub_sessions", "schema_version", "1"), |
| 53 | ("musehub_background_jobs", "status", "pending"), |
| 54 | ("musehub_intel_api_surface", "visibility", "public"), |
| 55 | ("musehub_mists", "visibility", "public"), |
| 56 | ("musehub_intel_breakage_issues", "severity", "warning"), |
| 57 | ("musehub_bridge_mirrors", "git_branch", "muse-mirror"), |
| 58 | ("musehub_collaborators", "permission", "write"), |
| 59 | ("musehub_coord_tasks", "queue", "default"), |
| 60 | ("musehub_coord_tasks", "status", "pending"), |
| 61 | ("musehub_domains", "version", "1.0.0"), |
| 62 | ("musehub_domains", "viewer_type", "generic"), |
| 63 | ] |
| 64 | |
| 65 | |
| 66 | def upgrade() -> None: |
| 67 | conn = op.get_bind() |
| 68 | for table, col in _BOOL_FALSE: |
| 69 | conn.execute(sa.text(f"ALTER TABLE {table} ALTER COLUMN {col} SET DEFAULT false")) |
| 70 | for table, col in _BOOL_TRUE: |
| 71 | conn.execute(sa.text(f"ALTER TABLE {table} ALTER COLUMN {col} SET DEFAULT true")) |
| 72 | for table, col, val in _STR_DEFAULTS: |
| 73 | conn.execute(sa.text(f"ALTER TABLE {table} ALTER COLUMN {col} SET DEFAULT '{val}'")) |
| 74 | |
| 75 | |
| 76 | def downgrade() -> None: |
| 77 | conn = op.get_bind() |
| 78 | for table, col in _BOOL_FALSE + _BOOL_TRUE: |
| 79 | conn.execute(sa.text(f"ALTER TABLE {table} ALTER COLUMN {col} DROP DEFAULT")) |
| 80 | for table, col, _ in _STR_DEFAULTS: |
| 81 | conn.execute(sa.text(f"ALTER TABLE {table} ALTER COLUMN {col} DROP DEFAULT")) |
File History
1 commit
sha256:3ff9c9863a9891bdcde71b4a43228f66d0493e38b7cc1d09fe9eb7de774046b2
feat: add repair-commit wire endpoint (API parity with repa…
Opus 4.8
minor
⚠
1 day ago