From 77ea0680fb2c39285a0fa1ce0862b045ef6b91a1 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 28 Feb 2026 19:22:13 +0800 Subject: [PATCH] [add] migration script --- .../versions/4bf27c66ae63_202602281918.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 api/migrations/versions/4bf27c66ae63_202602281918.py diff --git a/api/migrations/versions/4bf27c66ae63_202602281918.py b/api/migrations/versions/4bf27c66ae63_202602281918.py new file mode 100644 index 00000000..78b13435 --- /dev/null +++ b/api/migrations/versions/4bf27c66ae63_202602281918.py @@ -0,0 +1,44 @@ +"""202602281918 + +Revision ID: 4bf27c66ae63 +Revises: 7672d8f0f939 +Create Date: 2026-02-28 19:18:38.332468 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '4bf27c66ae63' +down_revision: Union[str, None] = '7672d8f0f939' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + # Add columns as nullable first + op.add_column('ontology_class', sa.Column('is_system_default', sa.Boolean(), nullable=True, comment='是否为系统默认类型')) + op.add_column('ontology_scene', sa.Column('is_system_default', sa.Boolean(), nullable=True, comment='是否为系统默认场景')) + + # Set default value for existing rows + op.execute("UPDATE ontology_class SET is_system_default = false WHERE is_system_default IS NULL") + op.execute("UPDATE ontology_scene SET is_system_default = false WHERE is_system_default IS NULL") + + # Now make columns NOT NULL + op.alter_column('ontology_class', 'is_system_default', nullable=False) + op.alter_column('ontology_scene', 'is_system_default', nullable=False) + + op.create_index(op.f('ix_ontology_scene_is_system_default'), 'ontology_scene', ['is_system_default'], unique=False) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_ontology_scene_is_system_default'), table_name='ontology_scene') + op.drop_column('ontology_scene', 'is_system_default') + op.drop_column('ontology_class', 'is_system_default') + # ### end Alembic commands ###