30 lines
850 B
JavaScript
30 lines
850 B
JavaScript
import { readFileSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { Pool } from 'pg';
|
|
|
|
const databaseUrl = process.env.IDEMPOTENCY_DATABASE_URL;
|
|
|
|
if (!databaseUrl) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('IDEMPOTENCY_DATABASE_URL is required');
|
|
process.exit(1);
|
|
}
|
|
|
|
const scriptDir = resolve(fileURLToPath(new URL('.', import.meta.url)));
|
|
const migrationPath = resolve(scriptDir, '../sql/001_command_idempotency.sql');
|
|
const sql = readFileSync(migrationPath, 'utf8');
|
|
|
|
const pool = new Pool({
|
|
connectionString: databaseUrl,
|
|
max: Number.parseInt(process.env.IDEMPOTENCY_DB_POOL_MAX || '5', 10),
|
|
});
|
|
|
|
try {
|
|
await pool.query(sql);
|
|
// eslint-disable-next-line no-console
|
|
console.log('Idempotency migration applied successfully');
|
|
} finally {
|
|
await pool.end();
|
|
}
|