fix: database should not overwrite
This commit is contained in:
@@ -4,9 +4,22 @@
|
||||
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import { Database } from "bun:sqlite";
|
||||
import { dirname } from "node:path";
|
||||
import { existsSync, mkdirSync } from "node:fs";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const DATABASE_PATH = `${import.meta.dir}/db.sqlite3`;
|
||||
const DEFAULT_DATABASE_PATH = "./data/db.sqlite3";
|
||||
const LEGACY_DATABASE_PATH = `${import.meta.dir}/db.sqlite3`;
|
||||
|
||||
const DATABASE_PATH =
|
||||
Bun.env.DATABASE_PATH ??
|
||||
(existsSync(DEFAULT_DATABASE_PATH)
|
||||
? DEFAULT_DATABASE_PATH
|
||||
: existsSync(LEGACY_DATABASE_PATH)
|
||||
? LEGACY_DATABASE_PATH
|
||||
: DEFAULT_DATABASE_PATH);
|
||||
|
||||
mkdirSync(dirname(DATABASE_PATH), { recursive: true });
|
||||
|
||||
const sqlite = new Database(DATABASE_PATH);
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user