1
This commit is contained in:
+87
@@ -0,0 +1,87 @@
|
||||
"""add module flow version and generation reference option
|
||||
|
||||
Revision ID: d8ebe79ab575
|
||||
Revises: e6eac828ff61
|
||||
Create Date: 2026-07-21 09:28:04.318458
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "d8ebe79ab575"
|
||||
down_revision: Union[str, None] = "e6eac828ff61"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def _column_names(table_name: str) -> set[str]:
|
||||
inspector = sa.inspect(op.get_bind())
|
||||
return {str(column["name"]) for column in inspector.get_columns(table_name)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
generation_record_columns = _column_names("generation_records")
|
||||
if "include_media_references" not in generation_record_columns:
|
||||
op.add_column(
|
||||
"generation_records",
|
||||
sa.Column(
|
||||
"include_media_references",
|
||||
sa.Boolean(),
|
||||
server_default=sa.text("false"),
|
||||
nullable=False,
|
||||
),
|
||||
)
|
||||
else:
|
||||
op.execute(
|
||||
sa.text(
|
||||
"UPDATE generation_records "
|
||||
"SET include_media_references = false "
|
||||
"WHERE include_media_references IS NULL"
|
||||
)
|
||||
)
|
||||
op.alter_column(
|
||||
"generation_records",
|
||||
"include_media_references",
|
||||
existing_type=sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.text("false"),
|
||||
)
|
||||
|
||||
project_columns = _column_names("module_generation_projects")
|
||||
if "flow_version" not in project_columns:
|
||||
op.add_column(
|
||||
"module_generation_projects",
|
||||
sa.Column(
|
||||
"flow_version",
|
||||
sa.String(length=16),
|
||||
server_default=sa.text("'v1'"),
|
||||
nullable=False,
|
||||
),
|
||||
)
|
||||
else:
|
||||
op.execute(
|
||||
sa.text(
|
||||
"UPDATE module_generation_projects "
|
||||
"SET flow_version = 'v1' "
|
||||
"WHERE flow_version IS NULL OR btrim(flow_version) = ''"
|
||||
)
|
||||
)
|
||||
op.alter_column(
|
||||
"module_generation_projects",
|
||||
"flow_version",
|
||||
existing_type=sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default=sa.text("'v1'"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
project_columns = _column_names("module_generation_projects")
|
||||
if "flow_version" in project_columns:
|
||||
op.drop_column("module_generation_projects", "flow_version")
|
||||
|
||||
generation_record_columns = _column_names("generation_records")
|
||||
if "include_media_references" in generation_record_columns:
|
||||
op.drop_column("generation_records", "include_media_references")
|
||||
Reference in New Issue
Block a user