Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
* refactor: add nitro bootstrap plugin to ensure app is started before first call * refactor(bootstrap): avoid duplicate event firing * refactor: extract common setup in initModule function * refactor: remove proxy pattern for db and auth Since we migrated away from rr this is not needed anymore as the bundler correctly split chunks
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { Database } from "bun:sqlite";
|
|
import { relations } from "./relations";
|
|
import path from "node:path";
|
|
import { drizzle } from "drizzle-orm/bun-sqlite";
|
|
import { migrate } from "drizzle-orm/bun-sqlite/migrator";
|
|
import { DATABASE_URL } from "../core/constants";
|
|
import fs from "node:fs";
|
|
import { config } from "../core/config";
|
|
import * as schema from "./schema";
|
|
|
|
fs.mkdirSync(path.dirname(DATABASE_URL), { recursive: true });
|
|
|
|
if (
|
|
fs.existsSync(path.join(path.dirname(DATABASE_URL), "ironmount.db")) &&
|
|
!fs.existsSync(DATABASE_URL)
|
|
) {
|
|
fs.renameSync(
|
|
path.join(path.dirname(DATABASE_URL), "ironmount.db"),
|
|
DATABASE_URL,
|
|
);
|
|
}
|
|
|
|
const sqlite = new Database(DATABASE_URL);
|
|
export const db = drizzle({ client: sqlite, relations, schema });
|
|
|
|
export const runDbMigrations = () => {
|
|
let migrationsFolder: string;
|
|
|
|
if (config.migrationsPath) {
|
|
migrationsFolder = config.migrationsPath;
|
|
} else if (config.__prod__) {
|
|
migrationsFolder = path.join("/app", "assets", "migrations");
|
|
} else {
|
|
migrationsFolder = path.join(process.cwd(), "app", "drizzle");
|
|
}
|
|
|
|
migrate(db, { migrationsFolder });
|
|
|
|
sqlite.run("PRAGMA foreign_keys = ON;");
|
|
};
|