initialize native database on boot

This commit is contained in:
Namekuji 2023-06-02 15:01:29 -04:00
parent 8bb87f9ea4
commit ba578c8701
No known key found for this signature in database
GPG key ID: B541BD6E646CABC7

View file

@ -78,6 +78,7 @@ import { entities as charts } from "@/services/chart/entities.js";
import { envOption } from "../env.js";
import { dbLogger } from "./logger.js";
import { redisClient } from "./redis.js";
import { nativeInitDatabase } from "native-utils/built/index.js";
const sqlLogger = dbLogger.createSubLogger("sql", "gray", false);
@ -220,6 +221,9 @@ export const db = new DataSource({
});
export async function initDb(force = false) {
await nativeInitDatabase(
`postgres://${config.db.user}:${config.db.pass}@${config.db.host}:${config.db.port}/${config.db.db}`,
);
if (force) {
if (db.isInitialized) {
await db.destroy();