-
Notifications
You must be signed in to change notification settings - Fork 1
fix: fixed failed push for v7 and improved push/pull speed #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| import { Hono } from "hono"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { writeFile, readFile, unlink } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { spawn } from "child_process"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { writeFile, readFile, rm, mkdir } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { execSync } from "child_process"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const app = new Hono(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| app.post("/", async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||
| const minimalSchema = `generator client { | ||||||||||||||||||||||||||||||||||||||||||||
| const minimalSchema = `generator client { | ||||||||||||||||||||||||||||||||||||||||||||
| provider = "prisma-client" | ||||||||||||||||||||||||||||||||||||||||||||
| output = "../app/generated/client" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -15,74 +13,69 @@ datasource db { | |||||||||||||||||||||||||||||||||||||||||||
| provider = "postgresql" | ||||||||||||||||||||||||||||||||||||||||||||
| }`; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| const connectionString = c.req.header("X-Connection-String"); | ||||||||||||||||||||||||||||||||||||||||||||
| async function createPrismaWorkspace( | ||||||||||||||||||||||||||||||||||||||||||||
| connectionString: string, | ||||||||||||||||||||||||||||||||||||||||||||
| schema: string | ||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<{ workDir: string; schemaPath: string; cleanup: () => Promise<void> }> { | ||||||||||||||||||||||||||||||||||||||||||||
| const timestamp = Date.now(); | ||||||||||||||||||||||||||||||||||||||||||||
| const workDir = `/tmp/prisma-${timestamp}`; | ||||||||||||||||||||||||||||||||||||||||||||
| const schemaPath = `${workDir}/schema.prisma`; | ||||||||||||||||||||||||||||||||||||||||||||
| const configPath = `${workDir}/prisma.config.ts`; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (!connectionString) { | ||||||||||||||||||||||||||||||||||||||||||||
| return c.json( | ||||||||||||||||||||||||||||||||||||||||||||
| { error: "Connection string not provided in headers" }, | ||||||||||||||||||||||||||||||||||||||||||||
| 400 | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| await mkdir(workDir, { recursive: true }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(schemaPath, schema); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const tempDir = "/tmp"; | ||||||||||||||||||||||||||||||||||||||||||||
| const schemaPath = `${tempDir}/schema-${Date.now()}.prisma`; | ||||||||||||||||||||||||||||||||||||||||||||
| const envPath = `${tempDir}/.env-${Date.now()}`; | ||||||||||||||||||||||||||||||||||||||||||||
| const configContent = `import { defineConfig } from "prisma/config"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(envPath, `DATABASE_URL="${connectionString}"`); | ||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(schemaPath, minimalSchema); | ||||||||||||||||||||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||||||||||||||||||||
| schema: "./schema.prisma", | ||||||||||||||||||||||||||||||||||||||||||||
| datasource: { | ||||||||||||||||||||||||||||||||||||||||||||
| url: "${connectionString}", | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same injection vulnerability as in push-force.ts. Apply the same Proposed fix const configContent = `import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "./schema.prisma",
datasource: {
- url: "${connectionString}",
+ url: ${JSON.stringify(connectionString)},
},
});
`;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(configPath, configContent); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||
| workDir, | ||||||||||||||||||||||||||||||||||||||||||||
| schemaPath, | ||||||||||||||||||||||||||||||||||||||||||||
| cleanup: async () => { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| const result = execSync(`npx prisma db pull --schema=${schemaPath}`, { | ||||||||||||||||||||||||||||||||||||||||||||
| env: { | ||||||||||||||||||||||||||||||||||||||||||||
| ...process.env, | ||||||||||||||||||||||||||||||||||||||||||||
| DATABASE_URL: connectionString, | ||||||||||||||||||||||||||||||||||||||||||||
| npm_config_cache: "/tmp/.npm", | ||||||||||||||||||||||||||||||||||||||||||||
| npm_config_prefix: "/tmp/.npm", | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| cwd: process.cwd(), | ||||||||||||||||||||||||||||||||||||||||||||
| encoding: "utf8", | ||||||||||||||||||||||||||||||||||||||||||||
| stdio: "pipe", | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const stdout = result; | ||||||||||||||||||||||||||||||||||||||||||||
| const stderr = ""; | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = | ||||||||||||||||||||||||||||||||||||||||||||
| error instanceof Error ? error.message : String(error); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (errorMessage.includes("The introspected database was empty")) { | ||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||
| schema: minimalSchema, | ||||||||||||||||||||||||||||||||||||||||||||
| message: "Database is empty - showing minimal schema", | ||||||||||||||||||||||||||||||||||||||||||||
| isEmpty: true, | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||
| await rm(workDir, { recursive: true, force: true }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||
| console.error("Cleanup error:", e); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| app.post("/", async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||
| const connectionString = c.req.header("X-Connection-String"); | ||||||||||||||||||||||||||||||||||||||||||||
| if (!connectionString) { | ||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ error: "Connection string not provided in headers" }, 400); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const schemaContent = await readFile(schemaPath, "utf-8"); | ||||||||||||||||||||||||||||||||||||||||||||
| const workspace = await createPrismaWorkspace(connectionString, minimalSchema); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||
| schema: schemaContent, | ||||||||||||||||||||||||||||||||||||||||||||
| message: "Schema pulled successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| await unlink(schemaPath); | ||||||||||||||||||||||||||||||||||||||||||||
| await unlink(envPath); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (cleanupError) { | ||||||||||||||||||||||||||||||||||||||||||||
| console.error("Cleanup error:", cleanupError); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||
| execSync("pnpx prisma db pull", { | ||||||||||||||||||||||||||||||||||||||||||||
| cwd: workspace.workDir, | ||||||||||||||||||||||||||||||||||||||||||||
| encoding: "utf8", | ||||||||||||||||||||||||||||||||||||||||||||
| stdio: "pipe", | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const schemaContent = await readFile(workspace.schemaPath, "utf-8"); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||
| schema: schemaContent, | ||||||||||||||||||||||||||||||||||||||||||||
| message: "Schema pulled successfully", | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = error instanceof Error ? error.message : String(error); | ||||||||||||||||||||||||||||||||||||||||||||
| const message = error instanceof Error ? error.message : String(error); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (errorMessage.includes("The introspected database was empty")) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (message.includes("The introspected database was empty")) { | ||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||
| schema: minimalSchema, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -94,10 +87,12 @@ datasource db { | |||||||||||||||||||||||||||||||||||||||||||
| return c.json( | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| error: "Failed to pull schema", | ||||||||||||||||||||||||||||||||||||||||||||
| details: errorMessage, | ||||||||||||||||||||||||||||||||||||||||||||
| details: message, | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| 500 | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||
| await workspace.cleanup(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,69 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Hono } from "hono"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { writeFile, unlink } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { spawn } from "child_process"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { writeFile, rm, mkdir } from "fs/promises"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { execSync } from "child_process"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const app = new Hono(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| app.post("/", async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = await c.req.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { schema } = body as { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| async function createPrismaWorkspace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| connectionString: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<{ workDir: string; cleanup: () => Promise<void> }> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const timestamp = Date.now(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const workDir = `/tmp/prisma-${timestamp}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const schemaPath = `${workDir}/schema.prisma`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const configPath = `${workDir}/prisma.config.ts`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ error: "Schema is required" }, 400); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await mkdir(workDir, { recursive: true }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const connectionString = c.req.header("X-Connection-String"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(schemaPath, schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!connectionString) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { error: "Connection string not provided in headers" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const configContent = `import { defineConfig } from "prisma/config"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const tempDir = "/tmp"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const schemaPath = `${tempDir}/schema-${Date.now()}.prisma`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const envPath = `${tempDir}/.env-${Date.now()}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(schemaPath, schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(envPath, `DATABASE_URL="${connectionString}"`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default defineConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| schema: "./schema.prisma", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| datasource: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: "${connectionString}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential injection vulnerability in config template. The Proposed fix using JSON.stringify for safe escaping const configContent = `import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "./schema.prisma",
datasource: {
- url: "${connectionString}",
+ url: ${JSON.stringify(connectionString)},
},
});
`;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| await writeFile(configPath, configContent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| workDir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cleanup: async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = execSync( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| `npx prisma db push --schema=${schemaPath} --accept-data-loss --force-reset`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| env: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...process.env, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| DATABASE_URL: connectionString, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| npm_config_cache: "/tmp/.npm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| npm_config_prefix: "/tmp/.npm", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: process.cwd(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: "utf8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: "pipe", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await rm(workDir, { recursive: true, force: true }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Cleanup error:", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Extract This helper is duplicated across 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: "Schema pushed successfully with force reset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await unlink(schemaPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await unlink(envPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (cleanupError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Cleanup error:", cleanupError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| app.post("/", async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const body = await c.req.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { schema } = body as { schema: string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ error: "Schema is required" }, 400); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const connectionString = c.req.header("X-Connection-String"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!connectionString) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ error: "Connection string not provided in headers" }, 400); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| const workspace = await createPrismaWorkspace(connectionString, schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| execSync("pnpx prisma db push --accept-data-loss --force-reset", { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: workspace.workDir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| encoding: "utf8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: "pipe", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: "Schema pushed successfully with force reset", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return c.json( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +74,8 @@ app.post("/", async (c) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| await workspace.cleanup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Server bootstrap may break Vercel serverless deployment.
The
serve()call executes unconditionally when this module is imported. Sincevercelis listed as a dependency and Vercel typically imports theappexport for serverless functions, this will attempt to bind port 4141 in the serverless environment, likely causing deployment failures.Consider conditionally starting the server only in local development:
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents