mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 03:55:38 -04:00
Docker self-hosting support: - Dockerfile (multi-stage Alpine build with tini init) - docker-compose.yml with named volume for SQLite persistence - /api/health endpoint for container health checks - Auto-migration on startup via drizzle-orm/libsql/migrator - Graceful shutdown (SIGTERM stops scheduler, closes DB) - Next.js standalone output mode for minimal image size Database driver migration (better-sqlite3 → @libsql/client): - Eliminates native C++ compilation, enabling Alpine Docker images - All DB queries converted from sync to async across services and routes - DATABASE_URL now uses libsql file: prefix format - drizzle.config.ts dialect changed to turso for libsql support - Initial migration files generated in drizzle/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
770 B
TypeScript
25 lines
770 B
TypeScript
import { createClient } from "@libsql/client";
|
|
import { drizzle } from "drizzle-orm/libsql";
|
|
import * as schema from "./schema";
|
|
|
|
const globalForDb = globalThis as unknown as {
|
|
_db: ReturnType<typeof drizzle> | undefined;
|
|
_client: ReturnType<typeof createClient> | undefined;
|
|
};
|
|
|
|
if (!globalForDb._client) {
|
|
globalForDb._client = createClient({
|
|
url: process.env.DATABASE_URL ?? "file:sqlite.db",
|
|
});
|
|
globalForDb._client.execute("PRAGMA journal_mode = WAL");
|
|
globalForDb._client.execute("PRAGMA foreign_keys = ON");
|
|
globalForDb._client.execute("PRAGMA busy_timeout = 5000");
|
|
}
|
|
|
|
if (!globalForDb._db) {
|
|
globalForDb._db = drizzle({ client: globalForDb._client, schema });
|
|
}
|
|
|
|
export const db = globalForDb._db;
|
|
export const client = globalForDb._client;
|