0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-17 22:31:28 -05:00

refactor(core): add migration scripts for #1973

This commit is contained in:
Gao Sun 2022-09-22 13:36:57 +08:00
parent c2aa427016
commit b367cd3380
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
4 changed files with 39 additions and 2 deletions

View file

@ -2,7 +2,13 @@ import { existsSync } from 'fs';
import { readdir, readFile } from 'fs/promises';
import path from 'path';
import { LogtoConfig, LogtoConfigs } from '@logto/schemas';
import {
LogtoConfig,
LogtoConfigs,
DatabaseVersion,
databaseVersionGuard,
MigrationScript,
} from '@logto/schemas';
import { conditionalString } from '@silverhand/essentials';
import chalk from 'chalk';
import { DatabasePool, sql } from 'slonik';
@ -15,7 +21,6 @@ import {
logtoConfigsTableFilePath,
migrationFilesDirectory,
} from './constants';
import { DatabaseVersion, databaseVersionGuard, MigrationScript } from './types';
import { compareVersion, getVersionFromFileName, migrationFileNameRegex } from './utils';
const { table, fields } = convertToIdentifiers(LogtoConfigs);

View file

@ -0,0 +1,31 @@
import { sql } from 'slonik';
import { MigrationScript } from '../types';
const migration: MigrationScript = {
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 migration;

View file

@ -2,3 +2,4 @@ export * from './connector';
export * from './log';
export * from './oidc-config';
export * from './user';
export * from './migration';