mirror of
https://github.com/tale/headplane.git
synced 2026-07-26 15:58:14 +00:00
b18147fa82
we also have added the necessary logic to auto prune ephemeral nodes because headscale doesn't seem to automatically remove them. this change made use of a database which is now stored in the persistent headplane directory.
27 lines
685 B
TypeScript
27 lines
685 B
TypeScript
import { mkdir } from 'node:fs/promises';
|
|
import { dirname } from 'node:path';
|
|
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
|
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
import log from '~/utils/log';
|
|
|
|
export async function createDbClient(path: string) {
|
|
try {
|
|
await mkdir(dirname(path), { recursive: true });
|
|
} catch (error) {
|
|
log.error(
|
|
'server',
|
|
'Failed to create directory for database at %s: %s',
|
|
path,
|
|
error instanceof Error ? error.message : String(error),
|
|
);
|
|
throw new Error(`Could not create directory for database at ${path}`);
|
|
}
|
|
|
|
const db = drizzle(path);
|
|
migrate(db, {
|
|
migrationsFolder: './drizzle',
|
|
});
|
|
|
|
return db;
|
|
}
|