0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/schemas/alterations/1.20.0-1725971571-add-verification-record.ts
2024-09-13 18:06:50 +08:00

35 lines
1.1 KiB
TypeScript

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 verification_records (
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
id varchar(21) not null,
user_id varchar(21)
references users (id) on update cascade on delete cascade,
created_at timestamptz not null default(now()),
expires_at timestamptz not null,
data jsonb /* @use VerificationRecordData */ not null default '{}'::jsonb,
primary key (id)
);
create index verification_records__id
on verification_records (tenant_id, id);
`);
await applyTableRls(pool, 'verification_records');
},
down: async (pool) => {
await dropTableRls(pool, 'verification_records');
await pool.query(sql`
drop table verification_records;
`);
},
};
export default alteration;