UNPKG

@launchql/cli

Version:
66 lines (65 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@launchql/core"); const logger_1 = require("@launchql/logger"); const pg_env_1 = require("pg-env"); const database_1 = require("../../utils/database"); const log = new logger_1.Logger('migrate-init'); exports.default = async (argv, prompter, _options) => { const pgEnv = (0, pg_env_1.getPgEnvOptions)(); // Get target database const database = await (0, database_1.getTargetDatabase)(argv, prompter, { message: 'Select database to initialize migration tracking' }); const questions = [ { name: 'yes', type: 'confirm', message: `Initialize LaunchQL migration schema in database "${database}"?`, required: true } ]; const { yes } = await prompter.prompt(argv, questions); if (!yes) { log.info('Operation cancelled.'); return; } log.info(`Initializing migration schema in database ${database}...`); const config = { host: pgEnv.host, port: pgEnv.port, user: pgEnv.user, password: pgEnv.password, database }; const client = new core_1.LaunchQLMigrate(config); try { await client.initialize(); log.success('Migration schema initialized successfully.'); // Check if there's an existing Sqitch deployment to import const hasSquitch = await client.hasSqitchTables(); if (hasSquitch) { const { importSquitch } = await prompter.prompt(argv, [ { name: 'importSquitch', type: 'confirm', message: 'Existing Sqitch deployment detected. Import it?', required: true } ]); if (importSquitch) { log.info('Importing Sqitch deployment history...'); await client.importFromSqitch(); log.success('Sqitch deployment imported successfully.'); } } } catch (error) { log.error(`Failed to initialize migration schema: ${error instanceof Error ? error.message : error}`); throw error; } finally { await client.close(); } return argv; };