653be7755b
CI/CD Pipeline / Build Production Runtime Images (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Failing after 52h57m33s
CI/CD Pipeline / Deploy Staging (push) Failing after 52h58m54s
CI/CD Pipeline / Frontend Lint (push) Failing after 53h0m13s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 53h0m59s
The _column_exists() helper in migrations 026-029 calls conn.execute() which returns None in Alembic's offline/SQL mode (--sql flag), causing AttributeError on result.scalar(). Add context.is_offline_mode() guard to skip the idempotency check in offline mode and unconditionally emit the DDL statements. Fixes: Validate CI step 'alembic upgrade head --sql' failure.
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
"""Add user profile fields (name, avatar, updated_at)
|
|
|
|
Revision ID: 026
|
|
Revises: 025
|
|
Create Date: 2026-07-05
|
|
|
|
补录用户资料字段。生产数据库已手动添加过这些字段,
|
|
因此 upgrade 做幂等检查,避免在已有字段的库上执行报错。
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from alembic import context, op
|
|
|
|
revision = "026"
|
|
down_revision = "025"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _column_exists(table: str, column: str) -> bool:
|
|
if context.is_offline_mode():
|
|
return False
|
|
conn = op.get_bind()
|
|
result = conn.execute(
|
|
sa.text(
|
|
"SELECT COUNT(*) FROM information_schema.columns " "WHERE table_name = :table AND column_name = :column"
|
|
),
|
|
{"table": table, "column": column},
|
|
)
|
|
return result.scalar() > 0
|
|
|
|
|
|
def upgrade() -> None:
|
|
if not _column_exists("users", "name"):
|
|
op.add_column("users", sa.Column("name", sa.String(100), nullable=True))
|
|
|
|
if not _column_exists("users", "avatar"):
|
|
op.add_column("users", sa.Column("avatar", sa.String(500), nullable=True))
|
|
|
|
if not _column_exists("users", "updated_at"):
|
|
op.add_column(
|
|
"users",
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(),
|
|
nullable=True,
|
|
server_default=sa.func.now(),
|
|
),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_column("users", "updated_at")
|
|
op.drop_column("users", "avatar")
|
|
op.drop_column("users", "name")
|