"""order and chat Revision ID: bde4f21924c8 Revises: b2d35cbc76bd Create Date: 2025-02-27 23:12:20.993488 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = 'bde4f21924c8' down_revision: Union[str, None] = 'b2d35cbc76bd' 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! ### op.create_table('system_chats', sa.Column('guid', sa.String(length=36), nullable=True), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'), sa.Column('is_deleted', sa.Boolean(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'), sa.PrimaryKeyConstraint('id'), comment='聊天表' ) op.create_index('idx_chat_on_guid', 'system_chats', ['guid'], unique=False) op.create_table('system_orders', sa.Column('order_id', sa.String(length=32), nullable=False, comment='订单id'), sa.Column('transaction_id', sa.String(length=32), nullable=True, comment='微信订单id'), sa.Column('user_id', sa.Integer(), nullable=False, comment='用户id'), sa.Column('product_id', sa.Integer(), nullable=False, comment='产品id'), sa.Column('total_fee', sa.Integer(), nullable=True, comment='发起的总金额,单位为分'), sa.Column('notify_total_fee', sa.Integer(), nullable=True, comment='回调成功支付的总金额,单位为分'), sa.Column('pay_url', sa.String(length=255), nullable=True, comment='支付地址'), sa.Column('status', sa.Enum('INIT', 'FAIL', 'OK', 'WAIT_PAYMENT', 'CANCEL', name='orderstatustype', inherit_schema=True), server_default='init', nullable=False, comment='订单状态,init:初始化 fail:失败 ok:完成 wait payment:待支付 cancel. 取消'), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'), sa.PrimaryKeyConstraint('id'), comment='产品订单表' ) op.create_index('idx_order_on_order_id', 'system_orders', ['order_id'], unique=False) op.create_table('system_products', sa.Column('name', sa.String(length=20), nullable=False, comment='产品名'), sa.Column('category', sa.Enum('VIP', 'POINTS', name='productcategory', inherit_schema=True), nullable=False, comment='商品分类, vip-会员服务 points-积分服务'), sa.Column('price', sa.Integer(), nullable=False, comment='价格,不带小数点 单位为分'), sa.Column('action', sa.String(length=10), nullable=False, comment='付款后的动作,会员续期:vip_renewal 积分:recharge_points'), sa.Column('number', sa.Integer(), nullable=False, comment='执行动作的增量值'), sa.Column('description', sa.Text(), nullable=True, comment='商品描述'), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'), sa.PrimaryKeyConstraint('id'), comment='产品信息表' ) op.create_table('chat_participant', sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('chat_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint(['chat_id'], ['system_chats.id'], ), sa.ForeignKeyConstraint(['user_id'], ['system_users.user_id'], ), sa.PrimaryKeyConstraint('user_id', 'chat_id'), comment='聊天参与者关联表' ) op.create_table('system_messages', sa.Column('guid', sa.String(length=36), nullable=True), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('chat_id', sa.Integer(), nullable=False), sa.Column('message_type', sa.Enum('TEXT', 'IMAGE', 'READ', name='messagetype', inherit_schema=True), nullable=False), sa.Column('content', sa.String(length=5000), nullable=True, comment='文本消息'), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'), sa.ForeignKeyConstraint(['chat_id'], ['system_chats.id'], ), sa.ForeignKeyConstraint(['user_id'], ['system_users.user_id'], ), sa.PrimaryKeyConstraint('id'), comment='聊天消息表' ) op.create_index('idx_message_on_chat_id', 'system_messages', ['chat_id'], unique=False) op.create_index('idx_message_on_user_id', 'system_messages', ['user_id'], unique=False) op.create_index('idx_message_on_user_id_chat_id', 'system_messages', ['chat_id', 'user_id'], unique=False) op.create_table('system_read_status', sa.Column('last_read_message_id', sa.Integer(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=False), sa.Column('chat_id', sa.Integer(), nullable=False), sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='自增id'), sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='创建时间'), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间'), sa.ForeignKeyConstraint(['chat_id'], ['system_chats.id'], ), sa.ForeignKeyConstraint(['user_id'], ['system_users.user_id'], ), sa.PrimaryKeyConstraint('id'), comment='聊天消息读取状态表' ) op.create_index('idx_read_status_on_chat_id', 'system_read_status', ['chat_id'], unique=False) op.create_index('idx_read_status_on_user_id', 'system_read_status', ['user_id'], unique=False) op.drop_index('cert_and_card_number_source', table_name='system_cache_cards') op.create_index('idx_cert_and_card_number_source', 'system_cache_cards', ['cert_number', 'source'], unique=False) op.drop_index('cert_number_category_source', table_name='system_cards') op.create_index('idx_cert_number_category_source', 'system_cards', ['cert_number', 'category', 'source'], unique=False) op.add_column('system_user_collections', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间')) op.add_column('system_user_followers', sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=False, comment='更新时间')) op.create_index('idx_wechat_openid', 'system_users', ['wechat_openid'], unique=False) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index('idx_wechat_openid', table_name='system_users') op.drop_column('system_user_followers', 'updated_at') op.drop_column('system_user_collections', 'updated_at') op.drop_index('idx_cert_number_category_source', table_name='system_cards') op.create_index('cert_number_category_source', 'system_cards', ['cert_number', 'category', 'source'], unique=False) op.drop_index('idx_cert_and_card_number_source', table_name='system_cache_cards') op.create_index('cert_and_card_number_source', 'system_cache_cards', ['cert_number', 'source'], unique=False) op.drop_index('idx_read_status_on_user_id', table_name='system_read_status') op.drop_index('idx_read_status_on_chat_id', table_name='system_read_status') op.drop_table('system_read_status') op.drop_index('idx_message_on_user_id_chat_id', table_name='system_messages') op.drop_index('idx_message_on_user_id', table_name='system_messages') op.drop_index('idx_message_on_chat_id', table_name='system_messages') op.drop_table('system_messages') op.drop_table('chat_participant') op.drop_table('system_products') op.drop_index('idx_order_on_order_id', table_name='system_orders') op.drop_table('system_orders') op.drop_index('idx_chat_on_guid', table_name='system_chats') op.drop_table('system_chats') # ### end Alembic commands ###