-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schemas): add
agree_to_terms_policy
for sie table
- Loading branch information
Showing
5 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/schemas/alterations/next-1718594164-add-agree-to-terms-policy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { yes } from '@silverhand/essentials'; | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
const isCi = yes(process.env.CI); | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
// Create type | ||
await pool.query(sql` | ||
create type agree_to_terms_policy as enum ('AutoAgree', 'RegistrationOnly', 'RegistrationAndSignIn'); | ||
`); | ||
|
||
if (isCi) { | ||
// Direct set default to 'AutoAgree' to align with the sql table definition | ||
await pool.query(sql` | ||
alter table sign_in_experiences add column agree_to_terms_policy agree_to_terms_policy not null default 'AutoAgree'; | ||
`); | ||
} else { | ||
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters