chore: replace manual SQL migrations with node-pg-migrate
SonarQube Analysis / sonarqube (pull_request) Successful in 2m42s
Tests / backend-unit (pull_request) Successful in 34s
Tests / backend-integration (pull_request) Successful in 50s
Tests / frontend-e2e (pull_request) Failing after 38s

This commit is contained in:
2026-08-14 10:05:09 -05:00
parent 6ca3366821
commit 7f4479605a
8 changed files with 284 additions and 75 deletions
+17 -5
View File
@@ -1,5 +1,5 @@
import { Pool } from 'pg';
import fs from 'fs';
import { runner } from 'node-pg-migrate';
import path from 'path';
export const testPool = new Pool({
@@ -11,17 +11,29 @@ export const testPool = new Pool({
});
export async function migrate(): Promise<void> {
const sql = fs.readFileSync(path.join(__dirname, '..', '..', '..', 'init.sql'), 'utf-8');
await testPool.query(sql);
await runner({
databaseUrl: {
host: process.env.TEST_PGHOST || 'localhost',
port: parseInt(process.env.TEST_PGPORT || '55432', 10),
user: process.env.TEST_PGUSER || 'redefined_test',
password: process.env.TEST_PGPASSWORD || 'redefined_test',
database: process.env.TEST_PGDATABASE || 'redefined_test'
},
dir: path.resolve(__dirname, '..', '..', '..', 'migrations'),
direction: 'up',
migrationsTable: 'pgmigrations',
count: Infinity
});
}
export async function resetDb(): Promise<void> {
await testPool.query(`
TRUNCATE TABLE orders, customer_tokens, customer_sessions, customers, item_images, items
TRUNCATE TABLE orders, checkout_items, checkouts, shipping_addresses, cart_items, carts,
customer_tokens, customer_sessions, customers, item_images, items
RESTART IDENTITY CASCADE
`);
}
export async function closeDb(): Promise<void> {
await testPool.end();
}
}