-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
202afd7
commit fc1a8ff
Showing
4 changed files
with
133 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +0,0 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = "" | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { z } from "zod"; | ||
import { exec } from "child_process"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import util from "util"; | ||
|
||
const execPromise = util.promisify(exec); | ||
|
||
|
||
const DbUrlSchema = z.object({ | ||
dbUrl: z.string(), | ||
dbType: z.string() | ||
}); | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const body = await req.json(); | ||
const parsedBody = DbUrlSchema.safeParse(body); | ||
|
||
if (!parsedBody.success) { | ||
return NextResponse.json({ error: "Invalid request body" }, { status: 400 }); | ||
} | ||
|
||
const { dbUrl,dbType } = parsedBody.data; | ||
|
||
// const schemaPath = path.join(process.cwd(), "prisma", "schema.prisma"); | ||
|
||
// const schemaContent = ` | ||
// generator client { | ||
// provider = "prisma-client-js" | ||
// } | ||
|
||
// datasource db { | ||
// provider = "${dbType}" | ||
// url = "${dbUrl}" | ||
// } | ||
|
||
// `; | ||
|
||
// fs.writeFileSync(schemaPath, schemaContent); | ||
|
||
const { stdout, stderr } = await execPromise("npx prisma db push"); | ||
if (stderr) { | ||
console.error(stderr); | ||
return NextResponse.json( | ||
{ error: "Failed to push database schema" }, | ||
{ status: 500 } | ||
); | ||
} | ||
// return NextResponse.json({message:schemaPath}, { status: 200 }); | ||
|
||
return NextResponse.json({ | ||
message: "Schema updated and database pushed successfully", | ||
output: stdout, | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
return NextResponse.json( | ||
{ error: "Internal Server Error" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters