Skip to content

Commit e349628

Browse files
Seed DB with characters' data if not exists only
1 parent f1c9469 commit e349628

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

prisma/seed/script.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ async function main() {
3333
await transClient.image.deleteMany({});
3434
await transClient.user.deleteMany({});
3535
await transClient.tag.deleteMany({});
36-
await transClient.characterRect.deleteMany({});
3736
await transClient.creation.deleteMany({ where: { isAdmin: true } });
3837

3938
console.log('Seeding the database...');
@@ -144,8 +143,13 @@ async function main() {
144143
}
145144
}
146145

147-
for (const data of characters) {
148-
await transClient.characterRect.create({ data });
146+
const dbCharacterRectCount = await transClient.characterRect.count();
147+
if (dbCharacterRectCount < characters.length) {
148+
console.log('Seeding the database with characters...');
149+
for (const data of characters) {
150+
const { name } = data;
151+
await transClient.characterRect.upsert({ where: { name }, create: data, update: data });
152+
}
149153
}
150154
},
151155
{

0 commit comments

Comments
 (0)