接入服务号模板推送通知
This commit is contained in:
@@ -353,6 +353,59 @@ async def _ensure_device_family_tables(conn) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def _ensure_parent_wechat_accounts_table(conn) -> None:
|
||||
await conn.execute(
|
||||
text(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS parent_wechat_accounts (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT NOT NULL,
|
||||
app_id VARCHAR(64) NOT NULL,
|
||||
account_type VARCHAR(32) NOT NULL,
|
||||
openid VARCHAR(64) NOT NULL,
|
||||
unionid VARCHAR(64) NULL,
|
||||
subscribed TINYINT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_parent_wechat_app_openid (app_id, openid),
|
||||
UNIQUE KEY uq_parent_wechat_user_type (user_id, account_type),
|
||||
KEY idx_parent_wechat_user (user_id),
|
||||
KEY idx_parent_wechat_unionid (unionid),
|
||||
CONSTRAINT fk_parent_wechat_user
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES parents (user_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def _ensure_wechat_mp_bind_states_table(conn) -> None:
|
||||
await conn.execute(
|
||||
text(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS wechat_mp_bind_states (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
state VARCHAR(128) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
expires_at DATETIME NOT NULL,
|
||||
consumed_at DATETIME NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_wechat_mp_bind_state (state),
|
||||
KEY idx_wechat_mp_bind_user (user_id),
|
||||
KEY idx_wechat_mp_bind_expires (expires_at),
|
||||
CONSTRAINT fk_wechat_mp_bind_user
|
||||
FOREIGN KEY (user_id)
|
||||
REFERENCES parents (user_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def init_db():
|
||||
"""初始化数据库,创建所有表"""
|
||||
try:
|
||||
@@ -374,6 +427,8 @@ async def init_db():
|
||||
await _ensure_bind_session_card_columns(conn)
|
||||
await _ensure_cards_allow_multiple_per_device(conn)
|
||||
await _ensure_device_family_tables(conn)
|
||||
await _ensure_parent_wechat_accounts_table(conn)
|
||||
await _ensure_wechat_mp_bind_states_table(conn)
|
||||
await engine.dispose()
|
||||
session_logger.info("system", "database", "数据库表已成功创建")
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user