2022-09-23 02:02:35 -05:00
|
|
|
import { DatabasePool, sql } from 'slonik';
|
2022-09-22 00:36:57 -05:00
|
|
|
|
2022-09-26 03:38:27 -05:00
|
|
|
export type AlterationScript = {
|
2022-09-23 02:02:35 -05:00
|
|
|
up: (pool: DatabasePool) => Promise<void>;
|
|
|
|
down: (pool: DatabasePool) => Promise<void>;
|
|
|
|
};
|
2022-09-22 00:36:57 -05:00
|
|
|
|
2022-09-26 03:38:27 -05:00
|
|
|
const alteration: AlterationScript = {
|
2022-09-22 00:36:57 -05:00
|
|
|
up: async (pool) => {
|
|
|
|
// [Pull] feat(core): machine to machine apps #1973
|
|
|
|
await pool.query(sql`
|
|
|
|
alter type application_type add value 'MachineToMachine';
|
|
|
|
alter table applications add role_names jsonb not null default '[]'::jsonb;
|
|
|
|
`);
|
|
|
|
},
|
|
|
|
down: async (pool) => {
|
|
|
|
// [Pull] feat(core): machine to machine apps #1973
|
|
|
|
await pool.query(sql`
|
|
|
|
-- Drop role_names
|
|
|
|
alter table applications drop role_names;
|
|
|
|
|
|
|
|
-- Drop enum 'MachineToMachine'
|
|
|
|
create type application_type_new as enum ('Native', 'SPA', 'Traditional');
|
|
|
|
delete from applications where "type"='MachineToMachine';
|
|
|
|
alter table applications
|
|
|
|
alter column "type" type application_type_new
|
|
|
|
using ("type"::text::application_type_new);
|
|
|
|
drop type application_type;
|
|
|
|
alter type application_type_new rename to application_type;
|
|
|
|
`);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-09-26 03:38:27 -05:00
|
|
|
export default alteration;
|