feat(accounts): 统一可换绑时间并加本地 7 天锁

- 新增官方时间、本地 bind_ok、7 天锁到期、检查时间和来源字段
- role_change_available_at 改为官方时间与本地锁取较晚者
- 绑定成功和官方探测统一写有效时间
- 分配过滤增加最近 elite bind_ok 的数据库兜底
- 迁移 0129 从 account_events 回填历史账号
- 补充字段/回填过滤测试和生命周期文档
This commit is contained in:
yml
2026-11-24 17:37:15 +08:00
parent a1530b7e74
commit 2e6303361c
11 changed files with 415 additions and 9 deletions
+9 -1
View File
@@ -44,7 +44,7 @@ TESTS_DIR = Path(__file__).resolve().parent
PROJECT_ROOT = TESTS_DIR.parent
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
HEAD_REVISION = "20261124_0128"
HEAD_REVISION = "20261124_0129"
# 迁移新增、但不声明在模型里的复合查询索引。
EXTRA_INDEXES = (
@@ -67,6 +67,11 @@ _ACCOUNT_PLATFORM_COLUMNS = {
"ck_observed_lifetime_seconds": "INTEGER NULL",
"ck_expiry_source": "VARCHAR(24) NOT NULL DEFAULT ''",
"value_tier": "INTEGER NULL",
"role_change_official_at": "DATETIME NULL",
"last_bind_ok_at": "DATETIME NULL",
"role_bind_lock_until": "DATETIME NULL",
"role_change_checked_at": "DATETIME NULL",
"role_change_source": "VARCHAR(16) NULL",
}
_LATER_ORM_COLUMNS = {
@@ -399,6 +404,7 @@ class TestMigrationSmoke:
cfg = _migration_config()
cfg.set_main_option("sqlalchemy.url", mig_url)
command.upgrade(cfg, "20261123_0123")
_add_account_platform_columns(mig_engine)
with Session(mig_engine) as session:
user = User(
username="binding-sync-user",
@@ -490,6 +496,7 @@ class TestMigrationSmoke:
cfg = _migration_config()
cfg.set_main_option("sqlalchemy.url", mig_url)
command.upgrade(cfg, "20261123_0125")
_add_account_platform_columns(mig_engine)
with Session(mig_engine) as session:
user = User(
username="false-binding-user",
@@ -607,6 +614,7 @@ class TestMigrationSmoke:
cfg = _migration_config()
cfg.set_main_option("sqlalchemy.url", mig_url)
command.upgrade(cfg, "20261123_0126")
_add_account_platform_columns(mig_engine)
with Session(mig_engine) as session:
user = User(
username="pending-link-user",