From 08e6e7220350a0f8f584246d3224199e9de53aea Mon Sep 17 00:00:00 2001 From: ChengCan <783785929@qq.com> Date: Thu, 26 Mar 2026 09:53:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=B7=BB=E7=94=A8=E6=88=B7=E8=AE=A4?= =?UTF-8?q?=E8=AF=81=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mini-program/database/sql/001_init_chat.sql | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/mini-program/database/sql/001_init_chat.sql b/mini-program/database/sql/001_init_chat.sql index 20a92d0..6ebf6a7 100644 --- a/mini-program/database/sql/001_init_chat.sql +++ b/mini-program/database/sql/001_init_chat.sql @@ -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,