0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/schemas/alterations/1.0.0_rc.1-1676906977-remove-demo-app.ts
Gao Sun aa203308f0
refactor: reorg packages
update `@logto/shared` to a non-business package
and put business components into `@logto/*kit`.
2023-04-04 16:28:48 +08:00

50 lines
1.4 KiB
TypeScript

import { generateStandardId } from '@logto/shared/universal';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {
const isCi = process.env.CI;
const { confirm } = await inquirer.prompt<{ confirm: boolean }>({
type: 'confirm',
name: 'confirm',
message: String(
chalk.bold(chalk.yellow('***CAUTION***')) +
'\n' +
'The application `demo-app` will be removed from your database.\n' +
'Usually this is harmless since the demo app will be still functional with predefined data.\n' +
'Are you sure to continue?'
),
default: false,
when: !isCi,
});
if (!isCi && !confirm) {
throw new Error('User cancelled alteration.');
}
await pool.query(sql`
delete from applications where id = 'demo-app';
`);
},
down: async (pool) => {
await pool.query(sql`
insert into applications
(tenant_id, id, secret, name, description, type, oidc_client_metadata)
values (
'default',
'demo-app',
${generateStandardId()},
'Demo App',
'Logto demo app.',
'SPA',
'{ "redirectUris": [], "postLogoutRedirectUris": [] }'::jsonb
);
`);
},
};
export default alteration;