Files
xiaobai-review/backend/database/migrations/m0005_account_switch_grants.py
T
f0a1adf52f 施工(HEL-226): 实现登录门户与本机免密切换账号
用设备 Cookie 和授权表记住本机已验证账号,登录页按确认样图做成门户,不再把密码写进浏览器。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-08-29 11:24:39 +08:00

43 lines
1.2 KiB
Python

from __future__ import annotations
import sqlite3
from backend.database.migrations.runner import Migration
def create_account_switch_grants(connection: sqlite3.Connection) -> None:
connection.execute(
"""
CREATE TABLE IF NOT EXISTS account_switch_grants (
id INTEGER PRIMARY KEY AUTOINCREMENT,
device_hash TEXT NOT NULL,
user_id INTEGER NOT NULL,
granted_at TEXT NOT NULL,
last_used_at TEXT NOT NULL,
expires_at TEXT NOT NULL,
UNIQUE (device_hash, user_id),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
)
"""
)
connection.execute(
"""
CREATE INDEX IF NOT EXISTS idx_account_switch_grants_device
ON account_switch_grants(device_hash, last_used_at DESC)
"""
)
connection.execute(
"""
CREATE INDEX IF NOT EXISTS idx_account_switch_grants_expiry
ON account_switch_grants(expires_at)
"""
)
MIGRATION = Migration(
version="0005",
name="create_account_switch_grants",
action=create_account_switch_grants,
signature="account-switch-grants:v1:device,user,granted,used,expires,unique",
)