41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
|
|
"""add features to product
|
||
|
|
|
||
|
|
Revision ID: abcd1237_add_features_to_product
|
||
|
|
Revises: 63d5e2868229
|
||
|
|
Create Date: 2025-12-07 21:30:00.000000
|
||
|
|
|
||
|
|
"""
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from sqlalchemy.engine import reflection
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision = 'abcd1237_add_features_to_product'
|
||
|
|
down_revision = '63d5e2868229'
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade():
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
# 检查列是否已存在
|
||
|
|
bind = op.get_bind()
|
||
|
|
inspector = reflection.Inspector.from_engine(bind)
|
||
|
|
columns = inspector.get_columns('product')
|
||
|
|
column_names = [column['name'] for column in columns]
|
||
|
|
|
||
|
|
# 只有当列不存在时才添加
|
||
|
|
if 'features' not in column_names:
|
||
|
|
with op.batch_alter_table('product', schema=None) as batch_op:
|
||
|
|
batch_op.add_column(sa.Column('features', sa.Text(), nullable=True, comment='产品功能特性'))
|
||
|
|
|
||
|
|
# ### end Alembic commands ###
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade():
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
with op.batch_alter_table('product', schema=None) as batch_op:
|
||
|
|
batch_op.drop_column('features')
|
||
|
|
|
||
|
|
# ### end Alembic commands ###
|