fix: locate migrations via process.cwd() (was dist/migrations -> ENOENT); add .dockerignore
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
.git
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
.astro
|
||||||
|
*.log
|
||||||
|
.env
|
||||||
|
# migrations/ + seeds/ NICHT ignorieren — werden zur Laufzeit gebraucht!
|
||||||
+10
-2
@@ -1,5 +1,5 @@
|
|||||||
import pg from 'pg';
|
import pg from 'pg';
|
||||||
import { readFileSync, readdirSync } from 'node:fs';
|
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { dirname, join } from 'node:path';
|
import { dirname, join } from 'node:path';
|
||||||
|
|
||||||
@@ -24,8 +24,16 @@ export async function one<T = any>(text: string, params?: any[]): Promise<T | nu
|
|||||||
export async function runMigrations(): Promise<void> {
|
export async function runMigrations(): Promise<void> {
|
||||||
await pool.query(`CREATE TABLE IF NOT EXISTS schema_migrations (
|
await pool.query(`CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||||
name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`);
|
name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`);
|
||||||
|
// Migrationen liegen im Projektwurzel-Ordner (Container: /app/migrations).
|
||||||
|
// Nicht relativ zum kompilierten Modul (dist/server/chunks) suchen!
|
||||||
const here = dirname(fileURLToPath(import.meta.url));
|
const here = dirname(fileURLToPath(import.meta.url));
|
||||||
const dir = join(here, '..', '..', 'migrations');
|
const candidates = [
|
||||||
|
join(process.cwd(), 'migrations'),
|
||||||
|
join(here, '..', '..', 'migrations'),
|
||||||
|
join(here, '..', '..', '..', 'migrations'),
|
||||||
|
];
|
||||||
|
const dir = candidates.find((d) => existsSync(d));
|
||||||
|
if (!dir) throw new Error(`migrations-Verzeichnis nicht gefunden (geprüft: ${candidates.join(', ')})`);
|
||||||
const files = readdirSync(dir).filter((f) => f.endsWith('.sql')).sort();
|
const files = readdirSync(dir).filter((f) => f.endsWith('.sql')).sort();
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const done = await one('SELECT name FROM schema_migrations WHERE name=$1', [file]);
|
const done = await one('SELECT name FROM schema_migrations WHERE name=$1', [file]);
|
||||||
|
|||||||
Reference in New Issue
Block a user