Added auto database creation based on sql scripts and jwt key cache

This commit is contained in:
fedyna-k
2025-01-16 23:13:58 +01:00
parent 914875a3df
commit 46a417f411
8 changed files with 70 additions and 7 deletions
+28
View File
@@ -0,0 +1,28 @@
import { Database } from "@db/sqlite";
export default async function ensureDatabases() {
for await (const file of Deno.readDir("databases/init")) {
if (!file.isFile) {
console.warn(`[WARN] Path ${file.name} is not a file.`);
continue;
}
const databaseName = file.name.substring(0, file.name.length - 4);
const databasePath = `databases/data/${databaseName}.db`;
try {
await Deno.stat(databasePath);
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
const sqlInitCode = await Deno.readTextFile(
`databases/init/${file.name}`,
);
const database = new Database(databasePath);
database.run(sqlInitCode);
database.close();
}
}
}
View File
View File