mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 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`
|
|
alter table organization_invitations
|
|
drop column magic_link_id;
|
|
`);
|
|
await dropTableRls(pool, 'magic_links');
|
|
await pool.query(sql`
|
|
drop table magic_links;
|
|
`);
|
|
},
|
|
down: async (pool) => {
|
|
await pool.query(sql`
|
|
create table magic_links (
|
|
tenant_id varchar(21) not null
|
|
references tenants (id) on update cascade on delete cascade,
|
|
/** The unique identifier of the link. */
|
|
id varchar(21) not null,
|
|
/** The token that can be used to verify the link. */
|
|
token varchar(32) not null,
|
|
/** The time when the link was created. */
|
|
created_at timestamptz not null default (now()),
|
|
/** The time when the link was consumed. */
|
|
consumed_at timestamptz,
|
|
primary key (id)
|
|
);
|
|
|
|
create index magic_links__token
|
|
on magic_links (tenant_id, token);
|
|
`);
|
|
await applyTableRls(pool, 'magic_links');
|
|
await pool.query(sql`
|
|
alter table organization_invitations
|
|
add column magic_link_id varchar(21)
|
|
references magic_links (id) on update cascade on delete cascade;
|
|
`);
|
|
},
|
|
};
|
|
|
|
export default alteration;
|