2025-11-19 22:49:24 +08:00
|
|
|
"""create order table
|
|
|
|
|
|
|
|
|
|
Revision ID: abcd1235
|
|
|
|
|
Revises: 695f07385773
|
|
|
|
|
Create Date: 2025-11-19 16:00:00.000000
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
from alembic import op
|
|
|
|
|
import sqlalchemy as sa
|
|
|
|
|
from sqlalchemy.dialects import mysql
|
2025-12-12 11:35:14 +08:00
|
|
|
from sqlalchemy.engine import reflection
|
2025-11-19 22:49:24 +08:00
|
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
|
revision = 'abcd1235'
|
|
|
|
|
down_revision = '695f07385773'
|
|
|
|
|
branch_labels = None
|
|
|
|
|
depends_on = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
2025-12-12 11:35:14 +08:00
|
|
|
# 获取数据库连接和表信息
|
|
|
|
|
bind = op.get_bind()
|
|
|
|
|
inspector = reflection.Inspector.from_engine(bind)
|
|
|
|
|
|
|
|
|
|
# 获取现有表
|
|
|
|
|
existing_tables = inspector.get_table_names()
|
|
|
|
|
|
|
|
|
|
# 只有当表不存在时才创建
|
|
|
|
|
if 'order' not in existing_tables:
|
|
|
|
|
op.create_table('order',
|
|
|
|
|
sa.Column('order_id', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('order_number', sa.String(length=32), nullable=False),
|
|
|
|
|
sa.Column('product_id', sa.String(length=32), nullable=False),
|
|
|
|
|
sa.Column('package_id', sa.String(length=64), nullable=False),
|
|
|
|
|
sa.Column('contact_person', sa.String(length=64), nullable=False),
|
|
|
|
|
sa.Column('phone', sa.String(length=20), nullable=False),
|
|
|
|
|
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('amount', sa.Float(), nullable=False),
|
|
|
|
|
sa.Column('status', sa.Integer(), nullable=False),
|
|
|
|
|
sa.Column('payment_method', sa.String(length=20), nullable=True),
|
|
|
|
|
sa.Column('payment_time', sa.DateTime(), nullable=True),
|
|
|
|
|
sa.Column('create_time', sa.DateTime(), nullable=True),
|
|
|
|
|
sa.Column('update_time', sa.DateTime(), nullable=True),
|
|
|
|
|
sa.ForeignKeyConstraint(['product_id'], ['product.product_id'], ),
|
|
|
|
|
sa.PrimaryKeyConstraint('order_id'),
|
|
|
|
|
sa.UniqueConstraint('order_number'),
|
|
|
|
|
mysql_charset='utf8mb4',
|
|
|
|
|
mysql_engine='InnoDB'
|
|
|
|
|
)
|
|
|
|
|
op.create_index(op.f('ix_order_order_number'), 'order', ['order_number'], unique=False)
|
2025-11-19 22:49:24 +08:00
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
|
|
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
|
|
|
op.drop_index(op.f('ix_order_order_number'), table_name='order')
|
|
|
|
|
op.drop_table('order')
|
|
|
|
|
# ### end Alembic commands ###
|