From 12c10e5ece4136aaf779f525787d1510b77ab0c2 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Wed, 12 Jun 2024 15:49:49 +0800 Subject: [PATCH] feat(schemas): add `agree_to_terms_policy` for sie table --- packages/experience/src/__mocks__/logto.tsx | 3 ++ ...xt-1718594164-add-agree-to-terms-policy.ts | 30 +++++++++++++++++++ .../schemas/tables/sign_in_experiences.sql | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 packages/schemas/alterations/next-1718594164-add-agree-to-terms-policy.ts diff --git a/packages/experience/src/__mocks__/logto.tsx b/packages/experience/src/__mocks__/logto.tsx index ec3b66d09d85..f079d680b318 100644 --- a/packages/experience/src/__mocks__/logto.tsx +++ b/packages/experience/src/__mocks__/logto.tsx @@ -1,5 +1,6 @@ import type { SignInExperience, SignIn, SsoConnectorMetadata } from '@logto/schemas'; import { + AgreeToTermsPolicy, ConnectorPlatform, ConnectorType, MfaPolicy, @@ -104,6 +105,7 @@ export const mockSignInExperience: SignInExperience = { signInMode: SignInMode.SignInAndRegister, customCss: null, customContent: {}, + agreeToTermsPolicy: AgreeToTermsPolicy.AutoAgree, passwordPolicy: {}, mfa: { policy: MfaPolicy.UserControlled, @@ -136,6 +138,7 @@ export const mockSignInExperienceSettings: SignInExperienceResponse = { }, customCss: null, customContent: {}, + agreeToTermsPolicy: AgreeToTermsPolicy.AutoAgree, passwordPolicy: {}, mfa: { policy: MfaPolicy.UserControlled, 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,