UNPKG

@launchql/cli

Version:
69 lines (68 loc) 2.8 kB
import { LaunchQLMigrate } from '@launchql/core'; import { getPgEnvOptions } from 'pg-env'; export async function selectDeployedChange(database, argv, prompter, log, action = 'revert') { const pgEnv = getPgEnvOptions({ database }); const client = new 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}`; } export async function selectDeployedPackage(database, argv, prompter, log, action = 'revert') { if (argv.package) { return argv.package; } const pgEnv = getPgEnvOptions({ database }); const client = new 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; }