UNPKG

@launchql/cli

Version:
60 lines (59 loc) 2.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@launchql/core"); const logger_1 = require("@launchql/logger"); const env_1 = require("@launchql/env"); const pg_env_1 = require("pg-env"); const core_2 = require("@launchql/core"); const types_1 = require("@launchql/types"); const path_1 = __importDefault(require("path")); const utils_1 = require("../utils"); const log = new logger_1.Logger('clear'); exports.default = async (argv, prompter, _options) => { const database = await (0, utils_1.getTargetDatabase)(argv, prompter, { message: 'Select database' }); const questions = [ { name: 'yes', type: 'confirm', message: 'Are you sure you want to clear ALL changes from the plan? This will remove all changes and their associated files.', required: true } ]; let { yes, cwd } = await prompter.prompt(argv, questions); if (!yes) { log.info('Operation cancelled.'); return; } log.debug(`Using current directory: ${cwd}`); const pkg = new core_1.LaunchQLPackage(cwd); if (!pkg.isInModule()) { throw new Error('Not in a LaunchQL module directory. Please run this command from within a module.'); } const modulePath = pkg.getModulePath(); if (!modulePath) { throw new Error('Could not resolve module path'); } const planPath = path_1.default.join(modulePath, 'launchql.plan'); const result = (0, core_2.parsePlanFile)(planPath); if (result.errors.length > 0) { throw types_1.errors.PLAN_PARSE_ERROR({ planPath, errors: result.errors.map(e => e.message).join(', ') }); } const plan = result.data; if (plan.changes.length === 0) { log.info('Plan is already empty - nothing to clear.'); return; } const firstChange = plan.changes[0].name; log.info(`Found ${plan.changes.length} changes in plan. Clearing from first change: ${firstChange}`); const opts = (0, env_1.getEnvOptions)({ pg: (0, pg_env_1.getPgEnvOptions)({ database }) }); await pkg.removeFromPlan(firstChange); log.success(`✅ Successfully cleared all changes from the plan.`); return argv; };