UNPKG

@launchql/cli

Version:
95 lines (94 loc) • 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@launchql/core"); const core_2 = require("@launchql/core"); const logger_1 = require("@launchql/logger"); const fs_1 = require("fs"); const path_1 = require("path"); const pg_env_1 = require("pg-env"); const database_1 = require("../../utils/database"); const log = new logger_1.Logger('migrate-status'); exports.default = async (argv, prompter, options) => { const cwd = argv.cwd || process.cwd(); const planPath = (0, path_1.join)(cwd, 'launchql.plan'); if (!(0, fs_1.existsSync)(planPath)) { log.error(`No launchql.plan found in ${cwd}`); process.exit(1); } // Get database configuration const pgEnv = (0, pg_env_1.getPgEnvOptions)(); const targetDatabase = await (0, database_1.getTargetDatabase)(argv, prompter, { message: 'Select database to check migration status' }); const client = new core_1.LaunchQLMigrate({ host: pgEnv.host, port: pgEnv.port, user: pgEnv.user, password: pgEnv.password, database: pgEnv.database }); try { // Parse plan file to get package name const planResult = (0, core_2.parsePlanFile)(planPath); if (!planResult.data || planResult.errors.length > 0) { log.error('Failed to parse plan file:', planResult.errors); process.exit(1); } const plan = planResult.data; // Switch to target database const targetClient = new core_1.LaunchQLMigrate({ host: pgEnv.host, port: pgEnv.port, user: pgEnv.user, password: pgEnv.password, database: targetDatabase }); const statusResults = await targetClient.status(plan.package); console.log('\nšŸ“Š Migration Status\n'); console.log(`Database: ${targetDatabase}`); if (statusResults.length > 0) { const status = statusResults[0]; console.log(`Package: ${status.package}`); console.log(`Total Deployed: ${status.totalDeployed}`); if (status.lastChange) { console.log(`Last Change: ${status.lastChange}`); console.log(`Last Deployed: ${status.lastDeployed.toLocaleString()}`); } else { console.log('No changes deployed yet'); } } else { console.log(`Package: ${plan.package}`); console.log('No deployment history found'); } // Show recent changes const recentChanges = await targetClient.getRecentChanges(targetDatabase, 5); if (recentChanges.length > 0) { console.log('\nšŸ“‹ Recent Changes:\n'); recentChanges.forEach((change) => { const status = change.deployed_at ? 'āœ…' : 'ā³'; const date = change.deployed_at ? new Date(change.deployed_at).toLocaleString() : 'Not deployed'; console.log(`${status} ${change.change_name.padEnd(30)} ${date}`); }); } // Show pending changes const pendingChanges = await targetClient.getPendingChanges(planPath, targetDatabase); if (pendingChanges.length > 0) { console.log(`\nā³ Pending Changes: ${pendingChanges.length}\n`); pendingChanges.slice(0, 5).forEach((change) => { console.log(` - ${change}`); }); if (pendingChanges.length > 5) { console.log(` ... and ${pendingChanges.length - 5} more`); } } else { console.log('\nāœ… All changes deployed'); } } catch (error) { log.error('Failed to get migration status:', error); process.exit(1); } };