-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathseed.ts
More file actions
126 lines (116 loc) · 3.3 KB
/
seed.ts
File metadata and controls
126 lines (116 loc) · 3.3 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// prisma/seed.ts
//
// Idempotent seed script for local development. Run from the repo root:
//
// pnpm exec tsx prisma/seed.ts # tsx, if installed
// pnpm exec ts-node prisma/seed.ts # ts-node fallback
//
// Or wire it into Prisma's seeding hook by adding to package.json:
//
// "prisma": {
// "schema": "./prisma/schema",
// "seed": "ts-node prisma/seed.ts"
// }
//
// See `docs/contributor-seed.md` for the full setup workflow.
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcrypt';
const prisma = new PrismaClient();
interface SeedUser {
email: string;
firstName: string;
lastName: string;
handle: string;
displayName: string;
bio: string;
walletAddress: string;
isVerified: boolean;
}
const SEED_USERS: SeedUser[] = [
{
email: 'alice.creator@example.test',
firstName: 'Alice',
lastName: 'Example',
handle: 'alice',
displayName: 'Alice Example',
bio: 'Verified creator for local development.',
walletAddress:
'GA7XLM00000000000000000000000000000000000000000000000ALICE',
isVerified: true,
},
{
email: 'bob.creator@example.test',
firstName: 'Bob',
lastName: 'Example',
handle: 'bob',
displayName: 'Bob Example',
bio: 'Unverified creator for local development.',
walletAddress:
'GA7XLM000000000000000000000000000000000000000000000000BOB00',
isVerified: false,
},
{
email: 'charlie.fan@example.test',
firstName: 'Charlie',
lastName: 'Fan',
handle: 'charlie',
displayName: 'Charlie Fan',
bio: 'Fan/holder account for ownership-check testing.',
walletAddress:
'GA7XLM0000000000000000000000000000000000000000000000CHARLIE',
isVerified: false,
},
];
async function seed() {
const passwordHash = await bcrypt.hash('localdev-password-1', 10);
for (const user of SEED_USERS) {
const upsertedUser = await prisma.user.upsert({
where: { email: user.email },
create: {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
passwordHash,
emailVerified: true,
emailVerifiedAt: new Date(),
},
update: {
firstName: user.firstName,
lastName: user.lastName,
},
});
await prisma.stellarWallet.upsert({
where: { userId: upsertedUser.id },
create: {
userId: upsertedUser.id,
address: user.walletAddress,
},
update: {
address: user.walletAddress,
},
});
await prisma.creatorProfile.upsert({
where: { userId: upsertedUser.id },
create: {
userId: upsertedUser.id,
handle: user.handle,
displayName: user.displayName,
bio: user.bio,
isVerified: user.isVerified,
},
update: {
handle: user.handle,
displayName: user.displayName,
bio: user.bio,
isVerified: user.isVerified,
},
});
console.log(`✓ seeded ${user.email} (${user.handle})`);
}
}
seed()
.catch(error => {
console.error('seed failed:', error);
process.exit(1);
})
.finally(() => prisma.$disconnect());