新添用户认证表

This commit is contained in:
ChengCan
2026-03-26 09:53:09 +08:00
parent 5a45ee1106
commit 08e6e72203

View File

@@ -11,6 +11,7 @@ SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS chat_message;
DROP TABLE IF EXISTS chat_conversation_member;
DROP TABLE IF EXISTS chat_conversation;
DROP TABLE IF EXISTS chat_user_auth;
DROP TABLE IF EXISTS chat_user;
SET FOREIGN_KEY_CHECKS=1;
@@ -27,6 +28,27 @@ CREATE TABLE IF NOT EXISTS chat_user (
KEY idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS chat_user_auth (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL,
auth_type TINYINT UNSIGNED NOT NULL COMMENT '1-wechat_miniapp_openid 2-wechat_unionid 3-phone_sms 4-email_magic_link 5-oauth 6-username_password',
auth_identifier VARCHAR(191) NOT NULL COMMENT 'openid/unionid/phone/email/oauth-sub/username',
password_hash CHAR(64) NULL COMMENT 'sha256 hex for demo only; production should use bcrypt/argon2',
credential_json JSON NULL COMMENT 'Extra auth payload, e.g. app_id/provider/phone_area',
is_primary TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '1-primary login identity 0-secondary',
status TINYINT UNSIGNED NOT NULL DEFAULT 1 COMMENT '1-active 2-disabled 3-revoked',
last_login_at DATETIME(3) NULL,
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
PRIMARY KEY (id),
UNIQUE KEY uk_auth_type_identifier (auth_type, auth_identifier),
KEY idx_user_status (user_id, status),
KEY idx_last_login_at (last_login_at),
CONSTRAINT fk_user_auth_user
FOREIGN KEY (user_id) REFERENCES chat_user(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS chat_conversation (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
title VARCHAR(128) NULL,
@@ -125,6 +147,60 @@ VALUES
'2026-03-25 21:11:00.000'
);
INSERT INTO chat_user_auth (
id,
user_id,
auth_type,
auth_identifier,
password_hash,
credential_json,
is_primary,
status,
last_login_at,
created_at,
updated_at
)
VALUES
(
1,
1,
6,
'test1',
SHA2('123', 256),
JSON_OBJECT('provider', 'local_account'),
1,
1,
'2026-03-25 09:58:00.000',
'2026-03-25 09:00:00.000',
'2026-03-25 09:58:00.000'
),
(
2,
2,
6,
'test2',
SHA2('123', 256),
JSON_OBJECT('provider', 'local_account'),
1,
1,
'2026-03-25 10:01:00.000',
'2026-03-25 09:20:00.000',
'2026-03-25 10:01:00.000'
),
(
3,
3,
6,
'test3',
SHA2('123', 256),
JSON_OBJECT('provider', 'local_account'),
1,
1,
'2026-03-25 21:11:00.000',
'2026-03-25 20:30:00.000',
'2026-03-25 21:11:00.000'
);
INSERT INTO chat_conversation (
id,
title,