Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
POSTGRES_PASSWORD=host39-local
# Used for bare-metal local dev (npm run dev / npm run migrate). Docker Compose
# injects its own DATABASE_URL (@db:5432), so this value is ignored under Docker.
DATABASE_URL=postgresql://host39:host39-local@localhost:5434/host39
JWT_SECRET=host39-dev-secret
JWT_EXPIRES_IN=7d
FRONTEND_URL=http://localhost:3002
Expand Down
14 changes: 11 additions & 3 deletions server/src/db/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { readdirSync } from 'node:fs';
import { readdirSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
import postgres from 'postgres';
import { buildConfig } from '../config.js';

/**
* Applies pending *.sql files from db/migrations in lexical order.
* Applies pending *.sql files from the migrations directory in lexical order.
* Tracks applied files in schema_migrations. Idempotent across runs.
* Each file runs in its own transaction.
*/
Expand All @@ -20,7 +21,14 @@ async function migrate(): Promise<void> {
)
`;

const dir = path.resolve(process.cwd(), 'db/migrations');
// Prefer migrations sitting next to this module (tsx running
// src/db/migrate.ts locally finds src/db/migrations). Fall back to the
// cwd-relative layout used by the Docker image, where the SQL files are
// copied to /app/db/migrations and the process runs from /app.
const moduleMigrations = path.join(path.dirname(fileURLToPath(import.meta.url)), 'migrations');
const dir = existsSync(moduleMigrations)
? moduleMigrations
: path.resolve(process.cwd(), 'db/migrations');
const files = readdirSync(dir)
.filter((f) => f.endsWith('.sql'))
.sort();
Expand Down
2 changes: 1 addition & 1 deletion server/src/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Wipes users + agent_cards and inserts 2 SMB + 2 personal test accounts.
*
* Usage:
* DATABASE_URL=postgresql://host39:host39-local@localhost:5433/host39 npx tsx src/scripts/seed.ts
* DATABASE_URL=postgresql://host39:host39-local@localhost:5434/host39 npx tsx src/scripts/seed.ts
*/

import bcrypt from 'bcryptjs';
Expand Down