a4d214964a
- 数据访问层统一: app/crud/{ad_reward,savings,signin,task,wallet}.py 移入
app/repositories/(与 user.py 同目录),删除 crud/;更新 10 处 import
(api/v1/* + scripts/* + repositories 内部交叉引用 app.crud→app.repositories)
- alembic/versions 9 个迁移文件去掉 hex 前缀,改成可读文件名(如
welfare_tables_coin_account_coin_txn.py);**仅重命名文件**,文件内
revision/down_revision 不动 → 迁移链与已迁移库的 alembic_version 不受影响
(alembic heads/history 验证链完好,单一 head c8d9e0f1a2b3)
- 测试: 37 passed(1 个 coupon 代理失败为连不到 pricebot 上游的环境问题,与本次无关)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
"""unique index on user.wechat_openid (一个微信只绑一个账号)
|
|
|
|
Revision ID: a7c8d9e0f1b2
|
|
Revises: f5b2d3c4e6a7
|
|
Create Date: 2026-05-25 19:10:00.000000
|
|
|
|
注意:升级前需保证 wechat_openid 无重复值(NULL 不算重复)。
|
|
本仓库 data/app.db 升级前已手动清掉重复 openid(保留最近绑定的账号)。
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'a7c8d9e0f1b2'
|
|
down_revision: Union[str, Sequence[str], None] = 'f5b2d3c4e6a7'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# nullable 列上的唯一索引:SQLite / Postgres 都允许多个 NULL,只约束非空值唯一
|
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
|
batch_op.create_index(
|
|
batch_op.f('ix_user_wechat_openid'), ['wechat_openid'], unique=True
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table('user', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_user_wechat_openid'))
|