@launchql/cli
Version:
LaunchQL CLI
73 lines (72 loc) • 3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectDeployedChange = selectDeployedChange;
exports.selectDeployedPackage = selectDeployedPackage;
const core_1 = require("@launchql/core");
const pg_env_1 = require("pg-env");
async function selectDeployedChange(database, argv, prompter, log, action = 'revert') {
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
const client = new core_1.LaunchQLMigrate(pgEnv);
let selectedPackage;
if (argv.package) {
selectedPackage = argv.package;
}
else {
const packageStatuses = await client.status();
if (packageStatuses.length === 0) {
log.warn('No deployed packages found in database');
return undefined;
}
const packageAnswer = await prompter.prompt(argv, [{
type: 'autocomplete',
name: 'package',
message: `Select package to ${action} from:`,
options: packageStatuses.map(status => ({
name: status.package,
value: status.package,
description: `${status.totalDeployed} changes, last: ${status.lastChange}`
}))
}]);
selectedPackage = packageAnswer.package;
}
const deployedChanges = await client.getDeployedChanges(database, selectedPackage);
if (deployedChanges.length === 0) {
log.warn(`No deployed changes found for package ${selectedPackage}`);
return undefined;
}
const changeAnswer = await prompter.prompt(argv, [{
type: 'autocomplete',
name: 'change',
message: `Select change to ${action} to in ${selectedPackage}:`,
options: deployedChanges.map(change => ({
name: change.change_name,
value: change.change_name,
description: `Deployed: ${new Date(change.deployed_at).toLocaleString()}`
}))
}]);
const selectedChange = changeAnswer.change;
return `${selectedPackage}:${selectedChange}`;
}
async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') {
if (argv.package) {
return argv.package;
}
const pgEnv = (0, pg_env_1.getPgEnvOptions)({ database });
const client = new core_1.LaunchQLMigrate(pgEnv);
const packageStatuses = await client.status();
if (packageStatuses.length === 0) {
log.warn('No deployed packages found in database');
return undefined;
}
const packageAnswer = await prompter.prompt(argv, [{
type: 'autocomplete',
name: 'package',
message: `Select package to ${action}:`,
options: packageStatuses.map(status => ({
name: status.package,
value: status.package,
description: `${status.totalDeployed} changes, last: ${status.lastChange}`
}))
}]);
return packageAnswer.package;
}
;