Files
zpan/server/platform/node.ts
T
saltboandClaude Opus 4.6 b73d7a0a0b feat(server): auto-migrate schema on Node platform boot
createNodePlatform now invokes drizzle-orm's better-sqlite3 migrator
against the configured migrations folder (defaults to ./migrations,
overridable via MIGRATIONS_DIR). Removes the operational burden of
manually running drizzle-kit against a Docker volume — the Node
runtime image no longer needs drizzle-kit (a devDependency) at all.

Tests are unaffected: server/test/setup.ts builds an in-memory SQLite
with hand-written DDL and never touches createNodePlatform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 11:06:16 -04:00

25 lines
737 B
TypeScript

import Database from 'better-sqlite3'
import { drizzle } from 'drizzle-orm/better-sqlite3'
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import * as authSchema from '../db/auth-schema'
import * as schema from '../db/schema'
import type { Platform } from './interface'
export function createNodePlatform(): Platform {
const dbPath = process.env.DATABASE_URL || './zpan.db'
const migrationsFolder = process.env.MIGRATIONS_DIR || './migrations'
const sqlite = new Database(dbPath)
sqlite.pragma('journal_mode = WAL')
const db = drizzle(sqlite, { schema: { ...schema, ...authSchema } })
migrate(db, { migrationsFolder })
return {
db,
getEnv(key: string) {
return process.env[key]
},
}
}