From 56b2e713d30e7630f92aedeb23e5021fafa3afd4 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 31 May 2025 11:52:49 +0700 Subject: [PATCH] enh: prefix schema to enum migrations Add support for nonstandard search path migrations --- migrations/20221003041349_add_mfa_schema.up.sql | 10 +++++----- ...1003041400_add_aal_and_factor_id_to_sessions.up.sql | 2 +- migrations/20230322519590_add_flow_state_table.up.sql | 4 ++-- .../20240427152123_add_one_time_tokens_table.up.sql | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/migrations/20221003041349_add_mfa_schema.up.sql b/migrations/20221003041349_add_mfa_schema.up.sql index a44654aed..ed178e62f 100644 --- a/migrations/20221003041349_add_mfa_schema.up.sql +++ b/migrations/20221003041349_add_mfa_schema.up.sql @@ -1,8 +1,8 @@ -- 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'); + 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 $$; @@ -12,8 +12,8 @@ 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, diff --git a/migrations/20221003041400_add_aal_and_factor_id_to_sessions.up.sql b/migrations/20221003041400_add_aal_and_factor_id_to_sessions.up.sql index cc8a2096d..426a42f59 100644 --- a/migrations/20221003041400_add_aal_and_factor_id_to_sessions.up.sql +++ b/migrations/20221003041400_add_aal_and_factor_id_to_sessions.up.sql @@ -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; diff --git a/migrations/20230322519590_add_flow_state_table.up.sql b/migrations/20230322519590_add_flow_state_table.up.sql index a8842e5b0..c54455f90 100644 --- a/migrations/20230322519590_add_flow_state_table.up.sql +++ b/migrations/20230322519590_add_flow_state_table.up.sql @@ -1,6 +1,6 @@ -- 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 $$; @@ -8,7 +8,7 @@ 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, diff --git a/migrations/20240427152123_add_one_time_tokens_table.up.sql b/migrations/20240427152123_add_one_time_tokens_table.up.sql index be7312656..38100c08c 100644 --- a/migrations/20240427152123_add_one_time_tokens_table.up.sql +++ b/migrations/20240427152123_add_one_time_tokens_table.up.sql @@ -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', @@ -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(),