feat: complete IM P0 and P1 reliability work
This commit is contained in:
+13
-15
@@ -1,14 +1,12 @@
|
||||
-- IM group business tables design.
|
||||
-- Scope: chapter 6 group chat business truth tables.
|
||||
-- Database: tenant database, default tinode.
|
||||
-- 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.
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS tinode CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
|
||||
|
||||
-- 1. Group profile and governance truth.
|
||||
-- Topic/Subscription remains the communication projection; this table is the product business truth.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_settings (
|
||||
CREATE TABLE IF NOT EXISTS im_group_settings (
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
owner_user_id BIGINT NOT NULL,
|
||||
name VARCHAR(128) NOT NULL DEFAULT '',
|
||||
@@ -36,7 +34,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_settings (
|
||||
|
||||
-- 2. Group members and role truth.
|
||||
-- Role changes must update this table and the Tinode Subscription ACL in the same transaction.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_members (
|
||||
CREATE TABLE IF NOT EXISTS im_group_members (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
@@ -63,7 +61,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_members (
|
||||
-- 3. Direct invitations.
|
||||
-- If join_approval is off, accepting an invitation can directly create im_group_members + Subscription.
|
||||
-- If join_approval is on, accepting may create a pending im_group_join_requests record.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_invitations (
|
||||
CREATE TABLE IF NOT EXISTS im_group_invitations (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
invitation_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
@@ -87,7 +85,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_invitations (
|
||||
|
||||
-- 4. Join requests.
|
||||
-- Pending users must not have a readable Subscription before approval.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_join_requests (
|
||||
CREATE TABLE IF NOT EXISTS im_group_join_requests (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
request_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
@@ -114,7 +112,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_join_requests (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- 5. Group announcements.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_announcements (
|
||||
CREATE TABLE IF NOT EXISTS im_group_announcements (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
announcement_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
@@ -136,7 +134,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_announcements (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
-- 6. Announcement read receipts.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_announcement_reads (
|
||||
CREATE TABLE IF NOT EXISTS im_group_announcement_reads (
|
||||
announcement_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
@@ -149,7 +147,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_announcement_reads (
|
||||
|
||||
-- 7. Current member mute state.
|
||||
-- Historical changes are stored in im_group_admin_logs.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_mutes (
|
||||
CREATE TABLE IF NOT EXISTS im_group_mutes (
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
user_id BIGINT NOT NULL,
|
||||
muted_by BIGINT NOT NULL,
|
||||
@@ -169,7 +167,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_mutes (
|
||||
|
||||
-- 8. Group QR codes / invite tokens.
|
||||
-- qr_token should remain opaque to clients. Store only token hash.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_qrcodes (
|
||||
CREATE TABLE IF NOT EXISTS im_group_qrcodes (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
token_id VARCHAR(64) NOT NULL,
|
||||
token_hash CHAR(64) NOT NULL,
|
||||
@@ -189,7 +187,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_qrcodes (
|
||||
|
||||
-- 9. Group file directory.
|
||||
-- File binary metadata still lives in the existing file table/storage. This is the group-visible index.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_files (
|
||||
CREATE TABLE IF NOT EXISTS im_group_files (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
group_file_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
@@ -218,7 +216,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_files (
|
||||
|
||||
-- 10. Group operation audit logs.
|
||||
-- Store role changes, governance changes, mutes, announcements, owner transfer, dissolve, file delete, etc.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_admin_logs (
|
||||
CREATE TABLE IF NOT EXISTS im_group_admin_logs (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
log_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
@@ -241,7 +239,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_admin_logs (
|
||||
|
||||
-- 11. Group operation idempotency.
|
||||
-- This can later be replaced by a global HTTP idempotency table.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_idempotency (
|
||||
CREATE TABLE IF NOT EXISTS im_group_idempotency (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT NOT NULL,
|
||||
method VARCHAR(8) NOT NULL,
|
||||
@@ -260,7 +258,7 @@ CREATE TABLE IF NOT EXISTS tinode.im_group_idempotency (
|
||||
-- 12. Group outbox events.
|
||||
-- Transactional bridge for group.membership.updated, group.join_request.created,
|
||||
-- group.announcement.updated, group.role.updated, group.mute.updated, group.dissolved, etc.
|
||||
CREATE TABLE IF NOT EXISTS tinode.im_group_events_outbox (
|
||||
CREATE TABLE IF NOT EXISTS im_group_events_outbox (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
event_id VARCHAR(64) NOT NULL,
|
||||
topic VARCHAR(32) NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user