lint
This commit is contained in:
parent
7c55fde138
commit
ade5a91ec9
2 changed files with 16 additions and 16 deletions
28
src/db/db.ts
28
src/db/db.ts
|
|
@ -3,25 +3,25 @@ import { PrismaClient } from "@prisma/client";
|
|||
import { execSync } from "node:child_process";
|
||||
|
||||
// ensure db exists
|
||||
if(!fs.existsSync("./data/mydb.sqlite")) {
|
||||
// run bun prisma migrate deploy with child_process
|
||||
console.log("Database not found, creating a new one...");
|
||||
execSync("bun prisma migrate deploy");
|
||||
if (!fs.existsSync("./data/mydb.sqlite")) {
|
||||
// run bun prisma migrate deploy with child_process
|
||||
console.log("Database not found, creating a new one...");
|
||||
execSync("bun prisma migrate deploy");
|
||||
}
|
||||
|
||||
// The db version before we switched to Prisma
|
||||
const prisma = new PrismaClient();
|
||||
const legacyVersion = await prisma.$queryRaw<{ user_version: bigint }[]>`PRAGMA user_version;`;
|
||||
if (legacyVersion[0]?.user_version === 1n) {
|
||||
// close prisma connection
|
||||
await prisma.$disconnect();
|
||||
// Existing legacy database found, needs migration
|
||||
console.log("Legacy database found. Skipping initial migration...");
|
||||
execSync("bun prisma migrate resolve --applied 0_init");
|
||||
// reconnect prisma
|
||||
await prisma.$connect();
|
||||
// set user_version to 2
|
||||
await prisma.$executeRaw`PRAGMA user_version = 2;`;
|
||||
// close prisma connection
|
||||
await prisma.$disconnect();
|
||||
// Existing legacy database found, needs migration
|
||||
console.log("Legacy database found. Skipping initial migration...");
|
||||
execSync("bun prisma migrate resolve --applied 0_init");
|
||||
// reconnect prisma
|
||||
await prisma.$connect();
|
||||
// set user_version to 2
|
||||
await prisma.$executeRaw`PRAGMA user_version = 2;`;
|
||||
}
|
||||
|
||||
console.log("Running database migrations...");
|
||||
|
|
@ -32,7 +32,7 @@ execSync("bun prisma migrate deploy");
|
|||
await prisma.$connect();
|
||||
|
||||
await prisma.$queryRaw`PRAGMA journal_mode = WAL;`.catch((e) => {
|
||||
console.error("Failed to set journal mode to WAL:", e);
|
||||
console.error("Failed to set journal mode to WAL:", e);
|
||||
});
|
||||
|
||||
export default prisma;
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ export const root = new Elysia().use(userService).get(
|
|||
},
|
||||
});
|
||||
|
||||
const { id } = await db.job.findFirst({
|
||||
const { id } = (await db.job.findFirst({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
|
|
@ -106,7 +106,7 @@ export const root = new Elysia().use(userService).get(
|
|||
select: {
|
||||
id: true,
|
||||
},
|
||||
}) as { id: number };
|
||||
})) as { id: number };
|
||||
|
||||
if (!jobId) {
|
||||
return { message: "Cookies should be enabled to use this app." };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue