-
-
Notifications
You must be signed in to change notification settings - Fork 454
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 account center table (#6761)
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/schemas/alterations/next-1730689363-add-account-center.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,31 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js'; | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
await pool.query(sql` | ||
create table account_centers ( | ||
tenant_id varchar(21) not null | ||
references tenants (id) on update cascade on delete cascade, | ||
id varchar(21) not null, | ||
/** The whole feature can be disabled */ | ||
enabled boolean not null default false, | ||
/** Control each fields */ | ||
fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb, | ||
primary key (tenant_id, id) | ||
); | ||
`); | ||
await applyTableRls(pool, 'account_centers'); | ||
}, | ||
down: async (pool) => { | ||
await dropTableRls(pool, 'account_centers'); | ||
await pool.query(sql` | ||
drop table account_centers; | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |
28 changes: 28 additions & 0 deletions
28
packages/schemas/src/foundations/jsonb-types/account-centers.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,28 @@ | ||
import { z } from 'zod'; | ||
|
||
export enum AccountCenterControlValue { | ||
Off = 'Off', | ||
ReadOnly = 'ReadOnly', | ||
Edit = 'Edit', | ||
} | ||
|
||
/** | ||
* Control list of each field in the account center (profile API) | ||
* all fields are optional, if not set, the default value is `Off` | ||
* this can make the alteration of the field control easier | ||
*/ | ||
export const accountCenterFieldControlGuard = z | ||
.object({ | ||
name: z.nativeEnum(AccountCenterControlValue), | ||
avatar: z.nativeEnum(AccountCenterControlValue), | ||
profile: z.nativeEnum(AccountCenterControlValue), | ||
email: z.nativeEnum(AccountCenterControlValue), | ||
phone: z.nativeEnum(AccountCenterControlValue), | ||
password: z.nativeEnum(AccountCenterControlValue), | ||
username: z.nativeEnum(AccountCenterControlValue), | ||
social: z.nativeEnum(AccountCenterControlValue), | ||
customData: z.nativeEnum(AccountCenterControlValue), | ||
}) | ||
.partial(); | ||
|
||
export type AccountCenterFieldControl = z.infer<typeof accountCenterFieldControlGuard>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create table account_centers ( | ||
tenant_id varchar(21) not null | ||
references tenants (id) on update cascade on delete cascade, | ||
id varchar(21) not null, | ||
/** The whole feature can be disabled */ | ||
enabled boolean not null default false, | ||
/** Control each fields */ | ||
fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb, | ||
primary key (tenant_id, id) | ||
); |