Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/prisma/dump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable no-console */
const { PrismaClient } = require("@prisma/client");
const fs = require("fs");
const path = require("path");

const prisma = new PrismaClient();

async function main() {
const pages = await prisma.page.findMany({
include: {
finalDraft: true,
},
});

const output = {};

for (const page of pages) {
if (!page.finalDraft) {
console.warn(`Skipping "${page.name}" (${page.path}) — no published draft.`);
continue;
}

output[page.path] = page.finalDraft.content;
}

const count = Object.keys(output).length;

if (count === 0) {
console.warn("No published pages found.");
return;
}

const json = JSON.stringify(output, null, 4) + "\n";
const outputPath = process.argv[2];

if (outputPath) {
fs.writeFileSync(path.resolve(outputPath), json, "utf-8");
console.info(`Dumped ${count} page(s) to ${outputPath}`);
} else {
process.stdout.write(json);
}
}

main()
.catch((error) => {
console.error("Failed to dump database", error);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
Loading