Complete migration setup

This commit is contained in:
Owen Schwartz 2024-12-25 16:40:39 -05:00
parent 907504eefb
commit 993eab5ac1
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
5 changed files with 79 additions and 129 deletions

View file

@ -3,10 +3,21 @@ import Database from "better-sqlite3";
import * as schema from "@server/db/schema";
import { APP_PATH } from "@server/config";
import path from "path";
import fs from "fs/promises";
export const location = path.join(APP_PATH, "db", "db.sqlite");
export const exists = await checkFileExists(location);
const sqlite = new Database(location);
export const db = drizzle(sqlite, { schema });
export default db;
async function checkFileExists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath);
return true;
} catch {
return false;
}
}

View file

@ -394,3 +394,5 @@ export type ResourcePincode = InferSelectModel<typeof resourcePincode>;
export type ResourcePassword = InferSelectModel<typeof resourcePassword>;
export type ResourceOtp = InferSelectModel<typeof resourceOtp>;
export type ResourceAccessToken = InferSelectModel<typeof resourceAccessToken>;
export type ResourceWhitelist = InferSelectModel<typeof resourceWhitelist>;
export type VersionMigration = InferSelectModel<typeof versionMigrations>;