diff --git a/bun.lockb b/bun.lockb index a576987..5ac24ee 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/pkgs/api/_deploy.ts b/pkgs/api/_deploy.ts index 0caa466..0d959a3 100644 --- a/pkgs/api/_deploy.ts +++ b/pkgs/api/_deploy.ts @@ -1,6 +1,11 @@ import { $ } from "execa"; import * as fs from "fs"; -import { dirAsync, readAsync, removeAsync, writeAsync } from "fs-jetpack"; +import { + dirAsync, + readAsync, + removeAsync, + writeAsync +} from "fs-jetpack"; import { apiContext } from "service-srv"; import { deploy } from "utils/deploy"; import { dir } from "utils/dir"; @@ -74,6 +79,7 @@ export const _ = { DATABASE_URL: action.url, }); await Bun.write(dir(".env"), env); + await Bun.write(dir("app/db/.env"), env); } return "ok"; case "db-gen": @@ -88,7 +94,7 @@ export const _ = { break; case "db-pull": { - const env = await readAsync(dir("app/db/.env")); + let env = await readAsync(dir("app/db/.env")); if (env) { const ENV = parseEnv(env); if (typeof ENV.DATABASE_URL === "string") { @@ -110,7 +116,7 @@ export const _ = { try { await Bun.write( dir("app/db/.env"), - `DATABASE_URL=${process.env.DATABASE_URL}` + `DATABASE_URL=${ENV.DATABASE_URL}` ); await $({ cwd: dir("app/db") })`bun install`; await $({ cwd: dir("app/db") })`bun prisma db pull --force`; diff --git a/pkgs/prod.ts b/pkgs/prod.ts index 32aeaff..e17e876 100644 --- a/pkgs/prod.ts +++ b/pkgs/prod.ts @@ -36,7 +36,7 @@ const main = { console.log("Process Manager running at port:", port); if (process.env.DATABASE_URL) { - if (!(await existsAsync(dir("node_modules/.prisma")))) { + if (!(await existsAsync(dir("node_modules/.prisma"))) && process.env.DATABASE_URL) { try { await Bun.write( dir("app/db/.env"), diff --git a/pkgs/utils/query.ts b/pkgs/utils/query.ts index 2391081..91eee7b 100644 --- a/pkgs/utils/query.ts +++ b/pkgs/utils/query.ts @@ -1,7 +1,5 @@ import { Property, createPrismaSchemaBuilder } from "@mrleebo/prisma-ast"; import { readAsync } from "fs-jetpack"; -//@ts-ignore -import { Prisma } from "../../app/db/db"; import { dir } from "./dir"; import { gunzipAsync } from "./gzip"; @@ -319,6 +317,7 @@ export const execQuery = async (args: DBArg, prisma: any) => { if (Array.isArray(json)) { const q = json.shift(); + const Prisma = (await import("../../app/db/db")).Prisma; return await tableInstance.bind(prisma)(Prisma.sql(q, ...json)); }