@opprs/db-prisma 2.2.0 → 2.2.1-canary.3bbfda2
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/package.json +3 -3
- package/prisma/seed.ts +45 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opprs/db-prisma",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1-canary.3bbfda2",
|
|
4
4
|
"description": "Database backend for OPPR (Open Pinball Player Ranking System) using Prisma and PostgreSQL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oppr",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"vitest": "^4.0.16"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@opprs/core": "^
|
|
59
|
+
"@opprs/core": "^2.2.1-canary.3bbfda2"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
62
|
+
"node": ">=20.9.0"
|
|
63
63
|
},
|
|
64
64
|
"prisma": {
|
|
65
65
|
"seed": "tsx prisma/seed.ts"
|
package/prisma/seed.ts
CHANGED
|
@@ -90,27 +90,59 @@ async function main() {
|
|
|
90
90
|
|
|
91
91
|
console.log(`✓ Created ${await prisma.player.count()} players`);
|
|
92
92
|
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
const
|
|
93
|
+
// Seed users from environment variables (development only)
|
|
94
|
+
const seedAdminEmail = process.env.SEED_ADMIN_EMAIL;
|
|
95
|
+
const seedAdminPassword = process.env.SEED_ADMIN_PASSWORD;
|
|
96
|
+
const seedTestEmail = process.env.SEED_TEST_EMAIL;
|
|
97
|
+
const seedTestPassword = process.env.SEED_TEST_PASSWORD;
|
|
98
|
+
|
|
99
|
+
// Create admin user if credentials provided
|
|
100
|
+
if (seedAdminEmail && seedAdminPassword) {
|
|
101
|
+
console.log('Creating admin user...');
|
|
102
|
+
const adminPasswordHash = await bcrypt.hash(seedAdminPassword, BCRYPT_SALT_ROUNDS);
|
|
103
|
+
await prisma.user.upsert({
|
|
104
|
+
where: { email: seedAdminEmail },
|
|
105
|
+
update: { passwordHash: adminPasswordHash, role: 'ADMIN' },
|
|
106
|
+
create: { email: seedAdminEmail, passwordHash: adminPasswordHash, role: 'ADMIN' },
|
|
107
|
+
});
|
|
108
|
+
console.log(`✓ Created admin user (${seedAdminEmail})`);
|
|
109
|
+
} else {
|
|
110
|
+
console.log('⏭ Skipping admin user (SEED_ADMIN_EMAIL/SEED_ADMIN_PASSWORD not set)');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Create test user if credentials provided (linked to Alice Champion)
|
|
114
|
+
if (seedTestEmail && seedTestPassword) {
|
|
115
|
+
console.log('Creating test user...');
|
|
116
|
+
const testPasswordHash = await bcrypt.hash(seedTestPassword, BCRYPT_SALT_ROUNDS);
|
|
117
|
+
await prisma.user.upsert({
|
|
118
|
+
where: { email: seedTestEmail },
|
|
119
|
+
update: { passwordHash: testPasswordHash, role: 'USER', playerId: player1.id },
|
|
120
|
+
create: { email: seedTestEmail, passwordHash: testPasswordHash, role: 'USER', playerId: player1.id },
|
|
121
|
+
});
|
|
122
|
+
console.log(`✓ Created test user (${seedTestEmail}) linked to ${player1.name}`);
|
|
123
|
+
} else {
|
|
124
|
+
console.log('⏭ Skipping test user (SEED_TEST_EMAIL/SEED_TEST_PASSWORD not set)');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Create admin user
|
|
128
|
+
console.log('Creating admin user...');
|
|
129
|
+
const adminPassword = 'AdminPassword123!';
|
|
130
|
+
const adminPasswordHash = await bcrypt.hash(adminPassword, BCRYPT_SALT_ROUNDS);
|
|
97
131
|
|
|
98
132
|
await prisma.user.upsert({
|
|
99
|
-
where: { email: '
|
|
133
|
+
where: { email: 'admin@example.com' },
|
|
100
134
|
update: {
|
|
101
|
-
passwordHash,
|
|
102
|
-
role: '
|
|
103
|
-
playerId: player1.id,
|
|
135
|
+
passwordHash: adminPasswordHash,
|
|
136
|
+
role: 'ADMIN',
|
|
104
137
|
},
|
|
105
138
|
create: {
|
|
106
|
-
email: '
|
|
107
|
-
passwordHash,
|
|
108
|
-
role: '
|
|
109
|
-
playerId: player1.id,
|
|
139
|
+
email: 'admin@example.com',
|
|
140
|
+
passwordHash: adminPasswordHash,
|
|
141
|
+
role: 'ADMIN',
|
|
110
142
|
},
|
|
111
143
|
});
|
|
112
144
|
|
|
113
|
-
console.log(`✓ Created
|
|
145
|
+
console.log(`✓ Created admin user (admin@example.com / ${adminPassword})`);
|
|
114
146
|
|
|
115
147
|
// Create sample tournaments (using upsert for idempotency)
|
|
116
148
|
console.log('Creating tournaments...');
|