From dc888e7cd0e1cfac767978ab5ae55ab8330a7adb Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Mon, 17 Aug 2026 22:48:50 +0900 Subject: [PATCH] fix(0042_iam_tables.sql): Fix PostgreSQL partial unique constraint syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: Table constraint with WHERE clause is invalid PostgreSQL syntax Error: 42601: syntax error at or near "WHERE" at position 1525 Solution: Move partial uniqueness to separate CREATE UNIQUE INDEX statement - Removed invalid WHERE clause from table UNIQUE() constraint - Created proper partial unique index with WHERE condition - PostgreSQL syntax now correct Syntax fix: ❌ UNIQUE(col1, col2) WHERE condition (invalid in table def) ✅ CREATE UNIQUE INDEX idx ON table(col1, col2) WHERE condition Co-Authored-By: Claude Haiku 4.5 --- db/migrations/0042_iam_tables.sql | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/db/migrations/0042_iam_tables.sql b/db/migrations/0042_iam_tables.sql index 6c08a290..4dd8c4c9 100644 --- a/db/migrations/0042_iam_tables.sql +++ b/db/migrations/0042_iam_tables.sql @@ -108,10 +108,7 @@ CREATE TABLE IF NOT EXISTS public.role_assignment ( -- Idempotency & correlation correlation_id UUID UNIQUE NOT NULL DEFAULT gen_random_uuid(), - checksum VARCHAR(64), - - -- Constraints: One role per identity (except temporary/special cases) - UNIQUE(identity_id, role_id) WHERE assignment_state NOT IN ('REVOKED', 'REJECTED') + checksum VARCHAR(64) ); CREATE INDEX idx_role_assignment_identity ON public.role_assignment(identity_id); @@ -119,6 +116,11 @@ CREATE INDEX idx_role_assignment_role ON public.role_assignment(role_id); CREATE INDEX idx_role_assignment_state ON public.role_assignment(assignment_state); CREATE INDEX idx_role_assignment_correlation ON public.role_assignment(correlation_id); +-- Partial unique constraint: One active role per identity +CREATE UNIQUE INDEX idx_role_assignment_unique_active + ON public.role_assignment(identity_id, role_id) + WHERE assignment_state NOT IN ('REVOKED', 'REJECTED'); + -- 4. PERMISSION TABLE (Granular Permissions) CREATE TABLE IF NOT EXISTS public.permission ( permission_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),