-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.ts
93 lines (84 loc) · 1.92 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { PrismaClient, Prisma } from "@prisma/client";
import { ACCOUNT_IDS, LEDGER_IDS } from "../src/constants/dataBase";
const prisma = new PrismaClient();
const userData: Prisma.UserCreateInput[] = [
{
name: "David",
email: "[email protected]",
},
{
name: "Nilu",
email: "[email protected]",
},
{
name: "Cristian",
email: "[email protected]",
},
];
const ledgerData: Prisma.LedgerCreateInput[] = [
{
id: LEDGER_IDS.usd,
description: "USD Ledger",
},
{
id: LEDGER_IDS.token,
description: "TOKEN Ledger",
},
];
const accountData: Prisma.AccountCreateInput[] = [
{
id: ACCOUNT_IDS.tokensInventory,
type: "ASSET",
description: "Represents Tokens inventory for an user",
},
{
id: ACCOUNT_IDS.tokensEarned,
type: "INCOME",
description: "Represents the income of tokens",
},
{
id: ACCOUNT_IDS.tokensExchanged,
type: "EXPENSE",
description: "Represents the Tokens exchanged by money",
},
{
id: ACCOUNT_IDS.usdInventory,
type: "ASSET",
description: "Represents USDs inventory for an user",
},
{
id: ACCOUNT_IDS.usdEarned,
type: "INCOME",
description: "Represents the income of USD",
},
];
async function main() {
console.log(`Start seeding ...`);
for (const u of userData) {
const user = await prisma.user.create({
data: u,
});
console.log(`Created user with id: ${user.id}`);
}
for (const l of ledgerData) {
const ledger = await prisma.ledger.create({
data: l,
});
console.log(`Created ledger with id: ${ledger.id}`);
}
for (const a of accountData) {
const account = await prisma.account.create({
data: a,
});
console.log(`Created account with id: ${account.id}`);
}
console.log(`Seeding finished.`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});