New table compliance_item_history stores an append-only audit trail of changes to resolution_date and remediation_plan. The current values remain on compliance_items for fast VCL reporting queries (no double-counting). Backend: - Migration: creates compliance_item_history with indexes - PATCH /items/:hostname/metadata: records old→new in history before updating, accepts optional change_reason field (max 500 chars) - GET /items/:hostname: returns history array (last 10 entries, newest first) - POST /vcl/bulk-commit: records history for each changed field per hostname Frontend: - ComplianceDetailPanel: added change reason input below Save button - Added Change History section showing field changes with timestamps, usernames, old→new values, and reasons - Re-fetches detail after save to show updated history immediately Tests updated to match new transaction-based PATCH flow.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
// Run all Postgres-compatible migrations in order.
|
|
// Each migration is idempotent (safe to re-run).
|
|
// Used by CI/CD pipeline during deploy to ensure schema is up to date.
|
|
//
|
|
// Usage: cd backend && node migrations/run-all.js
|
|
|
|
const { execSync } = require('child_process');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const MIGRATIONS_DIR = __dirname;
|
|
|
|
// Only run migrations that use the Postgres pool (not legacy SQLite ones).
|
|
// Add new migrations to this list as they're created.
|
|
const POSTGRES_MIGRATIONS = [
|
|
'add_decom_workflow_type.js',
|
|
'add_fp_submissions_dismissed.js',
|
|
'add_fp_submissions_requeued_at.js',
|
|
'add_vcl_reporting_columns.js',
|
|
'add_vcl_vertical_metadata.js',
|
|
'add_vcl_multi_vertical.js',
|
|
'add_compliance_item_history.js',
|
|
];
|
|
|
|
async function runAll() {
|
|
console.log(`[Migrations] Running ${POSTGRES_MIGRATIONS.length} Postgres migration(s)...`);
|
|
let succeeded = 0;
|
|
let failed = 0;
|
|
|
|
for (const file of POSTGRES_MIGRATIONS) {
|
|
const fullPath = path.join(MIGRATIONS_DIR, file);
|
|
if (!fs.existsSync(fullPath)) {
|
|
console.error(` [FAIL] ${file}: file not found`);
|
|
failed++;
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
console.log(` [run] ${file}`);
|
|
execSync(`node ${fullPath}`, {
|
|
cwd: path.join(MIGRATIONS_DIR, '..'),
|
|
stdio: 'inherit',
|
|
timeout: 30000,
|
|
});
|
|
succeeded++;
|
|
} catch (err) {
|
|
console.error(` [FAIL] ${file}: exit code ${err.status}`);
|
|
failed++;
|
|
}
|
|
}
|
|
|
|
console.log(`[Migrations] Done: ${succeeded} applied, ${failed} failed`);
|
|
if (failed > 0) process.exit(1);
|
|
}
|
|
|
|
runAll();
|