Files
X25020501_card_book/alembic/versions/4a97e1258bbb_feat_points.py
2025-05-07 22:52:09 +08:00

70 lines
3.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""feat points
Revision ID: 4a97e1258bbb
Revises: e2a204afe670
Create Date: 2025-05-07 20:08:47.923509
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision: str = '4a97e1258bbb'
down_revision: Union[str, None] = 'e2a204afe670'
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_points_transaction',
sa.Column('user_id', sa.Integer(), nullable=False, comment='用户id'),
sa.Column('transaction_type', sa.Integer(), nullable=False, comment='交易类型1-充值 2-消费 3-赠送 4-过期 5-系统调整'),
sa.Column('product_id', sa.Integer(), nullable=True, comment='关联产品id'),
sa.Column('points', sa.Integer(), nullable=False, comment='积分数量(正数表示增加,负数表示减少)'),
sa.Column('balance', sa.Integer(), nullable=False, comment='交易后余额'),
sa.Column('status', sa.Integer(), nullable=False, comment='状态0-无效 1-有效 2-已撤销'),
sa.Column('description', sa.String(length=255), 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.add_column('system_orders', sa.Column('ip_address', sa.String(length=255), nullable=True, comment='操作ip'))
op.add_column('system_products', sa.Column('gift_id', sa.Integer(), nullable=True, comment='礼物产品id'))
op.alter_column('system_products', 'category',
existing_type=mysql.ENUM('VIP', 'POINTS', 'GIFT'),
comment='商品分类, vip-会员服务 points-积分服务 gift-礼物',
existing_comment='商品分类, vip-会员服务 points-积分服务',
existing_nullable=False)
op.alter_column('system_products', 'action',
existing_type=mysql.VARCHAR(length=30),
type_=sa.Enum('VIP_RENEWAL', 'RECHARGE_POINTS', 'FREE_GIFT', name='productaction', inherit_schema=True),
comment='付款后的动作会员续期vip_renewal 积分recharge_points 赠送产品free_gift',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_nullable=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('system_products', 'action',
existing_type=sa.Enum('VIP_RENEWAL', 'RECHARGE_POINTS', 'FREE_GIFT', name='productaction', inherit_schema=True),
type_=mysql.VARCHAR(length=30),
comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points 赠送产品free_gift',
existing_nullable=False)
op.alter_column('system_products', 'category',
existing_type=mysql.ENUM('VIP', 'POINTS', 'GIFT'),
comment='商品分类, vip-会员服务 points-积分服务',
existing_comment='商品分类, vip-会员服务 points-积分服务 gift-礼物',
existing_nullable=False)
op.drop_column('system_products', 'gift_id')
op.drop_column('system_orders', 'ip_address')
op.drop_table('system_points_transaction')
# ### end Alembic commands ###