-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update primary key for identities table (#1311)
## What kind of change does this PR introduce? * We need to be able to have a consistent identifier to fetch an identity from the database. The current approach for using a composite primary key isn't sufficient and not ideal for exposing through the API. * Remove the composite primary key on (`auth.identities.id`, `auth.identities.provider`) * Rename `auth.identities.id` to `auth.identities.provider_id` * Add a new primary key called `auth.identities.id` * Add a unique constraint on (`auth.identities.provider_id`, `auth.identities.provider`) --------- Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
- Loading branch information
1 parent
9b93ac1
commit d8ec801
Showing
4 changed files
with
44 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
do $$ | ||
begin | ||
if not exists(select * | ||
from information_schema.columns | ||
where table_schema = '{{ index .Options "Namespace" }}' and table_name='identities' and column_name='provider_id') | ||
then | ||
alter table if exists {{ index .Options "Namespace" }}.identities | ||
rename column id to provider_id; | ||
end if; | ||
end$$; | ||
|
||
alter table if exists {{ index .Options "Namespace" }}.identities | ||
drop constraint if exists identities_pkey, | ||
add column if not exists id uuid default gen_random_uuid() primary key; | ||
|
||
do $$ | ||
begin | ||
if not exists | ||
(select constraint_name | ||
from information_schema.table_constraints | ||
where table_schema = '{{ index .Options "Namespace" }}' | ||
and table_name = 'identities' | ||
and constraint_name = 'identities_provider_id_provider_unique') | ||
then | ||
alter table if exists {{ index .Options "Namespace" }}.identities | ||
add constraint identities_provider_id_provider_unique | ||
unique(provider_id, provider); | ||
end if; | ||
end $$; |