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:
parent
fe06860645
commit
00e17525e7
4 changed files with 70 additions and 0 deletions
|
@ -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;
|
|
@ -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>;
|
|
@ -9,6 +9,7 @@ export * from './users.js';
|
||||||
export * from './sso-connector.js';
|
export * from './sso-connector.js';
|
||||||
export * from './applications.js';
|
export * from './applications.js';
|
||||||
export * from './verification-records.js';
|
export * from './verification-records.js';
|
||||||
|
export * from './account-centers.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
configurableConnectorMetadataGuard,
|
configurableConnectorMetadataGuard,
|
||||||
|
|
10
packages/schemas/tables/account_centers.sql
Normal file
10
packages/schemas/tables/account_centers.sql
Normal 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)
|
||||||
|
);
|
Loading…
Reference in a new issue