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 };