|
1 | 1 | -- Create unified custom OAuth/OIDC providers table |
2 | 2 | -- This table stores both OAuth2 and OIDC providers with type discrimination |
3 | 3 |
|
| 4 | +/* auth_migration: 20260128120000 */ |
4 | 5 | create table if not exists {{ index .Options "Namespace" }}.custom_oauth_providers ( |
5 | 6 | id uuid not null default gen_random_uuid(), |
6 | 7 |
|
@@ -96,50 +97,20 @@ create table if not exists {{ index .Options "Namespace" }}.custom_oauth_provide |
96 | 97 | constraint custom_oauth_providers_client_secret_length check ( |
97 | 98 | char_length(client_secret) >= 1 and char_length(client_secret) <= 1024 |
98 | 99 | ), |
99 | | - |
100 | | - -- Reserved provider names check |
101 | | - constraint custom_oauth_providers_identifier_not_reserved check ( |
102 | | - identifier not in ( |
103 | | - 'google', 'github', 'apple', 'facebook', 'azure', 'twitter', 'gitlab', |
104 | | - 'bitbucket', 'discord', 'twitch', 'slack', 'spotify', 'linkedin', |
105 | | - 'notion', 'kakao', 'zoom', 'figma', 'fly', 'snapchat', 'keycloak', |
106 | | - 'workos', 'linkedin-oidc', 'slack-oidc', 'vercel-marketplace', 'x' |
107 | | - ) |
108 | | - ) |
109 | 100 | ); |
110 | 101 |
|
111 | | --- Create indexes for efficient queries |
| 102 | +/* auth_migration: 20260128120000 */ |
112 | 103 | create index if not exists custom_oauth_providers_identifier_idx |
113 | 104 | on {{ index .Options "Namespace" }}.custom_oauth_providers (identifier); |
114 | 105 |
|
| 106 | +/* auth_migration: 20260128120000 */ |
115 | 107 | create index if not exists custom_oauth_providers_provider_type_idx |
116 | 108 | on {{ index .Options "Namespace" }}.custom_oauth_providers (provider_type); |
117 | 109 |
|
118 | | --- Create unique partial index for OIDC issuer (acts as unique constraint with WHERE clause) |
119 | | -create unique index if not exists custom_oauth_providers_oidc_issuer_key |
120 | | - on {{ index .Options "Namespace" }}.custom_oauth_providers (issuer) |
121 | | - where provider_type = 'oidc' and issuer is not null; |
122 | | - |
| 110 | +/* auth_migration: 20260128120000 */ |
123 | 111 | create index if not exists custom_oauth_providers_enabled_idx |
124 | 112 | on {{ index .Options "Namespace" }}.custom_oauth_providers (enabled); |
125 | 113 |
|
| 114 | +/* auth_migration: 20260128120000 */ |
126 | 115 | create index if not exists custom_oauth_providers_created_at_idx |
127 | 116 | on {{ index .Options "Namespace" }}.custom_oauth_providers (created_at); |
128 | | - |
129 | | -create index if not exists custom_oauth_providers_discovery_cached_at_idx |
130 | | - on {{ index .Options "Namespace" }}.custom_oauth_providers (discovery_cached_at) |
131 | | - where provider_type = 'oidc'; |
132 | | - |
133 | | --- Add trigger to update updated_at timestamp |
134 | | -create or replace function {{ index .Options "Namespace" }}.update_custom_oauth_providers_updated_at() |
135 | | -returns trigger as $$ |
136 | | -begin |
137 | | - new.updated_at = now(); |
138 | | - return new; |
139 | | -end; |
140 | | -$$ language plpgsql; |
141 | | - |
142 | | -create trigger update_custom_oauth_providers_updated_at |
143 | | - before update on {{ index .Options "Namespace" }}.custom_oauth_providers |
144 | | - for each row |
145 | | - execute function {{ index .Options "Namespace" }}.update_custom_oauth_providers_updated_at(); |
0 commit comments