feat(chat): 聊天单向删除

This commit is contained in:
xingc
2025-05-15 18:24:05 +08:00
parent 99f15cff84
commit cc097a587f
8 changed files with 147 additions and 43 deletions

View File

@@ -27,6 +27,30 @@ from core.db.models import BaseModel # 假设你的 SQLAlchemy 模型在 models
target_metadata = BaseModel.metadata
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def do_run_migrations(connection):
context.configure(
connection=connection,
@@ -62,4 +86,4 @@ else:
asyncio.set_event_loop(loop)
# 运行迁移
loop.run_until_complete(run_migrations_online())
loop.run_until_complete(run_migrations_online())

View File

@@ -24,4 +24,4 @@ def upgrade() -> None:
def downgrade() -> None:
pass
op.drop_column("system_cards", 'diy_source')

View File

@@ -21,18 +21,18 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('system_products', 'action',
existing_type=mysql.ENUM('VIP_RENEWAL', 'RECHARGE_POINTS', 'FREE_GIFT'),
comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points 赠送产品free_gift',
existing_nullable=False)
existing_type=mysql.ENUM('VIP_RENEWAL', 'RECHARGE_POINTS', 'FREE_GIFT'),
comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points 赠送产品free_gift',
existing_nullable=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('system_products', 'action',
existing_type=mysql.ENUM('VIP_RENEWAL', 'RECHARGE_POINTS', 'FREE_GIFT'),
comment='付款后的动作会员续期vip_renewal 积分recharge_points 赠送产品free_gift',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_nullable=False)
existing_type=mysql.ENUM('VIP_RENEWAL', 'RECHARGE_POINTS'),
comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_comment='付款后的动作会员续期vip_renewal 积分recharge_points',
existing_nullable=False)
# ### end Alembic commands ###

View File

@@ -0,0 +1,62 @@
"""add chat_participant to orm
Revision ID: e9466c397aa2
Revises: 4a03470b2c09
Create Date: 2025-05-15 17:22:26.087396
"""
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 = 'e9466c397aa2'
down_revision: Union[str, None] = '4a03470b2c09'
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_chat_participant',
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('chat_id', sa.Integer(), nullable=False),
sa.Column('is_deleted', sa.Boolean, default=False, 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.drop_table('chat_participant')
op.alter_column('system_orders', 'status',
existing_type=mysql.ENUM('INIT', 'FAIL', 'OK', 'WAIT_PAYMENT', 'PAID', 'CANCEL'),
comment='订单状态init初始化 fail失败 ok完成 wait payment待支付 paid已支付 cancel. 取消',
existing_comment='订单状态init初始化 fail失败 ok完成 wait payment待支付 cancel. 取消',
existing_nullable=False,
existing_server_default=sa.text("'INIT'"))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('system_orders', 'status',
existing_type=mysql.ENUM('INIT', 'FAIL', 'OK', 'WAIT_PAYMENT', 'PAID', 'CANCEL'),
comment='订单状态init初始化 fail失败 ok完成 wait payment待支付 cancel. 取消',
existing_comment='订单状态init初始化 fail失败 ok完成 wait payment待支付 paid已支付 cancel. 取消',
existing_nullable=False,
existing_server_default=sa.text("'INIT'"))
op.create_table('chat_participant',
sa.Column('user_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
sa.Column('chat_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['chat_id'], ['system_chats.id'], name='chat_participant_ibfk_1'),
sa.ForeignKeyConstraint(['user_id'], ['system_users.user_id'], name='chat_participant_ibfk_2'),
sa.PrimaryKeyConstraint('user_id', 'chat_id'),
comment='聊天参与者关联表',
mysql_comment='聊天参与者关联表',
mysql_default_charset='utf8mb4',
mysql_engine='InnoDB'
)
op.drop_table('system_chat_participant')
# ### end Alembic commands ###