Skip to content

Commit

Permalink
fix(migrations): update types that are not set on the schema
Browse files Browse the repository at this point in the history
This changeset updates the migrations schema that's causing trouble on new
supabase/auth installations whether its using docker or not. The types are not
set on the schema which causes the migrations to fail. And it adds residual
types on public schema.

Signed-off-by: Edward Fitz Abucay <[email protected]>
  • Loading branch information
ffimnsr committed Nov 27, 2024
1 parent e358da5 commit 8e3d422
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
19 changes: 11 additions & 8 deletions migrations/20221003041349_add_mfa_schema.up.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
-- see: https://stackoverflow.com/questions/7624919/check-if-a-user-defined-type-already-exists-in-postgresql/48382296#48382296
do $$ begin
create type factor_type as enum('totp', 'webauthn');
create type factor_status as enum('unverified', 'verified');
create type aal_level as enum('aal1', 'aal2', 'aal3');
do $$
begin
create type {{ index .Options "Namespace" }}.factor_type as enum('totp', 'webauthn');
create type {{ index .Options "Namespace" }}.factor_status as enum('unverified', 'verified');
create type {{ index .Options "Namespace" }}.aal_level as enum('aal1', 'aal2', 'aal3');
exception
when duplicate_object then null;
end $$;
when duplicate_object then raise notice '%, skipping', sqlerrm using errcode = sqlstate;
when others then null;
end
$$;

-- auth.mfa_factors definition
create table if not exists {{ index .Options "Namespace" }}.mfa_factors(
id uuid not null,
user_id uuid not null,
friendly_name text null,
factor_type factor_type not null,
status factor_status not null,
factor_type {{ index .Options "Namespace" }}.factor_type not null,
status {{ index .Options "Namespace" }}.factor_status not null,
created_at timestamptz not null,
updated_at timestamptz not null,
secret text null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-- add factor_id to sessions
alter table {{ index .Options "Namespace" }}.sessions add column if not exists factor_id uuid null;
alter table {{ index .Options "Namespace" }}.sessions add column if not exists aal aal_level null;
alter table {{ index .Options "Namespace" }}.sessions add column if not exists aal {{ index .Options "Namespace" }}.aal_level null;
4 changes: 2 additions & 2 deletions migrations/20230322519590_add_flow_state_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-- see: https://stackoverflow.com/questions/7624919/check-if-a-user-defined-type-already-exists-in-postgresql/48382296#48382296
do $$ begin
create type code_challenge_method as enum('s256', 'plain');
create type {{ index .Options "Namespace" }}.code_challenge_method as enum('s256', 'plain');
exception
when duplicate_object then null;
end $$;
create table if not exists {{ index .Options "Namespace" }}.flow_state(
id uuid primary key,
user_id uuid null,
auth_code text not null,
code_challenge_method code_challenge_method not null,
code_challenge_method {{ index .Options "Namespace" }}.code_challenge_method not null,
code_challenge text not null,
provider_type text not null,
provider_access_token text null,
Expand Down
4 changes: 2 additions & 2 deletions migrations/20240427152123_add_one_time_tokens_table.up.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
do $$ begin
create type one_time_token_type as enum (
create type {{ index .Options "Namespace" }}.one_time_token_type as enum (
'confirmation_token',
'reauthentication_token',
'recovery_token',
Expand All @@ -16,7 +16,7 @@ do $$ begin
create table if not exists {{ index .Options "Namespace" }}.one_time_tokens (
id uuid primary key,
user_id uuid not null references {{ index .Options "Namespace" }}.users on delete cascade,
token_type one_time_token_type not null,
token_type {{ index .Options "Namespace" }}.one_time_token_type not null,
token_hash text not null,
relates_to text not null,
created_at timestamp without time zone not null default now(),
Expand Down

0 comments on commit 8e3d422

Please sign in to comment.