-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.ts
More file actions
34 lines (27 loc) · 804 Bytes
/
seed.ts
File metadata and controls
34 lines (27 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import mongoose from "mongoose";
import * as dotenv from "dotenv";
import path from "path";
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") });
const MONGODB_URI = process.env.MONGODB_URI;
const UserSchema = new mongoose.Schema({
name: String,
email: { type: String, unique: true },
role: String,
moduleRoles: Array,
});
const User = mongoose.models.User || mongoose.model("User", UserSchema);
async function seed() {
await mongoose.connect(MONGODB_URI!);
const devUser = {
name: "Coding Club IITG",
email: "codingclub@iitg.ac.in",
role: "Secretary",
moduleRoles: [],
};
await User.findOneAndUpdate({ email: devUser.email }, devUser, {
upsert: true,
});
console.log("✅ Seeded dev user:", devUser.email);
mongoose.disconnect();
}
seed();