1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-11 02:10:14 +01:00
pingvin-share/backend/prisma/seed/config.seed.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

import { PrismaClient } from "@prisma/client";
2022-12-01 23:07:49 +01:00
import configVariables from "../../src/configVariables";
const prisma = new PrismaClient();
async function main() {
for (const variable of configVariables) {
const existingConfigVariable = await prisma.config.findUnique({
where: { key: variable.key },
});
// Create a new config variable if it doesn't exist
if (!existingConfigVariable) {
await prisma.config.create({
data: variable,
});
}
}
// Delete the config variable if it doesn't exist anymore
const configVariablesFromDatabase = await prisma.config.findMany();
for (const configVariableFromDatabase of configVariablesFromDatabase) {
if (!configVariables.find((v) => v.key == configVariableFromDatabase.key)) {
await prisma.config.delete({
where: { key: configVariableFromDatabase.key },
});
}
}
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});