forked from UKSOURCE/cms.lams
Adding backend of Student Support, Contact, Request
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
require("dotenv").config();
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const connectDB = require("../config/database");
|
||||
const Contact = require("../models/contact");
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
/**
|
||||
* Migration: Contact page content (slug: contact)
|
||||
* Reads data/contact.json and upserts into MongoDB.
|
||||
* Idempotent — safe to re-run.
|
||||
*/
|
||||
async function migrate() {
|
||||
try {
|
||||
await connectDB();
|
||||
const jsonPath = path.join(__dirname, "../data/contact.json");
|
||||
const raw = await fs.readFile(jsonPath, "utf8");
|
||||
const data = JSON.parse(raw);
|
||||
await Contact.migrateFromJson(data);
|
||||
console.log("Contact migration completed successfully");
|
||||
await mongoose.disconnect();
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
console.error("Contact migration error:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
migrate();
|
||||
}
|
||||
|
||||
module.exports = { migrate };
|
||||
Reference in New Issue
Block a user