#!/usr/bin/env node /** * Run a migration file against the task-mcp database * Usage: node run-migration.mjs */ import pg from 'pg'; import { readFileSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const { Pool } = pg; // Database configuration const pool = new Pool({ host: process.env.POSTGRES_HOST || 'infra.agiliton.internal', port: 5432, database: 'agiliton', user: 'agiliton', password: 'QtqiwCOAUpQNF6pjzOMAREzUny2bY8V1', max: 1, connectionTimeoutMillis: 5000, }); async function runMigration(migrationFile) { const client = await pool.connect(); try { console.log(`Running migration: ${migrationFile}`); // Read migration file const migrationPath = join(__dirname, 'migrations', migrationFile); const sql = readFileSync(migrationPath, 'utf-8'); // Execute migration await client.query(sql); console.log(`Migration completed successfully: ${migrationFile}`); } catch (error) { console.error(`Migration failed: ${error.message}`); throw error; } finally { client.release(); await pool.end(); } } // Get migration file from command line const migrationFile = process.argv[2]; if (!migrationFile) { console.error('Usage: node run-migration.mjs '); console.error('Example: node run-migration.mjs 018_deployments.sql'); process.exit(1); } runMigration(migrationFile) .then(() => process.exit(0)) .catch(() => process.exit(1));