api/firstRun.post: properly initialize database using @prisma/migrate
All checks were successful
Build dev / build (push) Successful in 1m2s

instead of executing the command,
which was not available in the build
now we use the proper library to initialize the database.
This commit is contained in:
Wroclaw 2023-11-09 23:52:56 +01:00
parent 1d8220d92c
commit 10ff342991
3 changed files with 2694 additions and 293 deletions

2966
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,7 @@
},
"dependencies": {
"@prisma/client": "5.5.2",
"@prisma/migrate": "^5.5.2",
"mysql2": "^3.2.3"
}
}

View file

@ -1,5 +1,8 @@
import { execSync } from "node:child_process";
import url from "node:url";
import path from "node:path";
import { defineEventHandler, setResponseStatus, readBody } from "h3";
// @ts-expect-error
import { DbPush } from "@prisma/migrate";
import { database } from "../utils/database";
import { isFirstRun } from "./firstRun.get";
@ -23,7 +26,20 @@ export default defineEventHandler(async (e) => {
const email = body.email;
if (typeof email !== "string") throw createError({ message: "email is not string", statusCode: 400 });
execSync("npx prisma db push --force-reset");
const dbPushParam = [
"--force-reset",
"--skip-generate",
];
if (!import.meta.dev ?? true) {
const mainPath = path.dirname(url.fileURLToPath(import.meta.url));
dbPushParam.push(
"--schema",
`${mainPath}/node_modules/.prisma/client/schema.prisma`,
);
}
await DbPush.new().parse(dbPushParam);
await database.user.create({
data: {
id: new Snowflake().state,