refactor: retire legacy tinode database routing

This commit is contained in:
richjohnrambo
2026-09-23 17:04:30 +08:00
parent 204043382c
commit aa9f562e1e
19 changed files with 294 additions and 744 deletions
+37 -35
View File
@@ -1,15 +1,15 @@
-- IM tenant business database initialization script.
-- Source baseline: local MySQL database `tinode` on 2026-09-13.
-- Source baseline: shared MySQL database `meeting_im` 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_DB__ -> target tenant business database, normally `meeting_im`.
-- __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`.
-- 3. Keep business tables empty; do not copy users, topics, messages, files, Kafka logs, or audit data from another database.
--
-- Notes:
-- - This script intentionally seeds only stable metadata/default configuration.
@@ -168,9 +168,10 @@ CREATE TABLE IF NOT EXISTS `im_attendance_records` (
CREATE TABLE IF NOT EXISTS `im_attendance_rules` (
`id` bigint NOT NULL AUTO_INCREMENT,
`tenant_id` bigint NOT NULL DEFAULT '2' COMMENT '商户ID',
`rule_id` varchar(64) NOT NULL,
`name` varchar(128) NOT NULL,
`workday` tinyint NOT NULL DEFAULT '1',
`workday` varchar(32) NOT NULL DEFAULT '1,2,3,4,5',
`location_required` tinyint NOT NULL DEFAULT '0',
`wifi_required` tinyint NOT NULL DEFAULT '0',
`allow_outside_checkin` tinyint NOT NULL DEFAULT '1',
@@ -181,12 +182,13 @@ CREATE TABLE IF NOT EXISTS `im_attendance_rules` (
`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`)
UNIQUE KEY `uk_im_attendance_rules_tenant_rule` (`tenant_id`,`rule_id`),
KEY `idx_im_attendance_rules_state` (`tenant_id`,`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,
`tenant_id` bigint NOT NULL DEFAULT '2' COMMENT '商户ID',
`shift_id` varchar(64) NOT NULL,
`rule_id` varchar(64) NOT NULL,
`name` varchar(128) NOT NULL,
@@ -199,8 +201,8 @@ CREATE TABLE IF NOT EXISTS `im_attendance_shifts` (
`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`)
UNIQUE KEY `uk_im_attendance_shifts_tenant_shift` (`tenant_id`,`shift_id`),
KEY `idx_im_attendance_shifts_rule` (`tenant_id`,`rule_id`,`state`,`sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `im_audit_logs` (
@@ -397,6 +399,7 @@ CREATE TABLE IF NOT EXISTS `im_favorites` (
CREATE TABLE IF NOT EXISTS `im_feedback_config` (
`id` bigint NOT NULL AUTO_INCREMENT,
`tenant_id` bigint NOT NULL DEFAULT '2' COMMENT '商户ID',
`categories` json DEFAULT NULL,
`max_length` int NOT NULL DEFAULT '1000',
`attachment_policy` json DEFAULT NULL,
@@ -404,7 +407,8 @@ CREATE TABLE IF NOT EXISTS `im_feedback_config` (
`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`)
PRIMARY KEY (`id`),
UNIQUE KEY `uk_im_feedback_config_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `im_feedback_submissions` (
@@ -951,6 +955,7 @@ CREATE TABLE IF NOT EXISTS `im_login_failure_logs` (
CREATE TABLE IF NOT EXISTS `im_mailbox_config` (
`id` bigint NOT NULL AUTO_INCREMENT,
`tenant_id` bigint NOT NULL DEFAULT '2' COMMENT '商户ID',
`enabled` tinyint NOT NULL DEFAULT '1',
`allow_anonymous` tinyint NOT NULL DEFAULT '1',
`required_fields` json DEFAULT NULL,
@@ -961,7 +966,8 @@ CREATE TABLE IF NOT EXISTS `im_mailbox_config` (
`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`)
PRIMARY KEY (`id`),
UNIQUE KEY `uk_im_mailbox_config_tenant` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `im_mailbox_submissions` (
@@ -1491,6 +1497,7 @@ CREATE TABLE IF NOT EXISTS `im_verification_codes` (
CREATE TABLE IF NOT EXISTS `im_workbench_apps` (
`id` bigint NOT NULL AUTO_INCREMENT,
`tenant_id` bigint NOT NULL DEFAULT '2' COMMENT '商户ID',
`code` varchar(64) NOT NULL,
`name` varchar(128) NOT NULL,
`icon_file_id` varchar(64) NOT NULL DEFAULT '',
@@ -1502,8 +1509,8 @@ CREATE TABLE IF NOT EXISTS `im_workbench_apps` (
`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`)
UNIQUE KEY `uk_im_workbench_apps_tenant_code` (`tenant_id`,`code`),
KEY `idx_im_workbench_apps_enabled_order` (`tenant_id`,`enabled`,`sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE IF NOT EXISTS `im_youth_mode_settings` (
@@ -1533,15 +1540,15 @@ 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`)
INSERT INTO `im_workbench_apps` (`tenant_id`, `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')
(2, 'attendance', '打卡', '/attendance', 10, 'attendance', 1, 'enabled'),
(2, 'monthly_reports', '月报', '/reports/monthly', 20, 'monthly_reports', 1, 'enabled'),
(2, 'daily_reports', '日报', '/reports/daily', 30, 'daily_reports', 1, 'enabled'),
(2, 'organization', '部门框架', '/organization', 40, 'organization', 1, 'enabled'),
(2, 'executive_mailbox', '举报信箱', '/executive-mailbox', 50, 'executive_mailbox', 1, 'enabled'),
(2, 'meetings', '会议通知', '/meetings', 60, 'meetings', 1, 'enabled'),
(2, 'meeting_notes', '会议笔记', '/meeting-notes', 70, '', 1, 'enabled')
ON DUPLICATE KEY UPDATE
`name` = VALUES(`name`),
`route` = VALUES(`route`),
@@ -1552,17 +1559,17 @@ VALUES
`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)
INSERT INTO `im_attendance_rules` (`tenant_id`, `rule_id`, `name`, `workday`, `location_required`, `wifi_required`, `allow_outside_checkin`, `appeal_allowed`)
VALUES (2, 'att_rule_default', '默认考勤规则', '1,2,3,4,5', 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)
INSERT INTO `im_attendance_shifts` (`tenant_id`, `shift_id`, `rule_id`, `name`, `work_start`, `work_end`, `checkin_start`, `checkout_end`, `sort_order`)
VALUES (2, 'shift_default', 'att_rule_default', '默认班次', '09:00:00', '18:00:00', '08:00:00', '19: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"}', '总经理信箱', '请如实填写诉求,匿名提交将按企业政策保护展示身份。')
INSERT INTO `im_mailbox_config` (`tenant_id`, `enabled`, `allow_anonymous`, `required_fields`, `max_length`, `attachment_policy`, `notice_title`, `notice_content`)
VALUES (2, 1, 1, '["subject","content"]', 5000, '{"max_files":5,"purpose":"executive_mailbox"}', '总经理信箱', '请如实填写诉求。')
ON DUPLICATE KEY UPDATE
`enabled` = VALUES(`enabled`),
`allow_anonymous` = VALUES(`allow_anonymous`),
@@ -1594,8 +1601,8 @@ VALUES
`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, '仅在你同意时上传脱敏诊断信息。')
INSERT INTO `im_feedback_config` (`tenant_id`, `categories`, `max_length`, `attachment_policy`, `allow_contact`, `diagnostics_notice`)
VALUES (2, '["bug","suggestion","complaint","other"]', 2000, '{"max_files":5,"purpose":"feedback"}', 1, '')
ON DUPLICATE KEY UPDATE
`categories` = VALUES(`categories`),
`max_length` = VALUES(`max_length`),
@@ -1612,15 +1619,10 @@ SET FOREIGN_KEY_CHECKS = 1;
-- 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)
INSERT INTO `hotgo`.`im_tenant` (`id`, `code`, `name`, `tenant_desc`, `state`, `created_by`, `updated_by`)
VALUES (2,'system', 'system merchant', 'system default merchant', 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);