feat: migrate IM identity and snowflake primary keys
This commit is contained in:
+10
-3
@@ -3,10 +3,12 @@
|
||||
-- Database: the currently selected tenant database.
|
||||
-- Important: one tenant owns one database, so these tables intentionally do not contain tenant_id.
|
||||
-- This SQL is for review first. Do not execute directly in production before confirming indexes and migration order.
|
||||
-- Non-auto-increment BIGINT primary keys are generated by the server Snowflake generator.
|
||||
|
||||
-- 1. Group profile and governance truth.
|
||||
-- Topic/Subscription remains the communication projection; this table is the product business truth.
|
||||
CREATE TABLE IF NOT EXISTS im_group_settings (
|
||||
id BIGINT NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
owner_user_id BIGINT NOT NULL,
|
||||
name VARCHAR(128) NOT NULL DEFAULT '',
|
||||
@@ -27,7 +29,8 @@ CREATE TABLE IF NOT EXISTS im_group_settings (
|
||||
dissolved_at DATETIME(3),
|
||||
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 (topic),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE INDEX uk_im_group_settings_topic (topic),
|
||||
INDEX idx_im_group_settings_owner (owner_user_id, group_status),
|
||||
INDEX idx_im_group_settings_status_updated (group_status, updated_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
@@ -135,19 +138,22 @@ CREATE TABLE IF NOT EXISTS im_group_announcements (
|
||||
|
||||
-- 6. Announcement read receipts.
|
||||
CREATE TABLE IF NOT EXISTS im_group_announcement_reads (
|
||||
id BIGINT NOT NULL,
|
||||
announcement_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
read_at DATETIME(3) NOT 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 (announcement_id, user_id),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE INDEX uk_im_group_announcement_reads_announcement_user (announcement_id, user_id),
|
||||
INDEX idx_im_group_announcement_reads_topic_user (topic, user_id, read_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- 7. Current member mute state.
|
||||
-- Historical changes are stored in im_group_admin_logs.
|
||||
CREATE TABLE IF NOT EXISTS im_group_mutes (
|
||||
id BIGINT NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
muted_by BIGINT NOT NULL,
|
||||
@@ -160,7 +166,8 @@ CREATE TABLE IF NOT EXISTS im_group_mutes (
|
||||
version INT NOT NULL DEFAULT 1,
|
||||
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 (topic, user_id),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE INDEX uk_im_group_mutes_topic_user (topic, user_id),
|
||||
INDEX idx_im_group_mutes_topic_status (topic, status, expires_at),
|
||||
INDEX idx_im_group_mutes_user_status (user_id, status, expires_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
Reference in New Issue
Block a user