forked from UKSOURCE/cms.lams
34 lines
962 B
JavaScript
34 lines
962 B
JavaScript
require("dotenv").config();
|
|
const fs = require("fs").promises;
|
|
const path = require("path");
|
|
const connectDB = require("../config/database");
|
|
const RequestInfo = require("../models/requestInfo");
|
|
const mongoose = require("mongoose");
|
|
|
|
/**
|
|
* Migration: Request Info page content (slug: request-info)
|
|
* Reads data/request-info.json and upserts into MongoDB.
|
|
* Idempotent — safe to re-run.
|
|
*/
|
|
async function migrate() {
|
|
try {
|
|
await connectDB();
|
|
const jsonPath = path.join(__dirname, "../data/request-info.json");
|
|
const raw = await fs.readFile(jsonPath, "utf8");
|
|
const data = JSON.parse(raw);
|
|
await RequestInfo.migrateFromJson(data);
|
|
console.log("Request Info migration completed successfully");
|
|
await mongoose.disconnect();
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error("Request Info migration error:", error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
if (require.main === module) {
|
|
migrate();
|
|
}
|
|
|
|
module.exports = { migrate };
|