39 lines
1.3 KiB
TypeScript
Executable File
39 lines
1.3 KiB
TypeScript
Executable File
import { Pool } from 'pg';
|
|
import { runner } from 'node-pg-migrate';
|
|
import path from 'path';
|
|
|
|
export const testPool = new Pool({
|
|
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'
|
|
});
|
|
|
|
export async function migrate(): Promise<void> {
|
|
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, 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();
|
|
} |