From 56232c5c932bdd7b34e2bb05d0caeb9966e2125b Mon Sep 17 00:00:00 2001 From: liangxu Date: Wed, 6 May 2026 13:42:51 +0800 Subject: [PATCH] fix(migrations): include client_id in platform account unique index Why: prior migration created the workspace identity unique index without client_id, so accounts on the same workspace+platform+uid couldn't coexist across desktop clients. Also drop the legacy uk_platform_accounts_identity_active index so re-runs are idempotent. Co-Authored-By: Claude Opus 4.7 (1M context) --- ...260421100010_add_desktop_fields_to_platform_accounts.up.sql | 2 +- ...06120000_scope_platform_accounts_to_desktop_client.down.sql | 3 ++- ...0506120000_scope_platform_accounts_to_desktop_client.up.sql | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/migrations/20260421100010_add_desktop_fields_to_platform_accounts.up.sql b/server/migrations/20260421100010_add_desktop_fields_to_platform_accounts.up.sql index 40eec4f..1ddc512 100644 --- a/server/migrations/20260421100010_add_desktop_fields_to_platform_accounts.up.sql +++ b/server/migrations/20260421100010_add_desktop_fields_to_platform_accounts.up.sql @@ -53,7 +53,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS uniq_platform_accounts_desktop_id ON platform_accounts (desktop_id); CREATE UNIQUE INDEX IF NOT EXISTS uniq_platform_accounts_workspace_identity_active - ON platform_accounts (workspace_id, platform_id, platform_uid) + ON platform_accounts (workspace_id, client_id, platform_id, platform_uid) WHERE deleted_at IS NULL; CREATE INDEX IF NOT EXISTS idx_platform_accounts_client_id diff --git a/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.down.sql b/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.down.sql index 258a6b4..b26f60a 100644 --- a/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.down.sql +++ b/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.down.sql @@ -1,5 +1,6 @@ +DROP INDEX IF EXISTS uk_platform_accounts_identity_active; DROP INDEX IF EXISTS uniq_platform_accounts_workspace_identity_active; CREATE UNIQUE INDEX IF NOT EXISTS uniq_platform_accounts_workspace_identity_active - ON platform_accounts (workspace_id, platform_id, platform_uid) + ON platform_accounts (workspace_id, client_id, platform_id, platform_uid) WHERE deleted_at IS NULL; diff --git a/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.up.sql b/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.up.sql index f324915..b26f60a 100644 --- a/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.up.sql +++ b/server/migrations/20260506120000_scope_platform_accounts_to_desktop_client.up.sql @@ -1,3 +1,4 @@ +DROP INDEX IF EXISTS uk_platform_accounts_identity_active; DROP INDEX IF EXISTS uniq_platform_accounts_workspace_identity_active; CREATE UNIQUE INDEX IF NOT EXISTS uniq_platform_accounts_workspace_identity_active