Skip to content

Commit

Permalink
fix: prisma client generation sporadically failling (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Mar 9, 2024
1 parent 095e281 commit 1ec9d67
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { dirname, fromFileUrl, isAbsolute, relative, resolve } from "https://deno.land/std@0.208.0/path/mod.ts";
export { copy, emptyDir, exists } from "https://deno.land/std@0.208.0/fs/mod.ts";
export { copy, emptyDir, exists, move } from "https://deno.land/std@0.208.0/fs/mod.ts";
export { parse, stringify } from "https://deno.land/std@0.208.0/yaml/mod.ts";
export { assert, assertEquals, assertExists } from "https://deno.land/std@0.208.0/assert/mod.ts";

Expand Down
5 changes: 4 additions & 1 deletion src/migrate/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ export async function generateClient(
);

// Copy to module
const dstDir = resolve(module.path, "_gen", "prisma");
const dstDir = resolve(module.path, "_gen", "prisma", "client", "js");
await emptyDir(dstDir);
await copy(generatedClientDir, dstDir, { overwrite: true });

// HACK: Remove the generated client dir to work around a bug in the Prisma CLI
await emptyDir(generatedClientDir);
},
);
}
3 changes: 1 addition & 2 deletions src/migrate/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export async function forEachPrismaSchema(
const generatedClientDir = resolve(
prismaDir,
"client",
"js",
);

// Copy db directory
Expand All @@ -103,7 +102,7 @@ export async function forEachPrismaSchema(
// Generated by Open Game Backend
generator client {
provider = "prisma-client-js"
output = "/prisma/client/js"
output = "/prisma/client"
previewFeatures = ["driverAdapters"]
}
`;
Expand Down
9 changes: 3 additions & 6 deletions src/utils/postgres_daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const POSTGRES_STATE = {

export async function ensurePostgresRunning(_project: Project) {
if (POSTGRES_STATE.running) return;
POSTGRES_STATE.running = true;

console.log("Starting Postgres server...");

Expand Down Expand Up @@ -78,16 +79,12 @@ export async function ensurePostgresRunning(_project: Project) {
while (true) {
const checkOutput = await new Deno.Command("docker", {
args: ["exec", CONTAINER_NAME, "pg_isready"],
stdout: "inherit",
stderr: "inherit",
}).output();
if (checkOutput.success) break;
await new Promise((r) => setTimeout(r, 500));
}

console.log("Ready");

await new Promise((r) => setTimeout(r, 1000));

console.log("Sleeping");

POSTGRES_STATE.running = true;
}
38 changes: 19 additions & 19 deletions tests/basic/deno.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"lint": {
"include": [
"src/"
],
"exclude": [
"tests/"
],
"rules": {
"exclude": [
"no-empty-interface",
"no-explicit-any",
"require-await"
]
}
},
"fmt": {
"useTabs": true
}
}
"lint": {
"include": [
"src/"
],
"exclude": [
"tests/"
],
"rules": {
"exclude": [
"no-empty-interface",
"no-explicit-any",
"require-await"
]
}
},
"fmt": {
"useTabs": true
}
}

0 comments on commit 1ec9d67

Please sign in to comment.