Skip to content

Commit 00e1752

Browse files
authored
feat(schemas): add account center table (#6761)
1 parent fe06860 commit 00e1752

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { sql } from '@silverhand/slonik';
2+
3+
import type { AlterationScript } from '../lib/types/alteration.js';
4+
5+
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js';
6+
7+
const alteration: AlterationScript = {
8+
up: async (pool) => {
9+
await pool.query(sql`
10+
create table account_centers (
11+
tenant_id varchar(21) not null
12+
references tenants (id) on update cascade on delete cascade,
13+
id varchar(21) not null,
14+
/** The whole feature can be disabled */
15+
enabled boolean not null default false,
16+
/** Control each fields */
17+
fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
18+
primary key (tenant_id, id)
19+
);
20+
`);
21+
await applyTableRls(pool, 'account_centers');
22+
},
23+
down: async (pool) => {
24+
await dropTableRls(pool, 'account_centers');
25+
await pool.query(sql`
26+
drop table account_centers;
27+
`);
28+
},
29+
};
30+
31+
export default alteration;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { z } from 'zod';
2+
3+
export enum AccountCenterControlValue {
4+
Off = 'Off',
5+
ReadOnly = 'ReadOnly',
6+
Edit = 'Edit',
7+
}
8+
9+
/**
10+
* Control list of each field in the account center (profile API)
11+
* all fields are optional, if not set, the default value is `Off`
12+
* this can make the alteration of the field control easier
13+
*/
14+
export const accountCenterFieldControlGuard = z
15+
.object({
16+
name: z.nativeEnum(AccountCenterControlValue),
17+
avatar: z.nativeEnum(AccountCenterControlValue),
18+
profile: z.nativeEnum(AccountCenterControlValue),
19+
email: z.nativeEnum(AccountCenterControlValue),
20+
phone: z.nativeEnum(AccountCenterControlValue),
21+
password: z.nativeEnum(AccountCenterControlValue),
22+
username: z.nativeEnum(AccountCenterControlValue),
23+
social: z.nativeEnum(AccountCenterControlValue),
24+
customData: z.nativeEnum(AccountCenterControlValue),
25+
})
26+
.partial();
27+
28+
export type AccountCenterFieldControl = z.infer<typeof accountCenterFieldControlGuard>;

packages/schemas/src/foundations/jsonb-types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './users.js';
99
export * from './sso-connector.js';
1010
export * from './applications.js';
1111
export * from './verification-records.js';
12+
export * from './account-centers.js';
1213

1314
export {
1415
configurableConnectorMetadataGuard,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
create table account_centers (
2+
tenant_id varchar(21) not null
3+
references tenants (id) on update cascade on delete cascade,
4+
id varchar(21) not null,
5+
/** The whole feature can be disabled */
6+
enabled boolean not null default false,
7+
/** Control each fields */
8+
fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
9+
primary key (tenant_id, id)
10+
);

0 commit comments

Comments
 (0)