Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 10s
Build & Deploy / 🧪 QA (push) Failing after 2m24s
Build & Deploy / 🏗️ Build (push) Failing after 3m40s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 3s
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { getPayload } from "payload";
|
|
import configPromise from "./payload.config";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
async function run() {
|
|
try {
|
|
const payload = await getPayload({ config: configPromise });
|
|
console.log("Payload initialized.");
|
|
|
|
const docsDir = path.resolve(process.cwd(), "docs");
|
|
|
|
if (!fs.existsSync(docsDir)) {
|
|
console.log(`Docs directory not found at ${docsDir}`);
|
|
process.exit(0);
|
|
}
|
|
|
|
const files = fs.readdirSync(docsDir);
|
|
let count = 0;
|
|
|
|
for (const file of files) {
|
|
if (file.endsWith(".md")) {
|
|
const content = fs.readFileSync(path.join(docsDir, file), "utf8");
|
|
|
|
// Check if already exists
|
|
const existing = await payload.find({
|
|
collection: "context-files",
|
|
where: { filename: { equals: file } },
|
|
});
|
|
|
|
if (existing.totalDocs === 0) {
|
|
await payload.create({
|
|
collection: "context-files",
|
|
data: {
|
|
filename: file,
|
|
content: content,
|
|
},
|
|
});
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(
|
|
`Migration successful! Added ${count} new context files to the database.`,
|
|
);
|
|
process.exit(0);
|
|
} catch (e) {
|
|
console.error("Migration failed:", e);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
run();
|