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:
parent
c2aa427016
commit
b367cd3380
4 changed files with 39 additions and 2 deletions
|
@ -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);
|
||||
|
|
31
packages/schemas/src/migrations/next.ts
Normal file
31
packages/schemas/src/migrations/next.ts
Normal 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;
|
|
@ -2,3 +2,4 @@ export * from './connector';
|
|||
export * from './log';
|
||||
export * from './oidc-config';
|
||||
export * from './user';
|
||||
export * from './migration';
|
||||
|
|
Loading…
Add table
Reference in a new issue