@opprs/db-prisma 2.2.0 → 2.2.1-canary.2ae1e14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/prisma/seed.ts CHANGED
@@ -13,6 +13,7 @@ async function main() {
13
13
  const playerData = [
14
14
  {
15
15
  externalId: 'player-1',
16
+ playerNumber: 10001,
16
17
  name: 'Alice Champion',
17
18
  rating: 1850,
18
19
  ratingDeviation: 50,
@@ -22,6 +23,7 @@ async function main() {
22
23
  },
23
24
  {
24
25
  externalId: 'player-2',
26
+ playerNumber: 10002,
25
27
  name: 'Bob Wizard',
26
28
  rating: 1750,
27
29
  ratingDeviation: 60,
@@ -31,6 +33,7 @@ async function main() {
31
33
  },
32
34
  {
33
35
  externalId: 'player-3',
36
+ playerNumber: 10003,
34
37
  name: 'Charlie Flipper',
35
38
  rating: 1650,
36
39
  ratingDeviation: 75,
@@ -40,6 +43,7 @@ async function main() {
40
43
  },
41
44
  {
42
45
  externalId: 'player-4',
46
+ playerNumber: 10004,
43
47
  name: 'Diana Tilt',
44
48
  rating: 1550,
45
49
  ratingDeviation: 100,
@@ -49,6 +53,7 @@ async function main() {
49
53
  },
50
54
  {
51
55
  externalId: 'player-5',
56
+ playerNumber: 10005,
52
57
  name: 'Eve Plunger',
53
58
  rating: 1300,
54
59
  ratingDeviation: 150,
@@ -90,27 +95,117 @@ async function main() {
90
95
 
91
96
  console.log(`✓ Created ${await prisma.player.count()} players`);
92
97
 
93
- // Create test user for e2e tests (linked to Alice Champion)
94
- console.log('Creating test user...');
95
- const testPassword = 'TestPassword123!';
96
- const passwordHash = await bcrypt.hash(testPassword, BCRYPT_SALT_ROUNDS);
98
+ // Seed users from environment variables (development only)
99
+ const seedAdminEmail = process.env.SEED_ADMIN_EMAIL;
100
+ const seedAdminPassword = process.env.SEED_ADMIN_PASSWORD;
101
+ const seedTestEmail = process.env.SEED_TEST_EMAIL;
102
+ const seedTestPassword = process.env.SEED_TEST_PASSWORD;
103
+
104
+ // Create admin user if credentials provided
105
+ if (seedAdminEmail && seedAdminPassword) {
106
+ console.log('Creating admin user...');
107
+ const adminPasswordHash = await bcrypt.hash(seedAdminPassword, BCRYPT_SALT_ROUNDS);
108
+ await prisma.user.upsert({
109
+ where: { email: seedAdminEmail },
110
+ update: { passwordHash: adminPasswordHash, role: 'ADMIN' },
111
+ create: { email: seedAdminEmail, passwordHash: adminPasswordHash, role: 'ADMIN' },
112
+ });
113
+ console.log(`✓ Created admin user (${seedAdminEmail})`);
114
+ } else {
115
+ console.log('⏭ Skipping admin user (SEED_ADMIN_EMAIL/SEED_ADMIN_PASSWORD not set)');
116
+ }
117
+
118
+ // Create test user if credentials provided (linked to Alice Champion)
119
+ if (seedTestEmail && seedTestPassword) {
120
+ console.log('Creating test user...');
121
+ const testPasswordHash = await bcrypt.hash(seedTestPassword, BCRYPT_SALT_ROUNDS);
122
+ await prisma.user.upsert({
123
+ where: { email: seedTestEmail },
124
+ update: { passwordHash: testPasswordHash, role: 'USER', playerId: player1.id },
125
+ create: { email: seedTestEmail, passwordHash: testPasswordHash, role: 'USER', playerId: player1.id },
126
+ });
127
+ console.log(`✓ Created test user (${seedTestEmail}) linked to ${player1.name}`);
128
+ } else {
129
+ console.log('⏭ Skipping test user (SEED_TEST_EMAIL/SEED_TEST_PASSWORD not set)');
130
+ }
131
+
132
+ // Create admin user
133
+ console.log('Creating admin user...');
134
+ const adminPassword = 'AdminPassword123!';
135
+ const adminPasswordHash = await bcrypt.hash(adminPassword, BCRYPT_SALT_ROUNDS);
97
136
 
98
137
  await prisma.user.upsert({
99
- where: { email: 'e2e-test@example.com' },
138
+ where: { email: 'admin@example.com' },
139
+ update: {
140
+ passwordHash: adminPasswordHash,
141
+ role: 'ADMIN',
142
+ },
143
+ create: {
144
+ email: 'admin@example.com',
145
+ passwordHash: adminPasswordHash,
146
+ role: 'ADMIN',
147
+ },
148
+ });
149
+
150
+ console.log(`✓ Created admin user (admin@example.com / ${adminPassword})`);
151
+
152
+ // Create sample locations (using upsert for idempotency)
153
+ console.log('Creating locations...');
154
+
155
+ const location1 = await prisma.location.upsert({
156
+ where: { externalId: 'location-1' },
157
+ update: {
158
+ name: 'Las Vegas Convention Center',
159
+ city: 'Las Vegas',
160
+ state: 'NV',
161
+ country: 'USA',
162
+ },
163
+ create: {
164
+ externalId: 'location-1',
165
+ name: 'Las Vegas Convention Center',
166
+ city: 'Las Vegas',
167
+ state: 'NV',
168
+ country: 'USA',
169
+ },
170
+ });
171
+
172
+ const location2 = await prisma.location.upsert({
173
+ where: { externalId: 'location-2' },
174
+ update: {
175
+ name: 'Ground Kontrol',
176
+ address: '115 NW 5th Ave',
177
+ city: 'Portland',
178
+ state: 'OR',
179
+ country: 'USA',
180
+ },
181
+ create: {
182
+ externalId: 'location-2',
183
+ name: 'Ground Kontrol',
184
+ address: '115 NW 5th Ave',
185
+ city: 'Portland',
186
+ state: 'OR',
187
+ country: 'USA',
188
+ },
189
+ });
190
+
191
+ const location3 = await prisma.location.upsert({
192
+ where: { externalId: 'location-3' },
100
193
  update: {
101
- passwordHash,
102
- role: 'USER',
103
- playerId: player1.id,
194
+ name: 'Add-a-Ball Amusements',
195
+ city: 'Seattle',
196
+ state: 'WA',
197
+ country: 'USA',
104
198
  },
105
199
  create: {
106
- email: 'e2e-test@example.com',
107
- passwordHash,
108
- role: 'USER',
109
- playerId: player1.id,
200
+ externalId: 'location-3',
201
+ name: 'Add-a-Ball Amusements',
202
+ city: 'Seattle',
203
+ state: 'WA',
204
+ country: 'USA',
110
205
  },
111
206
  });
112
207
 
113
- console.log(`✓ Created test user (e2e-test@example.com / ${testPassword})`);
208
+ console.log(`✓ Created ${await prisma.location.count()} locations`);
114
209
 
115
210
  // Create sample tournaments (using upsert for idempotency)
116
211
  console.log('Creating tournaments...');
@@ -118,7 +213,7 @@ async function main() {
118
213
  const tournament1Data = {
119
214
  externalId: 'tournament-1',
120
215
  name: 'World Pinball Championship 2024',
121
- location: 'Las Vegas, NV',
216
+ locationId: location1.id,
122
217
  date: new Date('2024-03-15'),
123
218
  eventBooster: EventBoosterType.MAJOR,
124
219
  allowsOptOut: false,
@@ -154,7 +249,7 @@ async function main() {
154
249
  const tournament2Data = {
155
250
  externalId: 'tournament-2',
156
251
  name: 'Spring Classics 2024',
157
- location: 'Portland, OR',
252
+ locationId: location2.id,
158
253
  date: new Date('2024-04-20'),
159
254
  eventBooster: EventBoosterType.CERTIFIED,
160
255
  allowsOptOut: true,
@@ -188,7 +283,7 @@ async function main() {
188
283
  const tournament3Data = {
189
284
  externalId: 'tournament-3',
190
285
  name: 'Monthly League Finals',
191
- location: 'Seattle, WA',
286
+ locationId: location3.id,
192
287
  date: new Date('2024-05-10'),
193
288
  eventBooster: EventBoosterType.NONE,
194
289
  allowsOptOut: false,
@@ -391,6 +486,7 @@ async function main() {
391
486
  console.log('Summary:');
392
487
  console.log(` - ${await prisma.player.count()} players`);
393
488
  console.log(` - ${await prisma.user.count()} users`);
489
+ console.log(` - ${await prisma.location.count()} locations`);
394
490
  console.log(` - ${await prisma.tournament.count()} tournaments`);
395
491
  console.log(` - ${await prisma.tournamentResult.count()} tournament results`);
396
492
  }