2024-03-16 06:04:55 -05:00
|
|
|
import { sql } from '@silverhand/slonik';
|
2023-01-17 04:52:54 -05:00
|
|
|
|
|
|
|
import type { AlterationScript } from '../lib/types/alteration.js';
|
|
|
|
|
|
|
|
const alteration: AlterationScript = {
|
|
|
|
up: async (pool) => {
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table roles_scopes
|
2023-01-18 00:12:57 -05:00
|
|
|
drop constraint roles_scopes_role_id_fkey;
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table users_roles
|
2023-01-18 00:12:57 -05:00
|
|
|
drop constraint users_roles_role_id_fkey;
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table roles
|
2023-01-18 00:12:57 -05:00
|
|
|
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);
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table roles_scopes
|
2023-01-18 00:12:57 -05:00
|
|
|
drop constraint if exists roles_permissison_pkey,
|
|
|
|
drop constraint if exists roles_scopes_pkey,
|
|
|
|
add primary key (role_id, scope_id);
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table users_roles
|
2023-01-18 00:12:57 -05:00
|
|
|
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
await pool.query(sql`
|
|
|
|
alter table roles_scopes
|
2023-01-18 00:12:57 -05:00
|
|
|
add foreign key (role_id) references roles (id) on update cascade on delete cascade;
|
2023-01-17 04:52:54 -05:00
|
|
|
`);
|
|
|
|
},
|
|
|
|
down: async (pool) => {
|
2023-01-18 00:12:57 -05:00
|
|
|
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;
|
|
|
|
`);
|
2023-01-17 04:52:54 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default alteration;
|