Add debug route to delete the database
To simplify development add a debug route to delete the database content so that it'll be re-generated to the demo schedule.
This commit is contained in:
parent
25793fecb8
commit
16191a8dd2
2 changed files with 38 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { readFile, unlink, writeFile } from "node:fs/promises";
|
||||
import { Schedule } from "~/shared/types/schedule";
|
||||
import { Account, Subscription, Session } from "~/shared/types/account";
|
||||
import { generateDemoSchedule, generateDemoAccounts } from "./generate-demo-schedule";
|
||||
|
@ -13,6 +13,23 @@ const nextAccountIdPath = "data/next-account-id.json";
|
|||
const sessionsPath = "data/sessions.json";
|
||||
const nextSessionIdPath = "data/next-session-id.json";
|
||||
|
||||
async function remove(path: string) {
|
||||
try {
|
||||
await unlink(path);
|
||||
} catch (err: any) {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteDatbase() {
|
||||
await remove(schedulePath);
|
||||
await remove(subscriptionsPath);
|
||||
await remove(accountsPath);
|
||||
await remove(sessionsPath);
|
||||
}
|
||||
|
||||
async function readJson<T>(filePath: string, fallback: T) {
|
||||
let data: T extends () => infer R ? R : T;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue