1621 lines
88 KiB
SQL
1621 lines
88 KiB
SQL
-- IM tenant business database initialization script.
|
|
-- Source baseline: local MySQL database `tinode` on 2026-09-13.
|
|
-- Purpose: create a clean business database for a new IM tenant.
|
|
--
|
|
-- Usage:
|
|
-- 1. Replace placeholders before execution:
|
|
-- __TENANT_DB__ -> new tenant business database, for example `tinode_acme`.
|
|
-- __TENANT_ID__ -> hotgo.im_tenant.id assigned to this tenant.
|
|
-- __TENANT_CODE__ -> public enterprise code, for example `acme`.
|
|
-- __TENANT_NAME__ -> tenant display name.
|
|
-- 2. Execute this SQL with a MySQL account that can CREATE DATABASE and write hotgo.im_tenant.
|
|
-- 3. Keep business tables empty; do not copy users, topics, messages, files, Kafka logs, or audit data from `tinode`.
|
|
--
|
|
-- Notes:
|
|
-- - This script intentionally seeds only stable metadata/default configuration.
|
|
-- - It does not copy default tenant's test users, groups, messages, login logs, or outbox rows.
|
|
-- - The IM Server must enable tenant_db_routing=true and use hotgo as tenant_registry_db when registry and tenant DB are separated.
|
|
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
CREATE DATABASE IF NOT EXISTS meeting_im DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
|
|
USE meeting_im;
|
|
|
|
-- ============================================================
|
|
-- 1. Tenant business schema.
|
|
-- ============================================================
|
|
CREATE TABLE IF NOT EXISTS `im_abuse_reasons` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`target_type` varchar(16) NOT NULL,
|
|
`reason_code` varchar(64) NOT NULL,
|
|
`label` varchar(128) NOT NULL,
|
|
`requires_description` tinyint NOT NULL DEFAULT '0',
|
|
`allows_evidence` tinyint NOT NULL DEFAULT '1',
|
|
`sort_order` int NOT NULL DEFAULT '0',
|
|
`enabled` tinyint 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 (`id`),
|
|
UNIQUE KEY `uk_im_abuse_reasons_type_code` (`target_type`,`reason_code`),
|
|
KEY `idx_im_abuse_reasons_type_order` (`target_type`,`enabled`,`sort_order`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_abuse_reports` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`report_id` varchar(64) NOT NULL,
|
|
`reporter_id` bigint NOT NULL,
|
|
`target_type` varchar(16) NOT NULL,
|
|
`target_user_id` bigint NOT NULL DEFAULT '0',
|
|
`target_topic` varchar(32) NOT NULL DEFAULT '',
|
|
`target_seq` bigint NOT NULL DEFAULT '0',
|
|
`reason_code` varchar(64) NOT NULL,
|
|
`description` text NOT NULL,
|
|
`evidence_file_ids` json DEFAULT NULL,
|
|
`snapshot` json DEFAULT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'received',
|
|
`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_im_abuse_reports_report` (`report_id`),
|
|
UNIQUE KEY `uk_im_abuse_reports_idempotency` (`reporter_id`,`idempotency_key`),
|
|
KEY `idx_im_abuse_reports_target` (`target_type`,`target_topic`,`target_seq`,`target_user_id`),
|
|
KEY `idx_im_abuse_reports_reporter` (`reporter_id`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_action_tokens` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`token_id` varchar(64) NOT NULL,
|
|
`action` varchar(64) NOT NULL,
|
|
`target` varchar(128) NOT NULL DEFAULT '',
|
|
`token_hash` char(64) NOT NULL,
|
|
`state` smallint NOT NULL,
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`consumed_at` datetime(3) DEFAULT 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_im_action_tokens_token` (`token_id`),
|
|
KEY `idx_im_action_tokens_user_action` (`user_id`,`action`,`target`,`state`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_app_releases` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`platform` varchar(32) NOT NULL,
|
|
`channel` varchar(32) NOT NULL DEFAULT 'stable',
|
|
`latest_version` varchar(64) NOT NULL,
|
|
`min_supported_version` varchar(64) NOT NULL,
|
|
`update_type` varchar(16) NOT NULL DEFAULT 'none',
|
|
`release_notes` text NOT NULL,
|
|
`store_url` varchar(512) NOT NULL DEFAULT '',
|
|
`package_url` varchar(512) NOT NULL DEFAULT '',
|
|
`checksum` varchar(128) NOT NULL DEFAULT '',
|
|
`remind_after_seconds` int NOT NULL DEFAULT '0',
|
|
`published_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(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 (`id`),
|
|
UNIQUE KEY `uk_im_app_releases_platform_channel` (`platform`,`channel`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_attendance_appeals` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`appeal_id` varchar(64) NOT NULL,
|
|
`record_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`appeal_type` varchar(64) NOT NULL,
|
|
`reason` varchar(512) NOT NULL,
|
|
`target_action` varchar(32) NOT NULL DEFAULT '',
|
|
`target_time` datetime(3) DEFAULT NULL,
|
|
`attachment_file_ids` json DEFAULT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'pending',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`submitted_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 (`id`),
|
|
UNIQUE KEY `uk_im_attendance_appeals_appeal` (`appeal_id`),
|
|
UNIQUE KEY `uk_im_attendance_appeals_idempotency` (`user_id`,`idempotency_key`),
|
|
KEY `idx_im_attendance_appeals_record` (`record_id`),
|
|
KEY `idx_im_attendance_appeals_user_status` (`user_id`,`status`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_attendance_checkins` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`checkin_id` varchar(64) NOT NULL,
|
|
`record_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`record_date` date NOT NULL,
|
|
`action` varchar(32) NOT NULL,
|
|
`rule_id` varchar(64) NOT NULL,
|
|
`shift_id` varchar(64) NOT NULL,
|
|
`client_time` datetime(3) NOT NULL,
|
|
`server_time` datetime(3) NOT NULL,
|
|
`result` varchar(32) NOT NULL,
|
|
`location` json DEFAULT NULL,
|
|
`wifi` json DEFAULT NULL,
|
|
`device` json DEFAULT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_attendance_checkins_checkin` (`checkin_id`),
|
|
UNIQUE KEY `uk_im_attendance_checkins_idempotency` (`user_id`,`idempotency_key`),
|
|
KEY `idx_im_attendance_checkins_record` (`record_id`,`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_attendance_records` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`record_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`record_date` date NOT NULL,
|
|
`rule_id` varchar(64) NOT NULL,
|
|
`shift_id` varchar(64) NOT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'not_checked',
|
|
`exceptions` json DEFAULT NULL,
|
|
`appeal_status` varchar(32) NOT NULL DEFAULT '',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_attendance_records_record` (`record_id`),
|
|
UNIQUE KEY `uk_im_attendance_records_user_date_shift` (`user_id`,`record_date`,`shift_id`),
|
|
KEY `idx_im_attendance_records_user_id` (`user_id`,`id` DESC),
|
|
KEY `idx_im_attendance_records_date_status` (`record_date`,`status`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_attendance_rules` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`rule_id` varchar(64) NOT NULL,
|
|
`name` varchar(128) NOT NULL,
|
|
`workday` tinyint NOT NULL DEFAULT '1',
|
|
`location_required` tinyint NOT NULL DEFAULT '0',
|
|
`wifi_required` tinyint NOT NULL DEFAULT '0',
|
|
`allow_outside_checkin` tinyint NOT NULL DEFAULT '1',
|
|
`appeal_allowed` tinyint NOT NULL DEFAULT '1',
|
|
`effective_from` date DEFAULT NULL,
|
|
`effective_to` date DEFAULT NULL,
|
|
`state` varchar(16) NOT NULL DEFAULT 'active',
|
|
`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_im_attendance_rules_rule` (`rule_id`),
|
|
KEY `idx_im_attendance_rules_state` (`state`,`effective_from`,`effective_to`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_attendance_shifts` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`shift_id` varchar(64) NOT NULL,
|
|
`rule_id` varchar(64) NOT NULL,
|
|
`name` varchar(128) NOT NULL,
|
|
`work_start` time NOT NULL,
|
|
`work_end` time NOT NULL,
|
|
`checkin_start` time NOT NULL,
|
|
`checkout_end` time NOT NULL,
|
|
`state` varchar(16) NOT NULL DEFAULT 'active',
|
|
`sort_order` int NOT NULL DEFAULT '0',
|
|
`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_im_attendance_shifts_shift` (`shift_id`),
|
|
KEY `idx_im_attendance_shifts_rule` (`rule_id`,`state`,`sort_order`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_audit_logs` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`actor_uid` bigint NOT NULL DEFAULT '0',
|
|
`actor_role` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`action` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
|
|
`target_type` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`target_id` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`before_snapshot` json DEFAULT NULL,
|
|
`after_snapshot` json DEFAULT NULL,
|
|
`reason` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`request_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`ip` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`user_agent` varchar(512) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
|
`metadata` json DEFAULT NULL,
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_im_audit_logs_actor` (`actor_uid`,`id` DESC),
|
|
KEY `idx_im_audit_logs_action` (`action`,`id` DESC),
|
|
KEY `idx_im_audit_logs_target` (`target_type`,`target_id`,`id` DESC),
|
|
KEY `idx_im_audit_logs_request` (`request_id`),
|
|
KEY `idx_im_audit_logs_created` (`created_at`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='IM租户审计日志';
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_auth` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`userid` bigint NOT NULL,
|
|
`authlvl` int NOT NULL,
|
|
`secret` varchar(255) NOT NULL,
|
|
`expires` datetime DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `auth_userid` (`userid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_business_events_outbox` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`event_id` varchar(64) NOT NULL,
|
|
`target_type` varchar(16) NOT NULL,
|
|
`target` varchar(128) NOT NULL,
|
|
`actor_user_id` bigint NOT NULL DEFAULT '0',
|
|
`event_type` varchar(64) NOT NULL,
|
|
`payload` json DEFAULT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`attempts` int NOT NULL DEFAULT '0',
|
|
`next_retry_at` datetime(3) DEFAULT NULL,
|
|
`delivered_at` datetime(3) DEFAULT 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_im_business_events_outbox_event` (`event_id`),
|
|
KEY `idx_im_business_events_outbox_pending` (`status`,`next_retry_at`,`id`),
|
|
KEY `idx_im_business_events_outbox_target` (`target_type`,`target`,`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_call_records` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`call_id` varchar(64) NOT NULL,
|
|
`topic` char(25) NOT NULL,
|
|
`seq_id` bigint NOT NULL,
|
|
`caller_id` bigint NOT NULL,
|
|
`callee_id` bigint NOT NULL,
|
|
`call_type` varchar(16) NOT NULL,
|
|
`status` varchar(32) NOT NULL,
|
|
`end_reason` varchar(64) NOT NULL DEFAULT '',
|
|
`duration_ms` bigint NOT NULL DEFAULT '0',
|
|
`started_at` datetime(3) NOT NULL,
|
|
`accepted_at` datetime(3) DEFAULT NULL,
|
|
`finished_at` datetime(3) DEFAULT 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_im_call_records_call` (`call_id`),
|
|
UNIQUE KEY `uk_im_call_records_topic_seq` (`topic`,`seq_id`),
|
|
KEY `idx_im_call_records_caller` (`caller_id`,`id` DESC),
|
|
KEY `idx_im_call_records_callee` (`callee_id`,`id` DESC),
|
|
KEY `idx_im_call_records_status` (`status`,`updated_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_conversation_settings` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`topic` varchar(128) NOT NULL,
|
|
`pinned` tinyint NOT NULL DEFAULT '0',
|
|
`muted` tinyint NOT NULL DEFAULT '0',
|
|
`remark` varchar(128) NOT NULL DEFAULT '',
|
|
`message_retention` varchar(32) NOT NULL DEFAULT 'default',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_conversation_settings_user_topic` (`user_id`,`topic`),
|
|
KEY `idx_im_conversation_settings_user_pinned` (`user_id`,`pinned`,`updated_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_credentials` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`deletedat` datetime(3) DEFAULT NULL,
|
|
`method` varchar(16) NOT NULL,
|
|
`value` varchar(128) NOT NULL,
|
|
`synthetic` varchar(192) NOT NULL,
|
|
`userid` bigint NOT NULL,
|
|
`resp` varchar(255) DEFAULT NULL,
|
|
`done` tinyint NOT NULL DEFAULT '0',
|
|
`retries` int NOT NULL DEFAULT '0',
|
|
PRIMARY KEY (`id`),
|
|
KEY `userid` (`userid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_daily_reports` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`report_id` varchar(64) NOT NULL,
|
|
`author_id` bigint NOT NULL,
|
|
`report_date` date NOT NULL,
|
|
`content` text NOT NULL,
|
|
`attachments` json DEFAULT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'draft',
|
|
`read_state` varchar(16) NOT NULL DEFAULT 'unread',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`submitted_at` datetime(3) DEFAULT 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_im_daily_reports_report` (`report_id`),
|
|
UNIQUE KEY `uk_im_daily_reports_author_date` (`author_id`,`report_date`),
|
|
KEY `idx_im_daily_reports_author_id` (`author_id`,`id` DESC),
|
|
KEY `idx_im_daily_reports_date_status` (`report_date`,`status`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_dellog` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`topic` char(25) NOT NULL,
|
|
`deletedfor` bigint NOT NULL DEFAULT '0',
|
|
`delid` int NOT NULL,
|
|
`low` int NOT NULL,
|
|
`hi` int NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `dellog_topic_delid_deletedfor` (`topic`,`delid`,`deletedfor`),
|
|
KEY `dellog_topic_deletedfor_low_hi` (`topic`,`deletedfor`,`low`,`hi`),
|
|
KEY `dellog_deletedfor` (`deletedfor`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_device_push_tokens` (
|
|
`id` bigint NOT NULL,
|
|
`device_id` varchar(128) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`provider` varchar(32) NOT NULL,
|
|
`token` varchar(512) NOT NULL,
|
|
`app_version` varchar(64) NOT NULL DEFAULT '',
|
|
`platform` varchar(32) NOT NULL DEFAULT '',
|
|
`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_im_device_push_tokens_provider_token` (`provider`,`token`),
|
|
UNIQUE KEY `uk_im_device_push_tokens_device` (`device_id`),
|
|
KEY `idx_im_device_push_tokens_user` (`user_id`,`updated_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_devices` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`userid` bigint NOT NULL,
|
|
`hash` char(16) NOT NULL,
|
|
`deviceid` text NOT NULL,
|
|
`platform` varchar(32) DEFAULT NULL,
|
|
`lastseen` datetime NOT NULL,
|
|
`lang` varchar(8) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `userid` (`userid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_favorites` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`favorite_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`item_type` varchar(16) NOT NULL,
|
|
`source_topic` char(25) NOT NULL,
|
|
`source_seq` bigint NOT NULL,
|
|
`snapshot` json DEFAULT NULL,
|
|
`attachment_refs` json DEFAULT NULL,
|
|
`availability` varchar(16) NOT NULL DEFAULT 'available',
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`collected_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 (`id`),
|
|
UNIQUE KEY `uk_im_favorites_favorite` (`favorite_id`),
|
|
UNIQUE KEY `uk_im_favorites_source` (`user_id`,`source_topic`,`source_seq`),
|
|
UNIQUE KEY `uk_im_favorites_idempotency` (`user_id`,(nullif(`idempotency_key`,_utf8mb4''))),
|
|
KEY `idx_im_favorites_inbox` (`user_id`,`id` DESC),
|
|
KEY `idx_im_favorites_type` (`user_id`,`item_type`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_feedback_config` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`categories` json DEFAULT NULL,
|
|
`max_length` int NOT NULL DEFAULT '1000',
|
|
`attachment_policy` json DEFAULT NULL,
|
|
`allow_contact` tinyint NOT NULL DEFAULT '1',
|
|
`diagnostics_notice` text 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 (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_feedback_submissions` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`feedback_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`category` varchar(64) NOT NULL,
|
|
`content` text NOT NULL,
|
|
`contact` varchar(128) NOT NULL DEFAULT '',
|
|
`attachment_file_ids` json DEFAULT NULL,
|
|
`client_context` json DEFAULT NULL,
|
|
`include_diagnostics` tinyint NOT NULL DEFAULT '0',
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'received',
|
|
`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_im_feedback_submissions_feedback` (`feedback_id`),
|
|
UNIQUE KEY `uk_im_feedback_submissions_idempotency` (`user_id`,`idempotency_key`),
|
|
KEY `idx_im_feedback_submissions_user` (`user_id`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_file_review_tasks` (
|
|
`id` bigint NOT NULL,
|
|
`task_id` varchar(64) NOT NULL,
|
|
`file_id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL DEFAULT '0',
|
|
`task_type` varchar(32) NOT NULL,
|
|
`provider` varchar(64) NOT NULL,
|
|
`storage_provider` varchar(32) NOT NULL DEFAULT '',
|
|
`object_name` varchar(2048) NOT NULL DEFAULT '',
|
|
`mime_type` varchar(255) NOT NULL DEFAULT '',
|
|
`file_size` bigint NOT NULL DEFAULT '0',
|
|
`provider_task_id` varchar(128) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`risk_level` varchar(32) NOT NULL DEFAULT '',
|
|
`risk_labels` json DEFAULT NULL,
|
|
`result_json` json DEFAULT NULL,
|
|
`error_code` varchar(64) NOT NULL DEFAULT '',
|
|
`error_message` varchar(512) NOT NULL DEFAULT '',
|
|
`attempts` int NOT NULL DEFAULT '0',
|
|
`next_retry_at` datetime(3) DEFAULT NULL,
|
|
`completed_at` datetime(3) DEFAULT 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_im_file_review_tasks_task` (`task_id`),
|
|
UNIQUE KEY `uk_im_file_review_tasks_file_provider` (`file_id`,`task_type`,`provider`),
|
|
KEY `idx_im_file_review_tasks_pending` (`status`,`next_retry_at`,`id`),
|
|
KEY `idx_im_file_review_tasks_file` (`file_id`),
|
|
KEY `idx_im_file_review_tasks_provider_task` (`provider`,`provider_task_id`),
|
|
KEY `idx_im_file_review_tasks_object` (`storage_provider`,`object_name`(191))
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_filemsglinks` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`fileid` bigint NOT NULL,
|
|
`msgid` int DEFAULT NULL,
|
|
`topic` char(25) DEFAULT NULL,
|
|
`userid` bigint DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `fileid` (`fileid`),
|
|
KEY `msgid` (`msgid`),
|
|
KEY `topic` (`topic`),
|
|
KEY `userid` (`userid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_fileuploads` (
|
|
`id` bigint NOT NULL,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`userid` bigint DEFAULT NULL,
|
|
`status` int NOT NULL,
|
|
`mimetype` varchar(255) NOT NULL,
|
|
`size` bigint NOT NULL,
|
|
`etag` varchar(128) DEFAULT NULL,
|
|
`location` varchar(2048) NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `fileuploads_status` (`status`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_friend_requests` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`request_id` varchar(64) NOT NULL,
|
|
`applicant_id` bigint NOT NULL,
|
|
`target_id` bigint NOT NULL,
|
|
`message` varchar(200) NOT NULL DEFAULT '',
|
|
`source` varchar(32) NOT NULL DEFAULT '',
|
|
`source_topic` varchar(64) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`handled_at` datetime(3) DEFAULT 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_im_friend_requests_request` (`request_id`),
|
|
UNIQUE KEY `uk_im_friend_requests_idempotency` (`applicant_id`,`idempotency_key`),
|
|
KEY `idx_im_friend_requests_pair` (`applicant_id`,`target_id`,`status`,`created_at`),
|
|
KEY `idx_im_friend_requests_inbox` (`target_id`,`status`,`created_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_friendships` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`peer_id` bigint NOT NULL,
|
|
`status` varchar(16) NOT NULL,
|
|
`remark` varchar(64) NOT NULL DEFAULT '',
|
|
`topic` char(25) NOT NULL DEFAULT '',
|
|
`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_im_friendships_pair` (`user_id`,`peer_id`),
|
|
KEY `idx_im_friendships_peer` (`peer_id`,`status`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`operator_id` bigint NOT NULL,
|
|
`target_user_id` bigint DEFAULT NULL,
|
|
`action` varchar(64) NOT NULL,
|
|
`object_type` varchar(32) NOT NULL DEFAULT '',
|
|
`object_id` varchar(64) NOT NULL DEFAULT '',
|
|
`before_data` json DEFAULT NULL,
|
|
`after_data` json DEFAULT NULL,
|
|
`request_id` varchar(128) NOT NULL DEFAULT '',
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_group_admin_logs_log` (`log_id`),
|
|
KEY `idx_im_group_admin_logs_topic_time` (`topic`,`id` DESC),
|
|
KEY `idx_im_group_admin_logs_operator` (`operator_id`,`id` DESC),
|
|
KEY `idx_im_group_admin_logs_object` (`object_type`,`object_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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 (`id`),
|
|
UNIQUE KEY `uk_im_group_announcement_reads_announcement_user` (`announcement_id`,`user_id`),
|
|
KEY `idx_im_group_announcement_reads_topic_user` (`topic`,`user_id`,`read_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`author_user_id` bigint NOT NULL,
|
|
`content` text NOT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'current',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`published_at` datetime(3) NOT NULL,
|
|
`deleted_by` bigint DEFAULT NULL,
|
|
`deleted_at` datetime(3) DEFAULT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`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_im_group_announcements_announcement` (`announcement_id`),
|
|
UNIQUE KEY `uk_im_group_announcements_idempotency` (`topic`,`author_user_id`,`idempotency_key`),
|
|
KEY `idx_im_group_announcements_topic_status` (`topic`,`status`,`version` DESC,`id` DESC),
|
|
KEY `idx_im_group_announcements_topic_time` (`topic`,`published_at` DESC,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`actor_user_id` bigint NOT NULL DEFAULT '0',
|
|
`event_type` varchar(64) NOT NULL,
|
|
`payload` json DEFAULT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`attempts` int NOT NULL DEFAULT '0',
|
|
`next_retry_at` datetime(3) DEFAULT NULL,
|
|
`delivered_at` datetime(3) DEFAULT 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_im_group_events_outbox_event` (`event_id`),
|
|
KEY `idx_im_group_events_outbox_pending` (`status`,`next_retry_at`,`id`),
|
|
KEY `idx_im_group_events_outbox_topic` (`topic`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`file_id` varchar(64) NOT NULL,
|
|
`source_topic` varchar(32) NOT NULL DEFAULT '',
|
|
`source_seq` bigint NOT NULL DEFAULT '0',
|
|
`uploader_id` bigint NOT NULL,
|
|
`file_name` varchar(255) NOT NULL DEFAULT '',
|
|
`mime_type` varchar(128) NOT NULL DEFAULT '',
|
|
`file_type` varchar(32) NOT NULL DEFAULT 'file',
|
|
`file_size` bigint NOT NULL DEFAULT '0',
|
|
`status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`deleted_by` bigint DEFAULT NULL,
|
|
`deleted_at` datetime(3) DEFAULT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`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_im_group_files_group_file` (`group_file_id`),
|
|
UNIQUE KEY `uk_im_group_files_topic_file` (`topic`,`file_id`),
|
|
UNIQUE KEY `uk_im_group_files_idempotency` (`topic`,`uploader_id`,`idempotency_key`),
|
|
KEY `idx_im_group_files_topic_type` (`topic`,`status`,`file_type`,`id` DESC),
|
|
KEY `idx_im_group_files_topic_name` (`topic`,`status`,`file_name`),
|
|
KEY `idx_im_group_files_uploader` (`uploader_id`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_group_idempotency` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`method` varchar(8) NOT NULL,
|
|
`route` varchar(256) NOT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`body_hash` char(64) NOT NULL,
|
|
`result_code` int NOT NULL DEFAULT '0',
|
|
`result_body` json DEFAULT 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_im_group_idempotency_request` (`user_id`,`method`,`route`,`idempotency_key`),
|
|
KEY `idx_im_group_idempotency_created` (`created_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`inviter_user_id` bigint NOT NULL,
|
|
`target_user_id` bigint NOT NULL,
|
|
`message` varchar(256) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`result` varchar(32) NOT NULL DEFAULT '',
|
|
`join_request_id` varchar(64) NOT NULL DEFAULT '',
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`handled_at` datetime(3) DEFAULT 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_im_group_invitations_invitation` (`invitation_id`),
|
|
UNIQUE KEY `uk_im_group_invitations_idempotency` (`inviter_user_id`,`idempotency_key`),
|
|
KEY `idx_im_group_invitations_target` (`target_user_id`,`status`,`expires_at`),
|
|
KEY `idx_im_group_invitations_topic_status` (`topic`,`status`,`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`applicant_user_id` bigint NOT NULL,
|
|
`inviter_user_id` bigint DEFAULT NULL,
|
|
`source` varchar(32) NOT NULL DEFAULT 'manual',
|
|
`qr_token_hash` char(64) NOT NULL DEFAULT '',
|
|
`message` varchar(256) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`reject_reason` varchar(256) NOT NULL DEFAULT '',
|
|
`handled_by` bigint DEFAULT NULL,
|
|
`handled_at` datetime(3) DEFAULT NULL,
|
|
`expires_at` datetime(3) DEFAULT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_group_join_requests_request` (`request_id`),
|
|
UNIQUE KEY `uk_im_group_join_requests_idempotency` (`applicant_user_id`,`idempotency_key`),
|
|
KEY `idx_im_group_join_requests_topic_status` (`topic`,`status`,`id`),
|
|
KEY `idx_im_group_join_requests_applicant` (`applicant_user_id`,`topic`,`status`,`id`),
|
|
KEY `idx_im_group_join_requests_expire` (`status`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_group_members` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`topic` varchar(32) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`role` varchar(16) NOT NULL DEFAULT 'member',
|
|
`member_status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`nickname` varchar(64) NOT NULL DEFAULT '',
|
|
`pinned` tinyint NOT NULL DEFAULT '0',
|
|
`mute_notifications` tinyint NOT NULL DEFAULT '0',
|
|
`join_source` varchar(32) NOT NULL DEFAULT 'manual',
|
|
`joined_by` bigint DEFAULT NULL,
|
|
`joined_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`left_at` datetime(3) DEFAULT NULL,
|
|
`removed_by` bigint DEFAULT NULL,
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_group_members_topic_user` (`topic`,`user_id`),
|
|
KEY `idx_im_group_members_user_status` (`user_id`,`member_status`,`updated_at`),
|
|
KEY `idx_im_group_members_topic_role` (`topic`,`role`,`member_status`,`id`),
|
|
KEY `idx_im_group_members_topic_status` (`topic`,`member_status`,`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_group_messages` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`topic` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '群 Topic,如 grp_xxx',
|
|
`group_id` bigint NOT NULL COMMENT '业务群 ID,便于分区、治理和统计',
|
|
`seqid` bigint NOT NULL COMMENT '群内消息序号,由 Redis 原子发号',
|
|
`from_user` bigint NOT NULL COMMENT '发送人用户 ID',
|
|
`client_msg_id` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '客户端幂等消息 ID',
|
|
`msg_type` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'text' COMMENT 'text/image/file/audio/video/system 等',
|
|
`status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'normal' COMMENT 'normal/recalled/deleted/blocked',
|
|
`content` json DEFAULT NULL COMMENT '消息正文或 Drafty 内容',
|
|
`head` json DEFAULT NULL COMMENT '消息头,包含 @、引用、客户端能力等',
|
|
`mentioned_user_ids` json DEFAULT NULL COMMENT '@ 用户列表,便于提醒和检索',
|
|
`mention_all` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否 @ 全体',
|
|
`reply_seqid` bigint DEFAULT NULL COMMENT '回复的群消息 seq',
|
|
`root_seqid` bigint DEFAULT NULL COMMENT '线程或合并上下文根消息 seq',
|
|
`file_count` int NOT NULL DEFAULT '0' COMMENT '附件数量',
|
|
`content_size` int NOT NULL DEFAULT '0' COMMENT '正文 JSON 序列化后的字节数',
|
|
`has_risk` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否命中风控或内容安全',
|
|
`audit_status` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pass' COMMENT 'pass/pending/reject',
|
|
`version` int NOT NULL DEFAULT '1' COMMENT '编辑版本',
|
|
`recalled_at` datetime(3) DEFAULT NULL,
|
|
`recalled_by` bigint DEFAULT NULL,
|
|
`deleted_at` datetime(3) DEFAULT NULL,
|
|
`expires_at` datetime(3) DEFAULT NULL COMMENT '可选保留期,便于过期归档或清理',
|
|
`created_at` datetime(3) NOT NULL,
|
|
`updated_at` datetime(3) NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_group_messages_group_seq` (`group_id`,`seqid`),
|
|
UNIQUE KEY `uk_im_group_messages_topic_seq` (`topic`,`seqid`),
|
|
UNIQUE KEY `uk_im_group_messages_topic_sender_client_mid` (`topic`,`from_user`,`client_msg_id`),
|
|
KEY `idx_im_group_messages_group_created` (`group_id`,`created_at`),
|
|
KEY `idx_im_group_messages_group_status_seq` (`group_id`,`status`,`seqid`),
|
|
KEY `idx_im_group_messages_topic_created` (`topic`,`created_at`),
|
|
KEY `idx_im_group_messages_topic_from_seq` (`topic`,`from_user`,`seqid`),
|
|
KEY `idx_im_group_messages_audit` (`audit_status`,`created_at`),
|
|
KEY `idx_im_group_messages_expires` (`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
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,
|
|
`muted_at` datetime(3) NOT NULL,
|
|
`expires_at` datetime(3) DEFAULT NULL,
|
|
`reason` varchar(256) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`revoked_by` bigint DEFAULT NULL,
|
|
`revoked_at` datetime(3) DEFAULT NULL,
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_group_mutes_topic_user` (`topic`,`user_id`),
|
|
KEY `idx_im_group_mutes_topic_status` (`topic`,`status`,`expires_at`),
|
|
KEY `idx_im_group_mutes_user_status` (`user_id`,`status`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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,
|
|
`topic` varchar(32) NOT NULL,
|
|
`created_by` bigint NOT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`revoked_by` bigint DEFAULT NULL,
|
|
`revoked_at` datetime(3) DEFAULT 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_im_group_qrcodes_token` (`token_id`),
|
|
UNIQUE KEY `uk_im_group_qrcodes_hash` (`token_hash`),
|
|
KEY `idx_im_group_qrcodes_topic_status` (`topic`,`status`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
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 '',
|
|
`avatar_file_id` varchar(64) NOT NULL DEFAULT '',
|
|
`description` varchar(512) NOT NULL DEFAULT '',
|
|
`group_status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`join_approval` tinyint NOT NULL DEFAULT '0',
|
|
`mute_all` tinyint NOT NULL DEFAULT '0',
|
|
`member_upload_files` tinyint NOT NULL DEFAULT '1',
|
|
`member_private_chat` tinyint NOT NULL DEFAULT '1',
|
|
`member_invite` tinyint NOT NULL DEFAULT '1',
|
|
`max_member_count` int NOT NULL DEFAULT '0' COMMENT '0 means use tenant default or unlimited',
|
|
`max_admin_count` int NOT NULL DEFAULT '10',
|
|
`member_count` int NOT NULL DEFAULT '0',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`created_by` bigint NOT NULL,
|
|
`dissolved_by` bigint DEFAULT NULL,
|
|
`dissolved_at` datetime(3) DEFAULT 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_im_group_settings_topic` (`topic`),
|
|
KEY `idx_im_group_settings_owner` (`owner_user_id`,`group_status`),
|
|
KEY `idx_im_group_settings_status_updated` (`group_status`,`updated_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_http_idempotency` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`method` varchar(8) NOT NULL,
|
|
`route` varchar(512) NOT NULL,
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`body_hash` char(64) NOT NULL,
|
|
`state` varchar(16) NOT NULL DEFAULT 'processing',
|
|
`response_status` int NOT NULL DEFAULT '0',
|
|
`response_body` mediumblob,
|
|
`expires_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 (`id`),
|
|
UNIQUE KEY `uk_im_http_idempotency_scope` (`user_id`,`method`,`route`,`idempotency_key`),
|
|
KEY `idx_im_http_idempotency_expiry` (`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_kafka_consume_log` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`event_id` varchar(96) NOT NULL,
|
|
`consumer_group` varchar(128) NOT NULL,
|
|
`source_topic` varchar(128) NOT NULL,
|
|
`event_type` varchar(96) NOT NULL DEFAULT '',
|
|
`biz_type` varchar(64) NOT NULL DEFAULT '',
|
|
`biz_id` varchar(128) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'processing',
|
|
`retry_count` int NOT NULL DEFAULT '0',
|
|
`last_reason` varchar(64) NOT NULL DEFAULT '',
|
|
`last_error` varchar(1000) NOT NULL DEFAULT '',
|
|
`processing_deadline` datetime(3) DEFAULT NULL,
|
|
`succeeded_at` datetime(3) DEFAULT NULL,
|
|
`dead_at` datetime(3) DEFAULT 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_im_kafka_consume_log_event_group` (`event_id`,`consumer_group`),
|
|
KEY `idx_im_kafka_consume_log_status` (`status`,`processing_deadline`),
|
|
KEY `idx_im_kafka_consume_log_biz` (`biz_type`,`biz_id`),
|
|
KEY `idx_im_kafka_consume_log_topic` (`source_topic`,`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_kafka_dead_letters` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`dead_id` varchar(96) NOT NULL,
|
|
`event_id` varchar(96) NOT NULL,
|
|
`parent_event_id` varchar(96) NOT NULL DEFAULT '',
|
|
`source_topic` varchar(128) NOT NULL,
|
|
`consumer_group` varchar(128) NOT NULL,
|
|
`event_type` varchar(96) NOT NULL DEFAULT '',
|
|
`biz_type` varchar(64) NOT NULL DEFAULT '',
|
|
`biz_id` varchar(128) NOT NULL DEFAULT '',
|
|
`envelope` json NOT NULL,
|
|
`retry_count` int NOT NULL DEFAULT '0',
|
|
`last_reason` varchar(64) NOT NULL DEFAULT '',
|
|
`last_error` varchar(1000) NOT NULL DEFAULT '',
|
|
`status` varchar(24) NOT NULL DEFAULT 'dead',
|
|
`replay_count` int NOT NULL DEFAULT '0',
|
|
`resolved_by` varchar(64) NOT NULL DEFAULT '',
|
|
`resolved_at` datetime(3) DEFAULT NULL,
|
|
`resolve_note` varchar(1000) NOT NULL DEFAULT '',
|
|
`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_im_kafka_dead_letters_dead` (`dead_id`),
|
|
KEY `idx_im_kafka_dead_letters_event` (`event_id`),
|
|
KEY `idx_im_kafka_dead_letters_status` (`status`,`created_at`),
|
|
KEY `idx_im_kafka_dead_letters_biz` (`biz_type`,`biz_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_kafka_outbox` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`event_id` varchar(96) NOT NULL,
|
|
`topic` varchar(128) NOT NULL,
|
|
`event_type` varchar(96) NOT NULL,
|
|
`biz_type` varchar(64) NOT NULL DEFAULT '',
|
|
`biz_id` varchar(128) NOT NULL DEFAULT '',
|
|
`key_value` varchar(256) NOT NULL DEFAULT '',
|
|
`envelope` json NOT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`attempts` int NOT NULL DEFAULT '0',
|
|
`next_retry_at` datetime(3) DEFAULT NULL,
|
|
`sent_at` datetime(3) DEFAULT NULL,
|
|
`last_reason` varchar(64) NOT NULL DEFAULT '',
|
|
`last_error` varchar(1000) NOT NULL DEFAULT '',
|
|
`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_im_kafka_outbox_event` (`event_id`),
|
|
KEY `idx_im_kafka_outbox_pending` (`status`,`next_retry_at`,`id`),
|
|
KEY `idx_im_kafka_outbox_biz` (`biz_type`,`biz_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_kvmeta` (
|
|
`id` bigint NOT NULL,
|
|
`key` varchar(64) NOT NULL,
|
|
`createdat` datetime(3) DEFAULT NULL,
|
|
`value` text,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_kvmeta_key` (`key`),
|
|
KEY `kvmeta_createdat_key` (`createdat`,`key`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_login_failure_logs` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint DEFAULT NULL,
|
|
`account_type` varchar(24) NOT NULL DEFAULT '',
|
|
`account_hash` char(64) NOT NULL DEFAULT '',
|
|
`account_mask` varchar(128) NOT NULL DEFAULT '',
|
|
`failure_type` varchar(32) NOT NULL,
|
|
`reason` varchar(96) NOT NULL DEFAULT '',
|
|
`detail` varchar(500) NOT NULL DEFAULT '',
|
|
`ip` varchar(64) NOT NULL DEFAULT '',
|
|
`region` varchar(128) NOT NULL DEFAULT '',
|
|
`device_id` varchar(255) NOT NULL DEFAULT '',
|
|
`platform` varchar(32) NOT NULL DEFAULT 'unknown',
|
|
`app_version` varchar(32) NOT NULL DEFAULT '',
|
|
`user_agent` varchar(512) NOT NULL DEFAULT '',
|
|
`risk_level` varchar(16) NOT NULL DEFAULT 'medium',
|
|
`risk_action` varchar(24) NOT NULL DEFAULT 'audit_only',
|
|
`request_id` varchar(64) NOT NULL DEFAULT '',
|
|
`attempt_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`metadata` json DEFAULT NULL,
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_im_login_failure_account_time` (`account_hash`,`attempt_at` DESC,`id` DESC),
|
|
KEY `idx_im_login_failure_user_time` (`user_id`,`attempt_at` DESC,`id` DESC),
|
|
KEY `idx_im_login_failure_ip_time` (`ip`,`attempt_at` DESC,`id` DESC),
|
|
KEY `idx_im_login_failure_type_time` (`failure_type`,`attempt_at` DESC,`id` DESC),
|
|
KEY `idx_im_login_failure_request` (`request_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_mailbox_config` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`enabled` tinyint NOT NULL DEFAULT '1',
|
|
`allow_anonymous` tinyint NOT NULL DEFAULT '1',
|
|
`required_fields` json DEFAULT NULL,
|
|
`max_length` int NOT NULL DEFAULT '5000',
|
|
`attachment_policy` json DEFAULT NULL,
|
|
`notice_title` varchar(128) NOT NULL DEFAULT '',
|
|
`notice_content` text NOT NULL,
|
|
`notice_updated_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(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 (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_mailbox_submissions` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`submission_id` varchar(64) NOT NULL,
|
|
`sender_id` bigint NOT NULL,
|
|
`subject` varchar(200) NOT NULL,
|
|
`content` text NOT NULL,
|
|
`anonymous` tinyint NOT NULL DEFAULT '0',
|
|
`attachment_file_ids` json DEFAULT NULL,
|
|
`notice_version` varchar(64) NOT NULL DEFAULT '',
|
|
`idempotency_key` varchar(128) NOT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'received',
|
|
`submitted_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 (`id`),
|
|
UNIQUE KEY `uk_im_mailbox_submissions_submission` (`submission_id`),
|
|
UNIQUE KEY `uk_im_mailbox_submissions_idempotency` (`sender_id`,`idempotency_key`),
|
|
KEY `idx_im_mailbox_submissions_sender` (`sender_id`,`id` DESC),
|
|
KEY `idx_im_mailbox_submissions_status` (`status`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_meeting_note_files` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`note_file_id` varchar(64) NOT NULL,
|
|
`meeting_id` varchar(64) NOT NULL,
|
|
`file_id` varchar(64) NOT NULL,
|
|
`uploader_id` bigint NOT NULL,
|
|
`file_name` varchar(255) NOT NULL DEFAULT '',
|
|
`mime_type` varchar(128) NOT NULL DEFAULT '',
|
|
`file_size` bigint NOT NULL DEFAULT '0',
|
|
`file_etag` varchar(128) NOT NULL DEFAULT '',
|
|
`status` varchar(16) NOT NULL DEFAULT 'active',
|
|
`preview_status` varchar(16) NOT NULL DEFAULT 'ready',
|
|
`preview_mode` varchar(16) NOT NULL DEFAULT 'native',
|
|
`preview_file_id` varchar(64) NOT NULL DEFAULT '',
|
|
`idempotency_key` varchar(128) NOT NULL DEFAULT '',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`deleted_by` bigint DEFAULT NULL,
|
|
`deleted_at` datetime(3) DEFAULT 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_im_meeting_note_files_id` (`note_file_id`),
|
|
UNIQUE KEY `uk_im_meeting_note_files_idempotency` (`meeting_id`,`uploader_id`,`idempotency_key`),
|
|
KEY `idx_im_meeting_note_files_file` (`meeting_id`,`file_id`,`status`),
|
|
KEY `idx_im_meeting_note_files_meeting` (`meeting_id`,`status`,`id` DESC),
|
|
KEY `idx_im_meeting_note_files_uploader` (`uploader_id`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_meeting_participants` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`meeting_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`response` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`response_at` datetime(3) DEFAULT 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_im_meeting_participants_user` (`meeting_id`,`user_id`),
|
|
KEY `idx_im_meeting_participants_user_time` (`user_id`,`meeting_id`),
|
|
KEY `idx_im_meeting_participants_response` (`meeting_id`,`response`),
|
|
CONSTRAINT `fk_im_meeting_participants_meeting` FOREIGN KEY (`meeting_id`) REFERENCES `im_meetings` (`meeting_id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_meetings` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`meeting_id` varchar(64) NOT NULL,
|
|
`organizer_id` bigint NOT NULL,
|
|
`recorder_user_id` bigint NOT NULL DEFAULT '0',
|
|
`title` varchar(200) NOT NULL,
|
|
`start_at` datetime(3) NOT NULL,
|
|
`end_at` datetime(3) NOT NULL,
|
|
`location` varchar(256) NOT NULL DEFAULT '',
|
|
`state` varchar(16) NOT NULL DEFAULT 'scheduled',
|
|
`reminder_minutes` json DEFAULT NULL,
|
|
`idempotency_key` varchar(128) DEFAULT NULL,
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`canceled_at` datetime(3) DEFAULT 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_im_meetings_meeting` (`meeting_id`),
|
|
UNIQUE KEY `uk_im_meetings_idempotency` (`organizer_id`,`idempotency_key`),
|
|
KEY `idx_im_meetings_organizer` (`organizer_id`,`start_at`),
|
|
KEY `idx_im_meetings_state_time` (`state`,`start_at`),
|
|
KEY `idx_im_meetings_recorder` (`recorder_user_id`,`end_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_message_admin_actions` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`action_id` varchar(96) NOT NULL,
|
|
`command_id` varchar(96) NOT NULL,
|
|
`conversation_type` varchar(16) NOT NULL,
|
|
`topic` varchar(64) NOT NULL,
|
|
`seqid` bigint NOT NULL,
|
|
`sender_user_id` bigint DEFAULT NULL,
|
|
`action` varchar(16) NOT NULL,
|
|
`action_status` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`reason` varchar(500) NOT NULL DEFAULT '',
|
|
`actor_admin_id` bigint NOT NULL DEFAULT '0',
|
|
`request_id` varchar(64) NOT NULL DEFAULT '',
|
|
`before_snapshot` json DEFAULT NULL,
|
|
`after_snapshot` json DEFAULT NULL,
|
|
`failure_reason` varchar(96) NOT NULL DEFAULT '',
|
|
`failure_message` varchar(1000) NOT NULL DEFAULT '',
|
|
`processed_at` datetime(3) DEFAULT 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_im_message_admin_action_id` (`action_id`),
|
|
UNIQUE KEY `uk_im_message_admin_command` (`command_id`),
|
|
KEY `idx_im_message_admin_target` (`conversation_type`,`topic`,`seqid`,`id` DESC),
|
|
KEY `idx_im_message_admin_status` (`action_status`,`created_at`,`id`),
|
|
KEY `idx_im_message_admin_actor` (`actor_admin_id`,`created_at` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_message_revisions` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`topic` char(25) NOT NULL,
|
|
`seqid` bigint NOT NULL,
|
|
`version` int NOT NULL,
|
|
`actor` bigint NOT NULL,
|
|
`head` json DEFAULT NULL,
|
|
`content` json DEFAULT NULL,
|
|
`reason` varchar(256) NOT NULL DEFAULT '',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_message_revisions_version` (`topic`,`seqid`,`version`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_messages` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`deletedat` datetime(3) DEFAULT NULL,
|
|
`delid` int DEFAULT '0',
|
|
`seqid` bigint NOT NULL,
|
|
`topic` char(25) NOT NULL,
|
|
`from` bigint NOT NULL,
|
|
`client_msg_id` varchar(64) DEFAULT NULL,
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`recalled_at` datetime(3) DEFAULT NULL,
|
|
`recalled_by` bigint DEFAULT NULL,
|
|
`head` json DEFAULT NULL,
|
|
`content` json DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `messages_sender_client_mid` (`from`,`client_msg_id`),
|
|
UNIQUE KEY `uk_im_messages_topic_seq` (`topic`,`seqid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_monthly_reports` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`report_id` varchar(64) NOT NULL,
|
|
`author_id` bigint NOT NULL,
|
|
`report_month` char(7) NOT NULL,
|
|
`work_summary` text NOT NULL,
|
|
`next_plan` text NOT NULL,
|
|
`attachments` json DEFAULT NULL,
|
|
`status` varchar(16) NOT NULL DEFAULT 'draft',
|
|
`read_state` varchar(16) NOT NULL DEFAULT 'unread',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`submitted_at` datetime(3) DEFAULT 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_im_monthly_reports_report` (`report_id`),
|
|
UNIQUE KEY `uk_im_monthly_reports_author_month` (`author_id`,`report_month`),
|
|
KEY `idx_im_monthly_reports_author_id` (`author_id`,`id` DESC),
|
|
KEY `idx_im_monthly_reports_month_status` (`report_month`,`status`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_org_departments` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`department_id` varchar(64) NOT NULL,
|
|
`name` varchar(128) NOT NULL,
|
|
`parent_id` varchar(64) NOT NULL DEFAULT 'root',
|
|
`sort_order` int NOT NULL DEFAULT '0',
|
|
`version` int NOT NULL DEFAULT '1',
|
|
`state` varchar(16) NOT NULL DEFAULT 'active',
|
|
`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_im_org_departments_department` (`department_id`),
|
|
KEY `idx_im_org_departments_parent` (`parent_id`,`state`,`sort_order`,`id`),
|
|
KEY `idx_im_org_departments_name` (`name`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_org_members` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`department_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`display_name` varchar(128) NOT NULL DEFAULT '',
|
|
`position` varchar(128) NOT NULL DEFAULT '',
|
|
`avatar_file_id` varchar(64) NOT NULL DEFAULT '',
|
|
`mobile` varchar(32) NOT NULL DEFAULT '',
|
|
`email` varchar(128) NOT NULL DEFAULT '',
|
|
`employment_state` varchar(16) NOT NULL DEFAULT 'active',
|
|
`contactable` tinyint NOT NULL DEFAULT '1',
|
|
`sort_order` int NOT NULL DEFAULT '0',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_org_members_department_user` (`department_id`,`user_id`),
|
|
KEY `idx_im_org_members_department` (`department_id`,`employment_state`,`sort_order`,`id`),
|
|
KEY `idx_im_org_members_user` (`user_id`),
|
|
KEY `idx_im_org_members_display_name` (`display_name`),
|
|
CONSTRAINT `fk_im_org_members_department` FOREIGN KEY (`department_id`) REFERENCES `im_org_departments` (`department_id`) ON DELETE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_org_visibility_overrides` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`visibility_scope` varchar(16) NOT NULL,
|
|
`state` varchar(16) NOT NULL DEFAULT 'active',
|
|
`remark` varchar(256) NOT NULL DEFAULT '',
|
|
`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_im_org_visibility_user` (`user_id`),
|
|
KEY `idx_im_org_visibility_scope` (`visibility_scope`,`state`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_realname_appeals` (
|
|
`id` bigint NOT NULL,
|
|
`appeal_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`reason` varchar(500) NOT NULL DEFAULT '',
|
|
`attachments_json` json DEFAULT NULL,
|
|
`status` varchar(32) NOT NULL DEFAULT 'pending',
|
|
`review_comment` varchar(500) NOT NULL DEFAULT '',
|
|
`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_im_realname_appeals_appeal` (`appeal_id`),
|
|
KEY `idx_im_realname_appeals_user` (`user_id`,`created_at`),
|
|
KEY `idx_im_realname_appeals_status` (`status`,`created_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_realname_verifications` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`submission_id` varchar(64) NOT NULL,
|
|
`status` varchar(16) NOT NULL,
|
|
`name_cipher` text NOT NULL,
|
|
`id_type` varchar(32) NOT NULL,
|
|
`id_number_cipher` text NOT NULL,
|
|
`id_number_hash` char(64) NOT NULL,
|
|
`masked_name` varchar(64) NOT NULL,
|
|
`masked_id_number` varchar(64) NOT NULL,
|
|
`review_reason` varchar(256) DEFAULT NULL,
|
|
`verified_at` datetime(3) DEFAULT 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_im_realname_submission` (`submission_id`),
|
|
KEY `idx_im_realname_user_latest` (`user_id`,`created_at`),
|
|
KEY `idx_im_realname_id_hash` (`id_number_hash`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_registration_invite_uses` (
|
|
`id` bigint NOT NULL,
|
|
`invite_code_id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`request_id` varchar(64) NOT NULL,
|
|
`used_at` datetime(3) NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_registration_invite_use_user` (`user_id`),
|
|
KEY `idx_im_registration_invite_use_request` (`request_id`),
|
|
KEY `idx_im_registration_invite_use_code` (`invite_code_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_risk_challenges` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`challenge_id` varchar(64) NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`action` varchar(64) NOT NULL,
|
|
`level` varchar(16) NOT NULL,
|
|
`notice_code` varchar(64) NOT NULL,
|
|
`notice_params` json DEFAULT NULL,
|
|
`state` varchar(16) NOT NULL DEFAULT 'pending',
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`decision` varchar(16) NOT NULL DEFAULT '',
|
|
`action_token_id` varchar(64) NOT NULL DEFAULT '',
|
|
`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_im_risk_challenges_challenge` (`challenge_id`),
|
|
KEY `idx_im_risk_challenges_user_state` (`user_id`,`state`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_subscriptions` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`deletedat` datetime(3) DEFAULT NULL,
|
|
`userid` bigint NOT NULL,
|
|
`topic` char(25) NOT NULL,
|
|
`delid` int DEFAULT '0',
|
|
`recvseqid` bigint DEFAULT '0',
|
|
`readseqid` bigint DEFAULT '0',
|
|
`modewant` char(8) DEFAULT NULL,
|
|
`modegiven` char(8) DEFAULT NULL,
|
|
`private` json DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `subscriptions_topic` (`topic`),
|
|
KEY `subscriptions_deletedat` (`deletedat`),
|
|
KEY `subscriptions_userid_topic_deletedat` (`userid`,`topic`,`deletedat`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_system_notifications` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`event_id` varchar(64) NOT NULL,
|
|
`event_type` varchar(64) NOT NULL,
|
|
`title` varchar(128) NOT NULL,
|
|
`summary` varchar(512) NOT NULL,
|
|
`action` json DEFAULT NULL,
|
|
`read_at` datetime(3) DEFAULT 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_im_system_notifications_event` (`user_id`,`event_id`),
|
|
KEY `idx_im_system_notifications_inbox` (`user_id`,`id` DESC)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_topic_drafts` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`topic` varchar(128) NOT NULL,
|
|
`content` text,
|
|
`entities_json` json DEFAULT NULL,
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_topic_drafts_user_topic` (`user_id`,`topic`),
|
|
KEY `idx_im_topic_drafts_user_updated` (`user_id`,`updated_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_topics` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`state` smallint NOT NULL DEFAULT '0',
|
|
`stateat` datetime(3) DEFAULT NULL,
|
|
`touchedat` datetime(3) DEFAULT NULL,
|
|
`name` char(25) NOT NULL,
|
|
`usebt` tinyint DEFAULT '0',
|
|
`owner` bigint NOT NULL DEFAULT '0',
|
|
`access` json DEFAULT NULL,
|
|
`seqid` bigint NOT NULL DEFAULT '0',
|
|
`delid` int DEFAULT '0',
|
|
`subcnt` int DEFAULT '0',
|
|
`mutation_version` bigint NOT NULL DEFAULT '0',
|
|
`public` json DEFAULT NULL,
|
|
`trusted` json DEFAULT NULL,
|
|
`tags` json DEFAULT NULL,
|
|
`aux` json DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `topics_owner` (`owner`),
|
|
KEY `topics_state_stateat` (`state`,`stateat`),
|
|
KEY `topics_name_state_seqid` (`name`,`state`,`seqid`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_topictags` (
|
|
`id` int NOT NULL AUTO_INCREMENT,
|
|
`topic` char(25) NOT NULL,
|
|
`tag` varchar(96) NOT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `topictags_tag` (`tag`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_blocks` (
|
|
`id` bigint NOT NULL,
|
|
`blocker_id` bigint NOT NULL,
|
|
`blocked_id` bigint 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 (`id`),
|
|
UNIQUE KEY `uk_im_user_blocks_pair` (`blocker_id`,`blocked_id`),
|
|
KEY `idx_im_user_blocks_blocked` (`blocked_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_ip_whitelists` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`ip_cidr` varchar(64) NOT NULL COMMENT 'IPv4, IPv6 or CIDR',
|
|
`status` tinyint NOT NULL DEFAULT '1' COMMENT '1 enabled, 2 disabled',
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`created_by` bigint NOT NULL DEFAULT '0',
|
|
`updated_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
|
`updated_by` bigint NOT NULL DEFAULT '0',
|
|
`deleted_at` datetime(3) DEFAULT NULL,
|
|
`deleted_by` bigint DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_im_user_ip_whitelist` (`user_id`,`ip_cidr`),
|
|
KEY `idx_im_user_ip_whitelist_user` (`user_id`,`status`),
|
|
KEY `idx_im_user_ip_whitelist_deleted` (`deleted_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Per-user login IP whitelist';
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_login_logs` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`user_id` bigint NOT NULL,
|
|
`username` varchar(64) NOT NULL DEFAULT '',
|
|
`account_type` varchar(24) NOT NULL DEFAULT '',
|
|
`account_hash` char(64) NOT NULL DEFAULT '',
|
|
`account_mask` varchar(128) NOT NULL DEFAULT '',
|
|
`login_type` varchar(24) NOT NULL,
|
|
`event_type` varchar(24) NOT NULL DEFAULT 'login',
|
|
`session_id` varchar(96) NOT NULL DEFAULT '',
|
|
`device_id` varchar(255) NOT NULL DEFAULT '',
|
|
`platform` varchar(32) NOT NULL DEFAULT 'unknown',
|
|
`app_version` varchar(32) NOT NULL DEFAULT '',
|
|
`ip` varchar(64) NOT NULL DEFAULT '',
|
|
`region` varchar(128) NOT NULL DEFAULT '',
|
|
`user_agent` varchar(512) NOT NULL DEFAULT '',
|
|
`risk_level` varchar(16) NOT NULL DEFAULT 'low',
|
|
`request_id` varchar(64) NOT NULL DEFAULT '',
|
|
`login_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
`logout_at` datetime(3) DEFAULT NULL,
|
|
`metadata` json DEFAULT NULL,
|
|
`created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_im_user_login_user_time` (`user_id`,`login_at` DESC,`id` DESC),
|
|
KEY `idx_im_user_login_ip_time` (`ip`,`login_at` DESC,`id` DESC),
|
|
KEY `idx_im_user_login_device_time` (`device_id`(64),`login_at` DESC),
|
|
KEY `idx_im_user_login_request` (`request_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_privacy_settings` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`add_me_methods` json DEFAULT NULL,
|
|
`profile_visibility` varchar(32) NOT NULL DEFAULT 'friends',
|
|
`last_seen_visibility` varchar(32) NOT NULL DEFAULT 'friends',
|
|
`read_receipts` tinyint NOT NULL DEFAULT '1',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_user_privacy_settings_user` (`user_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_profiles` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`avatar_file_id` varchar(64) NOT NULL DEFAULT '',
|
|
`nickname` varchar(64) NOT NULL DEFAULT '',
|
|
`birth_date` date DEFAULT NULL,
|
|
`signature` varchar(256) NOT NULL DEFAULT '',
|
|
`gender` varchar(16) NOT NULL DEFAULT '',
|
|
`region` varchar(128) NOT NULL DEFAULT '',
|
|
`email` varchar(128) NOT NULL DEFAULT '',
|
|
`public_account` varchar(64) NOT NULL DEFAULT '',
|
|
`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 (`id`),
|
|
UNIQUE KEY `uk_im_user_profiles_user` (`user_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_user_security` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`auth_version` int NOT NULL DEFAULT '1',
|
|
`password_updated_at` datetime(3) DEFAULT 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_im_user_security_user` (`user_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_users` (
|
|
`id` bigint NOT NULL,
|
|
`account_no` int unsigned NOT NULL DEFAULT '0' COMMENT '用户编å·',
|
|
`username` varchar(32) NOT NULL,
|
|
`createdat` datetime(3) NOT NULL,
|
|
`updatedat` datetime(3) NOT NULL,
|
|
`state` smallint NOT NULL DEFAULT '0',
|
|
`stateat` datetime(3) DEFAULT NULL,
|
|
`access` json DEFAULT NULL,
|
|
`lastseen` datetime DEFAULT NULL,
|
|
`useragent` varchar(255) DEFAULT '',
|
|
`phone` varchar(32) DEFAULT NULL,
|
|
`public` json DEFAULT NULL,
|
|
`trusted` json DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `users_username` (`username`),
|
|
UNIQUE KEY `uk_im_users_account_no` (`account_no`),
|
|
UNIQUE KEY `users_phone` (`phone`),
|
|
KEY `users_state_stateat` (`state`,`stateat`),
|
|
KEY `users_lastseen_updatedat` (`lastseen`,`updatedat`),
|
|
KEY `idx_im_users_account_no` (`account_no`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_verification_codes` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`challenge_id` varchar(64) NOT NULL,
|
|
`scene` varchar(32) NOT NULL,
|
|
`action` varchar(64) NOT NULL DEFAULT '',
|
|
`phone_hash` char(64) NOT NULL,
|
|
`phone_mask` varchar(32) NOT NULL,
|
|
`target_user` bigint DEFAULT NULL,
|
|
`code_hash` char(64) NOT NULL,
|
|
`verification_token_hash` char(64) DEFAULT NULL,
|
|
`state` smallint NOT NULL,
|
|
`attempts` int NOT NULL DEFAULT '0',
|
|
`max_attempts` int NOT NULL,
|
|
`expires_at` datetime(3) NOT NULL,
|
|
`resend_after` datetime(3) NOT NULL,
|
|
`verified_at` datetime(3) DEFAULT NULL,
|
|
`consumed_at` datetime(3) DEFAULT 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_im_verification_challenge` (`challenge_id`),
|
|
KEY `idx_im_verification_scene_phone_state` (`scene`,`phone_hash`,`state`,`expires_at`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_workbench_apps` (
|
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
|
`code` varchar(64) NOT NULL,
|
|
`name` varchar(128) NOT NULL,
|
|
`icon_file_id` varchar(64) NOT NULL DEFAULT '',
|
|
`route` varchar(128) NOT NULL,
|
|
`sort_order` int NOT NULL DEFAULT '0',
|
|
`unread_key` varchar(64) NOT NULL DEFAULT '',
|
|
`enabled` tinyint NOT NULL DEFAULT '1',
|
|
`permission` varchar(64) NOT NULL DEFAULT 'enabled',
|
|
`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_im_workbench_apps_code` (`code`),
|
|
KEY `idx_im_workbench_apps_enabled_order` (`enabled`,`sort_order`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS `im_youth_mode_settings` (
|
|
`id` bigint NOT NULL,
|
|
`user_id` bigint NOT NULL,
|
|
`purpose` varchar(64) NOT NULL,
|
|
`password_hash` varbinary(255) NOT NULL,
|
|
`enabled` tinyint NOT NULL DEFAULT '0',
|
|
`policy_version` int NOT NULL DEFAULT '1',
|
|
`restrictions` json DEFAULT NULL,
|
|
`enabled_at` datetime(3) DEFAULT NULL,
|
|
`failed_attempts` int NOT NULL DEFAULT '0',
|
|
`locked_until` datetime(3) DEFAULT 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_im_youth_mode_settings_user_purpose` (`user_id`,`purpose`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
-- ============================================================
|
|
-- 2. Tenant business seed data.
|
|
-- ============================================================
|
|
|
|
-- Tinode schema version expected by the current MySQL adapter.
|
|
INSERT INTO `im_kvmeta` (`id`, `key`, `createdat`, `value`)
|
|
VALUES (1, 'version', CURRENT_TIMESTAMP(3), 123)
|
|
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);
|
|
|
|
-- Workbench default apps. These are product navigation entries, not tenant business data.
|
|
INSERT INTO `im_workbench_apps` (`code`, `name`, `route`, `sort_order`, `unread_key`, `enabled`, `permission`)
|
|
VALUES
|
|
('attendance', '打卡', '/attendance', 10, 'attendance', 1, 'enabled'),
|
|
('monthly_reports', '月报', '/reports/monthly', 20, 'monthly_reports', 1, 'enabled'),
|
|
('daily_reports', '日报', '/reports/daily', 30, 'daily_reports', 1, 'enabled'),
|
|
('organization', '部门框架', '/organization', 40, 'organization', 1, 'enabled'),
|
|
('executive_mailbox', '举报信箱', '/executive-mailbox', 50, 'executive_mailbox', 1, 'enabled'),
|
|
('meetings', '会议通知', '/meetings', 60, 'meetings', 1, 'enabled'),
|
|
('meeting_notes', '会议笔记', '/meeting-notes', 70, '', 1, 'enabled')
|
|
ON DUPLICATE KEY UPDATE
|
|
`name` = VALUES(`name`),
|
|
`route` = VALUES(`route`),
|
|
`sort_order` = VALUES(`sort_order`),
|
|
`unread_key` = VALUES(`unread_key`),
|
|
`enabled` = VALUES(`enabled`),
|
|
`permission` = VALUES(`permission`),
|
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
-- Default attendance settings. Tenants can edit or replace them later.
|
|
INSERT INTO `im_attendance_rules` (`rule_id`, `name`, `workday`, `location_required`, `wifi_required`, `allow_outside_checkin`, `appeal_allowed`)
|
|
VALUES ('att_rule_default', '默认考勤规则', 1, 0, 0, 1, 1)
|
|
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
INSERT INTO `im_attendance_shifts` (`shift_id`, `rule_id`, `name`, `work_start`, `work_end`, `checkin_start`, `checkout_end`, `sort_order`)
|
|
VALUES ('shift_default', 'att_rule_default', '默认班次', '09:00:00', '18:00:00', '08:30:00', '20:00:00', 10)
|
|
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
-- Default mailbox configuration.
|
|
INSERT INTO `im_mailbox_config` (`id`, `enabled`, `allow_anonymous`, `required_fields`, `max_length`, `attachment_policy`, `notice_title`, `notice_content`)
|
|
VALUES (1, 1, 1, '["subject","content"]', 5000, '{"max_files":5,"purpose":"executive_mailbox"}', '总经理信箱', '请如实填写诉求,匿名提交将按企业政策保护展示身份。')
|
|
ON DUPLICATE KEY UPDATE
|
|
`enabled` = VALUES(`enabled`),
|
|
`allow_anonymous` = VALUES(`allow_anonymous`),
|
|
`required_fields` = VALUES(`required_fields`),
|
|
`max_length` = VALUES(`max_length`),
|
|
`attachment_policy` = VALUES(`attachment_policy`),
|
|
`notice_title` = VALUES(`notice_title`),
|
|
`notice_content` = VALUES(`notice_content`),
|
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
-- Default abuse report reasons.
|
|
INSERT INTO `im_abuse_reasons` (`target_type`, `reason_code`, `label`, `requires_description`, `allows_evidence`, `sort_order`)
|
|
VALUES
|
|
('user', 'fraud', '诈骗欺诈', 0, 1, 10),
|
|
('user', 'harassment', '骚扰辱骂', 0, 1, 20),
|
|
('user', 'illegal', '违法违规', 1, 1, 30),
|
|
('group', 'fraud', '诈骗欺诈', 0, 1, 10),
|
|
('group', 'spam', '垃圾广告', 0, 1, 20),
|
|
('group', 'illegal', '违法违规', 1, 1, 30),
|
|
('message', 'fraud', '诈骗欺诈', 0, 1, 10),
|
|
('message', 'spam', '垃圾广告', 0, 1, 20),
|
|
('message', 'harassment', '骚扰辱骂', 0, 1, 30),
|
|
('message', 'illegal', '违法违规', 1, 1, 40)
|
|
ON DUPLICATE KEY UPDATE
|
|
`label` = VALUES(`label`),
|
|
`requires_description` = VALUES(`requires_description`),
|
|
`allows_evidence` = VALUES(`allows_evidence`),
|
|
`sort_order` = VALUES(`sort_order`),
|
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
-- Default feedback configuration.
|
|
INSERT INTO `im_feedback_config` (`id`, `categories`, `max_length`, `attachment_policy`, `allow_contact`, `diagnostics_notice`)
|
|
VALUES (1, '["bug","suggestion","complaint","other"]', 1000, '{"max_files":5,"purpose":"feedback"}', 1, '仅在你同意时上传脱敏诊断信息。')
|
|
ON DUPLICATE KEY UPDATE
|
|
`categories` = VALUES(`categories`),
|
|
`max_length` = VALUES(`max_length`),
|
|
`attachment_policy` = VALUES(`attachment_policy`),
|
|
`allow_contact` = VALUES(`allow_contact`),
|
|
`diagnostics_notice` = VALUES(`diagnostics_notice`),
|
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
|
|
-- ============================================================
|
|
-- 3. Control database registry seed.
|
|
-- ============================================================
|
|
-- Keep this section in the same change set as tenant DB initialization.
|
|
-- If the tenant id is generated by Admin Server, replace __TENANT_ID__ with the generated id.
|
|
|
|
INSERT INTO `hotgo`.`im_tenant` (`id`, `code`, `name`, `tenant_desc`, `db_name`, `db_dsn`, `state`, `created_by`, `updated_by`)
|
|
VALUES (2,'system', 'system merchant', 'system default merchant', 'meeting_im', '', 1, 0, 0)
|
|
ON DUPLICATE KEY UPDATE
|
|
`code` = VALUES(`code`),
|
|
`name` = VALUES(`name`),
|
|
`db_name` = VALUES(`db_name`),
|
|
`state` = VALUES(`state`),
|
|
`updated_at` = CURRENT_TIMESTAMP(3);
|
|
|
|
INSERT INTO `hotgo`.`im_tenant_config` (`tenant_id`, `max_users`, `max_groups`, `max_group_members`, `created_by`, `updated_by`)
|
|
VALUES (2, 0, 0, 0, 0, 0)
|
|
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP(3);
|