Files
miles c250653961 Add comprehensive test suite for application functionality
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers.
- Create configuration tests to validate loading of defaults and environment overrides.
- Add tests for FEDL service to verify data handling and snapshot functionality.
- Introduce GitHub service tests to check API data normalization and caching behavior.
- Develop monitor service tests for network checks and uptime calculations.
- Implement persistence tests to ensure database migrations are idempotent and data persists across restarts.
- Add vault service tests for session management and brute-force protection mechanisms.
- Include helper functions for test context creation and JSON response handling.
2026-11-08 16:24:06 -06:00

44 lines
1.2 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const HERE = path.dirname(fileURLToPath(import.meta.url));
const MIGRATIONS_DIR = path.join(HERE, 'migrations');
export function migrate(db, { migrationsDir = MIGRATIONS_DIR } = {}) {
db.exec(`
CREATE TABLE IF NOT EXISTS schema_migrations (
version INTEGER PRIMARY KEY,
name TEXT NOT NULL,
applied_at TEXT NOT NULL
);
`);
const applied = new Set(
db.prepare('SELECT version FROM schema_migrations').all().map((row) => row.version)
);
const files = fs
.readdirSync(migrationsDir)
.filter((name) => /^\d+_.+\.sql$/.test(name))
.sort((a, b) => a.localeCompare(b));
const insert = db.prepare(
'INSERT INTO schema_migrations (version, name, applied_at) VALUES (?, ?, ?)'
);
let count = 0;
for (const file of files) {
const version = Number.parseInt(file.split('_')[0], 10);
if (applied.has(version)) continue;
const sql = fs.readFileSync(path.join(migrationsDir, file), 'utf8');
const run = db.transaction(() => {
db.exec(sql);
insert.run(version, file, new Date().toISOString());
});
run();
count += 1;
}
return count;
}