import { mkdirSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { DatabaseSync } from "node:sqlite";

const dataDirectory = resolve(process.env.DATA_DIR ?? "data");
mkdirSync(dataDirectory, { recursive: true });

const database = new DatabaseSync(resolve(dataDirectory, "game.db"));
const schema = await readFile(new URL("../db/schema.sql", import.meta.url), "utf8");
database.exec(schema);
database.close();

console.log(`Database ready: ${resolve(dataDirectory, "game.db")}`);
