diff --git a/packages/schemas/alterations/next-1718594164-add-agree-to-terms-policy.ts b/packages/schemas/alterations/next-1718594164-add-agree-to-terms-policy.ts new file mode 100644 index 000000000000..cff02ab36b56 --- /dev/null +++ b/packages/schemas/alterations/next-1718594164-add-agree-to-terms-policy.ts @@ -0,0 +1,30 @@ +import { sql } from '@silverhand/slonik'; + +import type { AlterationScript } from '../lib/types/alteration.js'; + +const alteration: AlterationScript = { + up: async (pool) => { + // Create type + await pool.query(sql` + create type agree_to_terms_policy as enum ('AutoAgree', 'RegistrationOnly', 'RegistrationAndSignIn'); + `); + + // For compatibility with existing data, default to 'RegistrationOnly' + await pool.query(sql` + alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'RegistrationOnly'; + `); + + // For new data, default to 'AutoAgree' + await pool.query(sql` + alter table sign_in_experiences alter column agree_to_terms_policy set default 'AutoAgree'; + `); + }, + down: async (pool) => { + await pool.query(sql` + alter table sign_in_experiences drop column agree_to_terms_policy; + drop type agree_to_terms_policy; + `); + }, +}; + +export default alteration; diff --git a/packages/schemas/tables/sign_in_experiences.sql b/packages/schemas/tables/sign_in_experiences.sql index 21594b0c6ebc..3df42f2d2737 100644 --- a/packages/schemas/tables/sign_in_experiences.sql +++ b/packages/schemas/tables/sign_in_experiences.sql @@ -1,4 +1,5 @@ create type sign_in_mode as enum ('SignIn', 'Register', 'SignInAndRegister'); +create type agree_to_terms_policy as enum ('AutoAgree', 'RegistrationOnly', 'RegistrationAndSignIn'); create table sign_in_experiences ( tenant_id varchar(21) not null @@ -9,6 +10,7 @@ create table sign_in_experiences ( language_info jsonb /* @use LanguageInfo */ not null, terms_of_use_url varchar(2048), privacy_policy_url varchar(2048), + agree_to_terms_policy agree_to_terms_policy not null default 'AutoAgree', sign_in jsonb /* @use SignIn */ not null, sign_up jsonb /* @use SignUp */ not null, social_sign_in jsonb /* @use SocialSignIn */ not null default '{}'::jsonb,