import { Command } from "commander"; import { getUnappliedMigrations, Migration } from "@/migrations/data"; import { triggerMigration } from "@/migrations/apply"; import { jsonToYaml } from "@/yaml"; import { migrateOptionsSchema } from "."; export const apply = new Command() .name("apply") .description("Apply pending infrastructure migrations in sequence") .option( "-d, --directory ", "Directory for the base infrastructure folder where the component should be added", process.cwd() ) .action(async (options) => { const cmdArgs = migrateOptionsSchema.parse(options); const currentDirectory = process.cwd(); process.chdir(cmdArgs.directory); console.log("Applying migrations..."); const migrations: Migration[] = await getUnappliedMigrations(); if (migrations.length === 0) { console.log("No migrations to apply."); return; } for (const migration of migrations) { console.log(`Applying migration ${migration.id}...`); await triggerMigration(migration); console.log( `Migration ${migration.id} applied.\n\n${jsonToYaml(migration)}` ); } process.chdir(currentDirectory); });