fix(#1894): fix alembic revision chain — rename 077→076 (no 076 existed), set down_revision to 075_add_sentence_timings, add postgresql dialect guard
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m8s
AI Code Review / AI Code Review (pull_request) Successful in 6m36s
PR Automation / Auto Approve on CI Green (pull_request) Failing after 11m42s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 16s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 16s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 10m35s
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 16h20m35s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 16h31m21s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 16h30m38s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 16h30m39s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 16h30m40s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 16h30m41s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 16h19m47s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 16h19m57s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 16h30m38s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 16h43m16s

KeyError: '076_membership_points' broke alembic upgrade on CI (Postgres).
No membership_points migration ever existed (PR #1919 added points
without a new alembic revision). Our migration should chain from
075_add_sentence_timings, the actual head on develop.
This commit is contained in:
xiaoxia
2026-09-15 22:14:36 +08:00
parent 509b8db3a3
commit f30fe14ff8
2 changed files with 68 additions and 64 deletions
@@ -0,0 +1,68 @@
"""#1894: merge title_library into scripts — add title_text/title_category/title_config to scripts
Revision ID: 076_merge_title_library_into_scripts
Revises: 075_add_sentence_timings
Create Date: 2026-09-15
"""
import sqlalchemy as sa
from alembic import context, op
revision = "076_merge_title_library_into_scripts"
down_revision = "075_add_sentence_timings"
branch_labels = None
depends_on = None
def upgrade() -> None:
# scripts 表新增标题配置三字段
with op.batch_alter_table("scripts") as batch:
batch.add_column(
sa.Column("title_text", sa.String(500), nullable=False, server_default=""),
)
batch.add_column(
sa.Column("title_category", sa.String(50), nullable=False, server_default=""),
)
batch.add_column(
sa.Column("title_config", sa.JSON, nullable=False, server_default="{}"),
)
# 从 title_libraries 迁移活跃数据到 scripts(仅 PostgreSQL;SQLite 下无历史数据)
if context.get_context().dialect.name == "postgresql":
conn = op.get_bind()
result = conn.execute(sa.text("SELECT to_regclass('public.title_libraries')"))
if result.scalar() is not None:
conn.execute(sa.text("""
INSERT INTO scripts
(id, user_id, title, content, segments, tags,
title_text, title_category, title_config,
created_at, updated_at)
SELECT
gen_random_uuid()::TEXT,
tl.user_id,
COALESCE(tl.name, '迁移标题'),
COALESCE(tl.text, ''),
'[]'::JSONB,
COALESCE(tl.tags, '[]'::JSONB),
COALESCE(tl.text, ''),
COALESCE(tl.category, ''),
COALESCE(tl."metadata", '{}'::JSONB),
tl.created_at,
tl.updated_at
FROM title_libraries tl
WHERE tl.is_active = true
AND NOT EXISTS (
SELECT 1 FROM scripts s
WHERE s.user_id = tl.user_id
AND s.title_text = COALESCE(tl.text, '')
AND s.title_category = COALESCE(tl.category, '')
AND s.created_at = tl.created_at
)
"""))
def downgrade() -> None:
with op.batch_alter_table("scripts") as batch:
batch.drop_column("title_config")
batch.drop_column("title_category")
batch.drop_column("title_text")
@@ -1,64 +0,0 @@
"""#1894: merge title_library into scripts — add title_text/title_category/title_config to scripts
Revision ID: 077_merge_title_library_into_scripts
Revises: 076_membership_points
Create Date: 2026-09-15
"""
import sqlalchemy as sa
from alembic import op
revision = "077_merge_title_library_into_scripts"
down_revision = "076_membership_points"
branch_labels = None
depends_on = None
def upgrade() -> None:
# scripts 表新增标题配置三字段
with op.batch_alter_table("scripts") as batch:
batch.add_column(
sa.Column("title_text", sa.String(500), nullable=False, server_default=""),
)
batch.add_column(
sa.Column("title_category", sa.String(50), nullable=False, server_default=""),
)
batch.add_column(
sa.Column("title_config", sa.JSON, nullable=False, server_default="{}"),
)
# 从 title_libraries 迁移活跃数据到 scripts(若 title_libraries 表存在)
conn = op.get_bind()
exists = conn.execute(sa.text("SELECT to_regclass('public.title_libraries') IS NOT NULL")).scalar()
if exists:
conn.execute(sa.text("""
INSERT INTO scripts (id, user_id, title, content, segments, tags, title_text, title_category, title_config, created_at, updated_at)
SELECT
gen_random_uuid()::TEXT,
tl.user_id,
COALESCE(tl.name, '迁移标题'),
COALESCE(tl.text, ''),
'[]'::JSONB,
COALESCE(tl.tags, '[]'::JSONB),
COALESCE(tl.text, ''),
COALESCE(tl.category, ''),
COALESCE(tl."metadata", '{}'::JSONB),
tl.created_at,
tl.updated_at
FROM title_libraries tl
WHERE tl.is_active = true
AND NOT EXISTS (
SELECT 1 FROM scripts s
WHERE s.user_id = tl.user_id
AND s.title_text = COALESCE(tl.text, '')
AND s.title_category = COALESCE(tl.category, '')
AND s.created_at = tl.created_at
)
"""))
def downgrade() -> None:
with op.batch_alter_table("scripts") as batch:
batch.drop_column("title_config")
batch.drop_column("title_category")
batch.drop_column("title_text")