feat(cms): robust api based migration endpoint for prod
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 4s
Build & Deploy / 🧪 QA (push) Failing after 31s
Build & Deploy / 🏗️ Build (push) Failing after 2m1s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 4s
Build & Deploy / 🧪 QA (push) Failing after 31s
Build & Deploy / 🏗️ Build (push) Failing after 2m1s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
This commit is contained in:
29
app/api/payload/migrate/route.ts
Normal file
29
app/api/payload/migrate/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getPayload } from "payload";
|
||||
import configPromise from "@payload-config";
|
||||
import { getServerAppServices } from "@/lib/services/create-services.server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const authHeader = req.headers.get("authorization");
|
||||
if (authHeader !== `Bearer ${process.env.PAYLOAD_SECRET}`) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { logger } = getServerAppServices();
|
||||
|
||||
try {
|
||||
logger.info("Starting programmatic Payload migrations...");
|
||||
const payload = await getPayload({ config: configPromise });
|
||||
|
||||
await payload.db.migrate({ forceAcceptWarning: true });
|
||||
|
||||
logger.info("Successfully executed Payload migrations.");
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Migrations executed successfully.",
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error("Failed to run migrations remotely", { error });
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user