0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/schemas/alterations/next-1663923211-machine-to-machine-app.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

import { DatabasePool, sql } from 'slonik';
export type AlterationScript = {
up: (pool: DatabasePool) => Promise<void>;
down: (pool: DatabasePool) => Promise<void>;
};
const alteration: AlterationScript = {
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;
`);
},
};
export default alteration;