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.0.0_rc.0-1673882867-fix-alteration-issues.ts
2023-02-02 22:21:34 +08:00

69 lines
2 KiB
TypeScript

import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {
await pool.query(sql`
alter table roles_scopes
drop constraint roles_scopes_role_id_fkey;
`);
await pool.query(sql`
alter table users_roles
drop constraint users_roles_role_id_fkey;
`);
await pool.query(sql`
alter table roles
drop constraint if exists roles_pkey;
`);
await pool.query(sql`drop index if exists roles_pkey;`);
await pool.query(sql`
alter table roles
add primary key (id);
`);
await pool.query(sql`
alter table roles_scopes
drop constraint if exists roles_permissison_pkey,
drop constraint if exists roles_scopes_pkey,
add primary key (role_id, scope_id);
`);
await pool.query(sql`
alter table users_roles
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
`);
await pool.query(sql`
alter table roles_scopes
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
`);
},
down: async (pool) => {
await pool.query(sql`
alter table roles_scopes
drop constraint roles_scopes_role_id_fkey;
`);
await pool.query(sql`
alter table users_roles
drop constraint users_roles_role_id_fkey;
`);
await pool.query(sql`
alter table roles_scopes
drop constraint if exists roles_permissison_pkey,
drop constraint if exists roles_scopes_pkey,
add primary key (role_id, scope_id);
`);
await pool.query(sql`
alter table users_roles
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
`);
await pool.query(sql`
alter table roles_scopes
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
`);
},
};
export default alteration;