ci(deploy): Auto-Deploy-Runner für Push auf main + reproduzierbarer API-Build
ci / quality (push) Failing after 35s
ci / build (push) Has been skipped
deploy / deploy (push) Successful in 53s

- .gitea/workflows/deploy.yml: deployt bei Push auf main via Host-Runner
  (git reset --hard origin/main in /opt/build/cockpit, docker compose up
  -d --build in /opt/stacks/cockpit, Healthcheck auf cockpit-api).
- Auto-Migrate: runMigrations() (drizzle-orm Migrator) wird beim API-Start
  aufgerufen; Schema wird vor dem Listen idempotent aktualisiert.
- API-Dockerfile: Workspace-Libs (@cockpit/db, @cockpit/shared) werden jetzt
  mit Emit kompiliert und main/exports im Image auf dist gebogen. Vorher war
  das Prod-Image nicht reproduzierbar baubar (Node konnte die TS-Quelle der
  Libs nicht laden → ERR_MODULE_NOT_FOUND). Dev-Modus und Web-/Vite-Build
  bleiben unberührt.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Raffael SheikhandClaude Opus 4.8 committed 2026-06-05 18:51:17 +02:00
1 parent 9f3ee13094
commit 3b928d0ad0
5 files changed
+102 -1

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
export * from './schema.js';
export { createDbClient } from './client.js';
export { runMigrations } from './migrate.js';
export type { Db, CreateDbClientOptions } from './client.js';
export const DB_VERSION = '0.0.1';
+31
View File
@@ -0,0 +1,31 @@
import { drizzle } from 'drizzle-orm/node-postgres';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
import pg from 'pg';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
/**
* Wendet alle ausstehenden Drizzle-Migrationen aus `packages/db/migrations` an.
* Idempotent: Drizzle führt Buch über bereits eingespielte Migrationen in
* `__drizzle_migrations` und überspringt sie. Wird beim API-Start aufgerufen,
* damit ein Deploy automatisch das Schema aktualisiert.
*
* Der Migrations-Ordner liegt eine Ebene über dieser Datei — funktioniert
* sowohl für die kompilierte Variante (`dist/migrate.js` → `../migrations`)
* als auch im Dev-Modus (`src/migrate.ts` → `../migrations`).
*/
export async function runMigrations(connectionString: string): Promise<void> {
const migrationsFolder = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'..',
'migrations',
);
const pool = new pg.Pool({ connectionString, max: 1 });
try {
const db = drizzle(pool);
await migrate(db, { migrationsFolder });
} finally {
await pool.end();
}
}