more advanced seed ts

This commit is contained in:
Kalle (Sendou)
2020-10-18 02:16:46 +03:00
parent e7088240e4
commit 2c64aac14d

View File

@@ -1,8 +1,30 @@
import { PrismaClient } from "@prisma/client";
const fs = require("fs");
const path = require("path");
const prisma = new PrismaClient();
const main = async () => {
fs.readFile(path.join(__dirname, "/.env"), function (err: any, data: any) {
if (!err) {
for (const line of data.toString().split("\n")) {
if (!line.startsWith("DATABASE_URL=")) {
continue;
}
if (!line.includes("localhost:")) {
console.error("trying to seed a database not in localhost");
process.exit(1);
}
}
} else {
console.error(err);
process.exit(1);
}
});
await prisma.profile.deleteMany({});
await prisma.user.deleteMany({});
await prisma.user.create({
data: {
username: "N-ZAP",
@@ -22,6 +44,7 @@ const main = async () => {
"Luna Blaster",
"N-ZAP '89",
],
twitterName: "nintendovs",
twitchName: "nintendo",
youtubeId: "UCAtobAxsQcACwDZCSH9uJfA",
},