-
Notifications
You must be signed in to change notification settings - Fork 6
/
seed.ts
68 lines (63 loc) · 2.72 KB
/
seed.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
Cause_areas,
Data_owner,
Distribution_cause_area_organizations,
Distribution_cause_areas,
Distributions,
Donations,
Donors,
Organizations,
Payment,
Payment_intent,
PrismaClient,
Referral_types,
Tax_unit,
} from "@prisma/client";
import fs from "fs";
import path from "path";
const prisma = new PrismaClient();
const basePath: string = path.resolve(__dirname, "./fakedata/json/");
async function main() {
const fakeDonors: Donors[] = readAndParseJsonFile("/fakeDonors.json");
const fakePayments: Payment[] = readAndParseJsonFile("/fakePayments.json");
const fakeCauseAreas: Cause_areas[] = readAndParseJsonFile("/fakeCauseAreas.json");
const fakeOrganizations: Organizations[] = readAndParseJsonFile("/fakeOrganizations.json");
const fakeTaxUnits: Tax_unit[] = readAndParseJsonFile("/fakeTaxUnits.json");
const fakeDonations: Donations[] = readAndParseJsonFile("/fakeDonations.json");
const fakePaymentIntents: Payment_intent[] = readAndParseJsonFile("/fakePaymentIntents.json");
const fakeDistributions: Distributions[] = readAndParseJsonFile("/fakeDistributions.json");
const fakeDistributionCauseAreas: Distribution_cause_areas[] = readAndParseJsonFile(
"/fakeDistributionCauseAreas.json",
);
const fakeDistributionCauseAreaOrganizations: Distribution_cause_area_organizations[] =
readAndParseJsonFile("/fakeDistributionCauseAreaOrganizations.json");
const fakeReferralTypes: Referral_types[] = readAndParseJsonFile("/fakeReferralTypes.json");
const fakeDataOwner: Data_owner[] = readAndParseJsonFile("/fakeDataOwner.json");
await prisma.data_owner.createMany({ data: fakeDataOwner });
await prisma.payment.createMany({ data: fakePayments });
await prisma.donors.createMany({ data: fakeDonors });
await prisma.cause_areas.createMany({ data: fakeCauseAreas });
await prisma.organizations.createMany({ data: fakeOrganizations });
await prisma.tax_unit.createMany({ data: fakeTaxUnits });
await prisma.distributions.createMany({ data: fakeDistributions });
await prisma.distribution_cause_areas.createMany({ data: fakeDistributionCauseAreas });
await prisma.distribution_cause_area_organizations.createMany({
data: fakeDistributionCauseAreaOrganizations,
});
await prisma.donations.createMany({ data: fakeDonations });
await prisma.payment_intent.createMany({ data: fakePaymentIntents });
await prisma.referral_types.createMany({ data: fakeReferralTypes });
}
function readAndParseJsonFile(path: string) {
const jsonFile: string = fs.readFileSync(basePath + path, "utf8");
return JSON.parse(jsonFile);
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});