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.13.0-1705991158-update-invitation-indices.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-03-16 06:04:55 -05:00
import { sql } from '@silverhand/slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
/**
* @fileoverview Separates the index (tenant_id, inviter_id, organization_id) to two indices. Also
* makes the inviter_id nullable.
*/
const alteration: AlterationScript = {
up: async (pool) => {
await pool.query(sql`
alter table organization_invitations
drop constraint organization_invitations_tenant_id_inviter_id_organization_fkey,
add foreign key (inviter_id) references users (id) on update cascade on delete cascade,
add foreign key (organization_id) references organizations (id) on update cascade on delete cascade,
alter column inviter_id drop not null;
`);
},
down: async (pool) => {
await pool.query(sql`
alter table organization_invitations
drop constraint organization_invitations_inviter_id_fkey,
drop constraint organization_invitations_organization_id_fkey,
add foreign key (tenant_id, inviter_id, organization_id) references organization_user_relations
(tenant_id, user_id, organization_id) on update cascade on delete cascade,
alter column inviter_id set not null;
`);
},
};
export default alteration;