-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
/
Copy pathseed-companies.ts
37 lines (32 loc) · 886 Bytes
/
seed-companies.ts
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
35
36
37
import * as fs from 'fs';
const { PrismaClient } = require('@prisma/client');
const { parse } = require('csv-parse/sync');
const prisma = new PrismaClient();
async function main() {
console.log('Seeding started...');
const file = fs.readFileSync('prisma/companies.csv');
const companies = parse(file, {
columns: true,
skip_empty_lines: true,
});
console.info('Seeding companies');
await prisma.company.createMany({
data: companies.map((company) => ({
name: company.name,
slug: company.slug,
description: !!company.description ? company.description : undefined,
website: company.website,
logoUrl: company.logoUrl,
})),
skipDuplicates: true,
});
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});