2023-04-04 03:23:25 -05:00
|
|
|
import { generateStandardId } from '@logto/shared/universal';
|
2023-02-20 22:45:06 -05:00
|
|
|
import chalk from 'chalk';
|
|
|
|
import inquirer from 'inquirer';
|
2024-03-16 06:04:55 -05:00
|
|
|
import { sql } from '@silverhand/slonik';
|
2023-02-20 22:45:06 -05:00
|
|
|
|
|
|
|
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
|
2023-02-21 08:24:43 -05:00
|
|
|
);
|
2023-02-20 22:45:06 -05:00
|
|
|
`);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default alteration;
|