b3b731f25d
冲突全在领券「弹窗频控按 App 独立」这一功能——本分支夹带的旧 WIP 草稿(2026-06-12, app_package 可空+NULL 兜底行)与 main 上已合并的最终版 #52(2026-06-14,package NOT NULL +"" 占位)是同一功能的两套不兼容实现。 解决:四个 coupon 文件(api/models/repositories/schemas)一律取 main(#52)——它是 权威已合版,且文件未冲突区已自动并入 #52 的签名,只有取 theirs 才自洽。 Alembic 收敛为单 head: - 删本分支 WIP 迁移 coupon_engagement_app_package(否则与 #52 重复建 per-App 列) 及其仅用于挂接它的两个空 merge 节点 3a9941e76909 / f3d0a16bb4c2 - device_liveness_table 的 down_revision 由 f3d0a16bb4c2 改挂 main 头 store_mapping_tb_dl_invalid 验证:alembic heads 单头;全链在临时 sqlite upgrade head 通过; coupon_prompt_engagement 只有 package、无 app_package;app 全量 import 通过。 注:本分支不再保留他人领券 WIP——无损,#52 即该功能的最终版,已在 main。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
"""device table (无障碍保护存活检测 + 极光推送)
|
|
|
|
Revision ID: device_liveness_table
|
|
Revises: store_mapping_tb_dl_invalid
|
|
Create Date: 2026-06-15 12:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'device_liveness_table'
|
|
down_revision: Union[str, Sequence[str], None] = 'store_mapping_tb_dl_invalid'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
'device',
|
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('device_id', sa.String(length=128), nullable=False),
|
|
sa.Column('registration_id', sa.String(length=64), nullable=True),
|
|
sa.Column('platform', sa.String(length=16), nullable=False),
|
|
sa.Column('app_version', sa.String(length=32), nullable=True),
|
|
sa.Column('ever_protected', sa.Boolean(), nullable=False),
|
|
sa.Column('last_heartbeat_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('last_report_protection_on', sa.Boolean(), nullable=False),
|
|
sa.Column('liveness_state', sa.String(length=16), nullable=False),
|
|
sa.Column('notified_at', sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('user_id', 'device_id', name='uq_device_user_device'),
|
|
)
|
|
with op.batch_alter_table('device', schema=None) as batch_op:
|
|
batch_op.create_index(batch_op.f('ix_device_user_id'), ['user_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_device_device_id'), ['device_id'], unique=False)
|
|
batch_op.create_index(batch_op.f('ix_device_last_heartbeat_at'), ['last_heartbeat_at'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table('device', schema=None) as batch_op:
|
|
batch_op.drop_index(batch_op.f('ix_device_last_heartbeat_at'))
|
|
batch_op.drop_index(batch_op.f('ix_device_device_id'))
|
|
batch_op.drop_index(batch_op.f('ix_device_user_id'))
|
|
|
|
op.drop_table('device')
|