0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(schemas): add account center table (#6761)

This commit is contained in:
wangsijie 2024-11-06 11:37:51 +08:00 committed by GitHub
parent fe06860645
commit 00e17525e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 0 deletions

View file

@ -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;

View file

@ -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>;

View file

@ -9,6 +9,7 @@ export * from './users.js';
export * from './sso-connector.js';
export * from './applications.js';
export * from './verification-records.js';
export * from './account-centers.js';
export {
configurableConnectorMetadataGuard,

View file

@ -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)
);