Skip to content

Commit aff2fe6

Browse files
authored
feat: make dropping users_email_key backward compatible (#995)
Dropping the `users_email_key` can sometimes be an issue as the `auth.users.email` column has been used as a foreign key reference in certain projects. This PR will continue with the migration, but will raise a notice that the developers of such projects should take care of this change manually. If it is not handled, SSO will not work and future compatibility with new versions may be an issue.
1 parent 551793e commit aff2fe6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

migrations/20221215195500_modify_users_email_unique_index.up.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ alter table only {{ index .Options "Namespace" }}.users
88

99
comment on column {{ index .Options "Namespace" }}.users.is_sso_user is 'Auth: Set this column to true when the account comes from SSO. These accounts can have duplicate emails.';
1010

11+
do $$
12+
begin
13+
alter table only {{ index .Options "Namespace" }}.users
14+
drop constraint if exists users_email_key;
15+
exception
16+
-- dependent object: https://www.postgresql.org/docs/current/errcodes-appendix.html
17+
when SQLSTATE '2BP01' then
18+
raise notice 'Unable to drop users_email_key constraint due to dependent objects, please resolve this manually or SSO may not work';
19+
end $$;
20+
1121
create unique index if not exists users_email_partial_key on {{ index .Options "Namespace" }}.users (email) where (is_sso_user = false);
1222

1323
comment on index {{ index .Options "Namespace" }}.users_email_partial_key is 'Auth: A partial unique index that applies only when is_sso_user is false';
14-
15-
alter table only {{ index .Options "Namespace" }}.users
16-
drop constraint if exists users_email_key;

0 commit comments

Comments
 (0)