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) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 13:42:51 +08:00
parent 1ba29b9a09
commit 56232c5c93
3 changed files with 4 additions and 2 deletions
@@ -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
@@ -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;
@@ -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