refactor: retire legacy tinode database routing
This commit is contained in:
@@ -56,6 +56,67 @@ ALTER TABLE im_auth
|
||||
DROP INDEX auth_userid,
|
||||
ADD UNIQUE INDEX auth_tenant_userid (tenant_id, userid);
|
||||
|
||||
-- Topic/subscription runtime indexes for shared-database deployments.
|
||||
-- These tables are on hot paths for topic lookup, message seq updates,
|
||||
-- unread calculation and subscription permission checks. Keep tenant_id as
|
||||
-- the leading column so one tenant does not scan another tenant's rows.
|
||||
SET @schema_name := DATABASE();
|
||||
|
||||
SET @sql := IF((
|
||||
SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'im_topics'
|
||||
AND index_name = 'uk_topics_tenant_name'
|
||||
) = 0,
|
||||
'ALTER TABLE im_topics ADD UNIQUE INDEX uk_topics_tenant_name(tenant_id, name)',
|
||||
'SELECT ''skip uk_topics_tenant_name'' AS status'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql := IF((
|
||||
SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'im_topics'
|
||||
AND index_name = 'idx_topics_tenant_name_state_seqid'
|
||||
) = 0,
|
||||
'ALTER TABLE im_topics ADD INDEX idx_topics_tenant_name_state_seqid(tenant_id, name, state, seqid)',
|
||||
'SELECT ''skip idx_topics_tenant_name_state_seqid'' AS status'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql := IF((
|
||||
SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'im_topics'
|
||||
AND index_name = 'idx_topics_tenant_owner'
|
||||
) = 0,
|
||||
'ALTER TABLE im_topics ADD INDEX idx_topics_tenant_owner(tenant_id, owner)',
|
||||
'SELECT ''skip idx_topics_tenant_owner'' AS status'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql := IF((
|
||||
SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'im_subscriptions'
|
||||
AND index_name = 'idx_subscriptions_tenant_topic_deletedat'
|
||||
) = 0,
|
||||
'ALTER TABLE im_subscriptions ADD INDEX idx_subscriptions_tenant_topic_deletedat(tenant_id, topic, deletedat)',
|
||||
'SELECT ''skip idx_subscriptions_tenant_topic_deletedat'' AS status'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql := IF((
|
||||
SELECT COUNT(*) FROM information_schema.statistics
|
||||
WHERE table_schema = @schema_name
|
||||
AND table_name = 'im_subscriptions'
|
||||
AND index_name = 'idx_subscriptions_tenant_user_topic_deletedat'
|
||||
) = 0,
|
||||
'ALTER TABLE im_subscriptions ADD INDEX idx_subscriptions_tenant_user_topic_deletedat(tenant_id, userid, topic, deletedat)',
|
||||
'SELECT ''skip idx_subscriptions_tenant_user_topic_deletedat'' AS status'
|
||||
);
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- Default app release rows used by /v1/im/app/releases/latest.
|
||||
INSERT INTO hotgo.im_app_releases (
|
||||
platform, channel, latest_version, min_supported_version, update_type,
|
||||
|
||||
Reference in New Issue
Block a user