feat: add database-backed console login
This commit is contained in:
36
internal/storage/mysql/migrations/000029_console_auth.up.sql
Normal file
36
internal/storage/mysql/migrations/000029_console_auth.up.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
-- Orbit 控制台账号与会话;账号只用于人登录,业务 SDK 仍使用命名空间凭据。
|
||||
CREATE TABLE orbit_console_users (
|
||||
id BINARY(16) NOT NULL COMMENT '控制台账号标识,全局唯一',
|
||||
namespace_id BINARY(16) NOT NULL COMMENT '登录后可访问的命名空间',
|
||||
credential_id BINARY(16) NOT NULL COMMENT '登录后代表该账号调用 API 的业务凭据',
|
||||
revision BIGINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '乐观并发版本,从 1 开始',
|
||||
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间,统一 UTC',
|
||||
updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '最后更新时间,统一 UTC',
|
||||
username VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs NOT NULL COMMENT '登录名,大小写敏感',
|
||||
display_name VARCHAR(128) NOT NULL COMMENT '展示名称',
|
||||
password_hash VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL COMMENT 'bcrypt 密码哈希,不保存明文',
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE COMMENT '是否允许登录',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_console_username (username),
|
||||
KEY ix_console_user_principal (namespace_id, credential_id),
|
||||
CONSTRAINT ck_console_users_0 CHECK (revision > 0)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs COMMENT='控制台人类账号,不替代业务 SDK 凭据';
|
||||
|
||||
CREATE TABLE orbit_console_sessions (
|
||||
id BINARY(16) NOT NULL COMMENT '会话记录标识',
|
||||
user_id BINARY(16) NOT NULL COMMENT '控制台账号标识',
|
||||
namespace_id BINARY(16) NOT NULL COMMENT '会话对应命名空间',
|
||||
credential_id BINARY(16) NOT NULL COMMENT '会话对应业务凭据',
|
||||
token_digest BINARY(32) NOT NULL COMMENT '会话令牌摘要,不保存令牌原文',
|
||||
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间,统一 UTC',
|
||||
expires_at DATETIME(6) NOT NULL COMMENT '会话过期时间,统一 UTC',
|
||||
last_seen_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '最近一次使用时间,统一 UTC',
|
||||
revoked_at DATETIME(6) NULL COMMENT '撤销时间;为空表示未撤销',
|
||||
user_agent VARCHAR(512) NOT NULL DEFAULT '' COMMENT '登录时的客户端摘要',
|
||||
remote_addr VARCHAR(64) NOT NULL DEFAULT '' COMMENT '登录时的来源地址',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uq_console_session_token (token_digest),
|
||||
KEY ix_console_session_user (user_id, revoked_at, expires_at),
|
||||
KEY ix_console_session_expiry (expires_at, revoked_at),
|
||||
CONSTRAINT ck_console_sessions_0 CHECK (expires_at > created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_as_cs COMMENT='控制台 HttpOnly 登录会话,只保存令牌摘要';
|
||||
Reference in New Issue
Block a user