mirror of
https://github.com/saltbo/zpan.git
synced 2026-10-31 02:41:33 +08:00
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>
25 lines
737 B
TypeScript
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]
|
|
},
|
|
}
|
|
}
|