Skip to content

Commit 8f62ef3

Browse files
committed
fix: group schema migration fix
1 parent 2150c67 commit 8f62ef3

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

migrations/20251210100002_add_scim_groups.up.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,26 @@
33
create table if not exists {{ index .Options "Namespace" }}.scim_groups (
44
id uuid not null,
55
sso_provider_id uuid not null,
6-
external_id text not null,
6+
external_id text null,
77
display_name text not null,
88
created_at timestamptz null,
99
updated_at timestamptz null,
1010

1111
constraint scim_groups_pkey primary key (id),
1212
constraint scim_groups_sso_provider_fkey foreign key (sso_provider_id)
1313
references {{ index .Options "Namespace" }}.sso_providers (id) on delete cascade,
14-
constraint "external_id not empty" check (char_length(external_id) > 0),
14+
constraint "external_id not empty if set" check (external_id is null or char_length(external_id) > 0),
1515
constraint "display_name not empty" check (char_length(display_name) > 0)
1616
);
1717

18-
-- Unique index Scoped to SSO provider
18+
-- Unique index scoped to SSO provider (only for non-null external_id)
1919
create unique index if not exists scim_groups_sso_provider_external_id_idx
20-
on {{ index .Options "Namespace" }}.scim_groups (sso_provider_id, external_id);
20+
on {{ index .Options "Namespace" }}.scim_groups (sso_provider_id, external_id)
21+
where external_id is not null;
22+
23+
-- Unique index for displayName per SSO provider (case-insensitive, required by Azure AD)
24+
create unique index if not exists scim_groups_sso_provider_display_name_idx
25+
on {{ index .Options "Namespace" }}.scim_groups (sso_provider_id, lower(display_name));
2126

2227
-- Index for listing groups by SSO provider
2328
create index if not exists scim_groups_sso_provider_id_idx

0 commit comments

Comments
 (0)