mirror of
https://github.com/logto-io/logto.git
synced 2024-12-23 20:33:16 -05:00
69 lines
2 KiB
TypeScript
69 lines
2 KiB
TypeScript
import { sql } from '@silverhand/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;
|