@compfest-18/oppenheimer-schema 0.0.2-develop.abfb770

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/README.md ADDED
@@ -0,0 +1,540 @@
1
+ # @compfest-18/oppenheimer-schema
2
+
3
+ Private Drizzle ORM schema package for the Oppenheimer database. This package contains all database table definitions, enums, and relationships used by the Oppenheimer NestJS backend.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Consumer Setup](#consumer-setup)
9
+ - [Usage](#usage)
10
+ - [Schema Overview](#schema-overview)
11
+ - [Available Tables](#available-tables)
12
+ - [Enums](#enums)
13
+ - [Type Safety](#type-safety)
14
+ - [Versioning \& Branching](#versioning--branching)
15
+ - [CI/CD Pipeline](#cicd-pipeline)
16
+ - [Development](#development)
17
+ - [Publishing](#publishing)
18
+ - [License](#license)
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ### Prerequisites
25
+
26
+ 1. **GitHub Account** with access to the COMPFEST organization
27
+ 2. **GitHub Personal Access Token (PAT)** with `read:packages` scope
28
+ 3. **Node.js** v18+ and **pnpm** v9+
29
+
30
+ ### Quick Install
31
+
32
+ ```bash
33
+ # Add GitHub Packages registry configuration
34
+ echo "@compfest:registry=https://npm.pkg.github.com" >> .npmrc
35
+ echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrc
36
+
37
+ # Install the schema package
38
+ pnpm add @compfest-18/oppenheimer-schema
39
+ ```
40
+
41
+ ### Manual Setup (Recommended for Production)
42
+
43
+ Create a `.npmrc` file in your project root:
44
+
45
+ ```ini
46
+ # .npmrc
47
+ @compfest:registry=https://npm.pkg.github.com
48
+ //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
49
+ ```
50
+
51
+ Then install:
52
+
53
+ ```bash
54
+ pnpm add @compfest-18/oppenheimer-schema
55
+ ```
56
+
57
+ ### Environment Variable Setup
58
+
59
+ For CI/CD environments, set `GITHUB_TOKEN` as a secret. In GitHub Actions:
60
+
61
+ ```yaml
62
+ - name: Install dependencies
63
+ run: pnpm install
64
+ env:
65
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66
+ ```
67
+
68
+ For local development, create a Classic PAT with `read:packages` scope:
69
+ 1. Go to GitHub → Settings → Developer settings → Personal access tokens
70
+ 2. Generate new token with `read:packages` permission
71
+ 3. Add to your shell profile or use `pnpm add` with `--auth-token` flag
72
+
73
+ ---
74
+
75
+ ## Consumer Setup
76
+
77
+ ### Full Example: Adding Schema to a New Service
78
+
79
+ ```bash
80
+ # 1. Initialize your project
81
+ pnpm init
82
+
83
+ # 2. Add required dependencies
84
+ pnpm add drizzle-orm @compfest-18/oppenheimer-schema
85
+ pnpm add -D drizzle-kit @types/node typescript tsx
86
+
87
+ # 3. Create drizzle.config.ts
88
+ cat > drizzle.config.ts << 'EOF'
89
+ import { defineConfig } from 'drizzle-kit';
90
+
91
+ export default defineConfig({
92
+ schema: './node_modules/@compfest-18/oppenheimer-schema',
93
+ dialect: 'postgresql',
94
+ out: './drizzle',
95
+ dbCredentials: {
96
+ url: process.env.DATABASE_URL!,
97
+ },
98
+ });
99
+ EOF
100
+
101
+ # 4. Generate migrations
102
+ pnpm drizzle-kit generate
103
+
104
+ # 5. Push schema to database (development only!)
105
+ pnpm drizzle-kit push
106
+ ```
107
+
108
+ ### Using Schemas in Your Code
109
+
110
+ ```typescript
111
+ // Import specific tables or enums
112
+ import { users, eventEnum } from '@compfest-18/oppenheimer-schema';
113
+ import { eq, and, desc } from 'drizzle-orm';
114
+
115
+ // Use with your database instance
116
+ const result = await db
117
+ .select()
118
+ .from(users)
119
+ .where(eq(users.id, '123'))
120
+ .orderBy(desc(users.createdAt));
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Usage
126
+
127
+ ### Basic Query Examples
128
+
129
+ ```typescript
130
+ import { db } from './your-db-instance'; // Your Drizzle db instance
131
+ import { users, eventEnum } from '@compfest-18/oppenheimer-schema';
132
+ import { eq, and, inArray } from 'drizzle-orm';
133
+
134
+ // Select single user
135
+ const user = await db.select().from(users).where(eq(users.id, '123'));
136
+
137
+ // Insert new user
138
+ const newUser = await db.insert(users).values({
139
+ id: 'user-456',
140
+ email: 'john@example.com',
141
+ name: 'John Doe',
142
+ referralCode: 'JOHN123',
143
+ });
144
+
145
+ // Update user
146
+ await db.update(users)
147
+ .set({ name: 'Jane Doe' })
148
+ .where(eq(users.id, 'user-456'));
149
+
150
+ // Delete user
151
+ await db.delete(users).where(eq(users.id, 'user-456'));
152
+
153
+ // Batch insert
154
+ await db.insert(users).values([
155
+ { id: 'user-1', email: 'a@test.com', name: 'User A' },
156
+ { id: 'user-2', email: 'b@test.com', name: 'User B' },
157
+ ]);
158
+ ```
159
+
160
+ ### Using Enums
161
+
162
+ ```typescript
163
+ import { eventEnum } from '@compfest-18/oppenheimer-schema';
164
+
165
+ // Enum values are typed
166
+ type EventType = typeof eventEnum.enumValues[number];
167
+
168
+ const eventType: EventType = 'GRAND_LAUNCHING';
169
+ ```
170
+
171
+ ### Relations (if available)
172
+
173
+ ```typescript
174
+ import { users, userProfiles } from '@compfest-18/oppenheimer-schema';
175
+
176
+ const result = await db
177
+ .select()
178
+ .from(users)
179
+ .leftJoin(userProfiles, eq(users.id, userProfiles.userId))
180
+ .where(eq(users.email, 'john@example.com'));
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Schema Overview
186
+
187
+ The Oppenheimer schema covers a comprehensive event management system with the following domains:
188
+
189
+ | Domain | Description |
190
+ |--------|-------------|
191
+ | **Auth** | User authentication and profiles |
192
+ | **Events** | Event definitions and registrations |
193
+ | **Programs** | Academy and competition programs |
194
+ | **Tasks** | Program tasks and submissions |
195
+ | **Games** | Game integrations and rules |
196
+ | **Playground** | Virtual playground system |
197
+ | **Tokens** | Token economy (rewards, expenses) |
198
+ | **Quiz** | Quiz systems (main event and mini) |
199
+ | **Feedback** | Event feedback collection |
200
+ | **Exhibition** | Company exhibition booths |
201
+ | **Job Fair** | Walk-in interview system |
202
+ | **CV Clinic** | CV clinic voucher system |
203
+ | **Voting** | Project voting system |
204
+ | **Booth** | Event booth rewards |
205
+ | **Supermarket** | Virtual supermarket |
206
+ | **Notifications** | Dashboard notifications |
207
+ | **Announcements** | Event announcements |
208
+ | **Content** | Articles and fun facts |
209
+ | **Ads** | Advertisement system |
210
+
211
+ ---
212
+
213
+ ## Available Tables
214
+
215
+ ### Auth Module
216
+
217
+ | Table | Description |
218
+ |-------|-------------|
219
+ | `users` | User accounts synced from SSO (Feynman) |
220
+ | `userProfiles` | Extended user profile information |
221
+
222
+ ### Events Module
223
+
224
+ | Table | Description |
225
+ |-------|-------------|
226
+ | `event` | Event definitions |
227
+ | `eventDate` | Event date/time information |
228
+ | `eventRegistration` | User event registrations |
229
+ | `grandLaunchingRegistration` | Grand launching event registrations |
230
+ | `mainEventRegistration` | Main event registrations |
231
+ | `xcelerateRegistration` | Xcelerate seminar/workshop registrations |
232
+
233
+ ### Programs Module
234
+
235
+ | Table | Description |
236
+ |-------|-------------|
237
+ | `program` | Program definitions |
238
+ | `team` | Team information |
239
+ | `member` | Team members |
240
+ | `programRegistration` | Program registrations |
241
+ | `singleParticipant` | Single participant programs |
242
+
243
+ ### Tasks Module
244
+
245
+ | Table | Description |
246
+ |-------|-------------|
247
+ | `programTask` | Tasks within programs |
248
+ | `programTaskExtraDescription` | Additional task descriptions |
249
+ | `programTaskSubmission` | Task submissions |
250
+ | `xcelerateWorkshopTask` | Xcelerate workshop tasks |
251
+ | `xcelerateWorkshopTaskSubmission` | Workshop task submissions |
252
+
253
+ ### Games Module
254
+
255
+ | Table | Description |
256
+ |-------|-------------|
257
+ | `game` | Game definitions |
258
+ | `gameDeveloper` | Game developers |
259
+ | `gameRule` | Game rules |
260
+ | `userPlayGameHistory` | User game play history |
261
+
262
+ ### Tokens Module
263
+
264
+ | Table | Description |
265
+ |-------|-------------|
266
+ | `playgroundToken` | User token balances |
267
+ | `playgroundExpenseHistory` | Token expense records |
268
+ | `playgroundRewardHistory` | Token reward records |
269
+
270
+ ### Quiz Module
271
+
272
+ | Table | Description |
273
+ |-------|-------------|
274
+ | `miniQuiz` | Mini quiz definitions |
275
+ | `miniQuizQuestion` | Mini quiz questions |
276
+ | `miniQuizAttempt` | Mini quiz attempts |
277
+ | `mainEventMiniQuiz` | Main event mini quiz |
278
+ | `mainEventMiniQuizQuestion` | Main event quiz questions |
279
+ | `mainEventMiniQuizQuestionOption` | Question options |
280
+ | `mainEventMiniQuizAttempt` | Main event quiz attempts |
281
+
282
+ ### And more...
283
+
284
+ See the full list in [`index.ts`](./index.ts)
285
+
286
+ ---
287
+
288
+ ## Enums
289
+
290
+ The package includes the following PostgreSQL enums:
291
+
292
+ ```typescript
293
+ // Event types
294
+ 'GRAND_LAUNCHING', 'XCELERATE_SEMINAR', 'XCELERATE_WORKSHOP',
295
+ 'XCELERATE_FOUNDATION', 'COMPFEST_TALKS', 'MAIN_EVENT_PLAYGROUND',
296
+ 'MAIN_EVENT_SEMINAR', 'MAIN_EVENT_STAGE'
297
+
298
+ // Program codes
299
+ 'LANDING', 'SEA', 'UXA', 'DSA', 'PMA', 'IGI', 'SCPC', 'JCPC',
300
+ 'AIC', 'BIZZIT', 'CTF', 'DAD', 'GAMEJAM', 'MINICASE'
301
+
302
+ // Program types
303
+ 'ACADEMY', 'COMPETITION'
304
+
305
+ // Task types
306
+ 'TEAM', 'PERSONAL'
307
+
308
+ // Submission status
309
+ 'PENDING', 'REJECTED', 'ACCEPTED'
310
+
311
+ // Team status
312
+ 'WAITING_FOR_VERIFICATION', 'VERIFIED', 'VERIFICATION_FAILED'
313
+
314
+ // And many more...
315
+ ```
316
+
317
+ Import enums:
318
+ ```typescript
319
+ import {
320
+ eventEnum,
321
+ programCodeEnum,
322
+ submissionStatusEnum,
323
+ teamStatusEnum,
324
+ } from '@compfest-18/oppenheimer-schema';
325
+ ```
326
+
327
+ ---
328
+
329
+ ## Type Safety
330
+
331
+ This package provides full TypeScript type safety:
332
+
333
+ ### Table Types
334
+
335
+ ```typescript
336
+ import type { InferSelectModel, InferInsertModel } from 'drizzle-orm';
337
+ import { users } from '@compfest-18/oppenheimer-schema';
338
+
339
+ // Extract row type from table
340
+ type User = InferSelectModel<typeof users>;
341
+ type NewUser = InferInsertModel<typeof users>;
342
+
343
+ // Full type safety for queries
344
+ const user: User = {
345
+ id: '123',
346
+ email: 'test@example.com',
347
+ name: 'Test User',
348
+ referralCode: 'TEST123',
349
+ createdAt: new Date(),
350
+ updatedAt: new Date(),
351
+ };
352
+ ```
353
+
354
+ ### Query Builder Type Safety
355
+
356
+ ```typescript
357
+ import { users } from '@compfest-18/oppenheimer-schema';
358
+ import { eq } from 'drizzle-orm';
359
+
360
+ // Drizzle automatically infers return types
361
+ const result = await db
362
+ .select({
363
+ id: users.id,
364
+ email: users.email,
365
+ name: users.name,
366
+ })
367
+ .from(users)
368
+ .where(eq(users.email, 'test@example.com'));
369
+
370
+ // result is typed as { id: string; email: string; name: string }[]
371
+ ```
372
+
373
+ ---
374
+
375
+ ## Versioning & Branching
376
+
377
+ This package uses semantic versioning with branch-specific tags:
378
+
379
+ | Branch | NPM Tag | Example Version |
380
+ |--------|---------|-----------------|
381
+ | `main` | `@latest` | `1.2.3` |
382
+ | `staging` | `@staging` | `1.2.3-staging.a1b2c3d` |
383
+ | `develop` | `@develop` | `1.2.3-develop.f4e5d6` |
384
+
385
+ ### Installing Specific Branch Versions
386
+
387
+ ```bash
388
+ # Install latest stable (from main)
389
+ pnpm add @compfest-18/oppenheimer-schema@latest
390
+
391
+ # Install staging version
392
+ pnpm add @compfest-18/oppenheimer-schema@staging
393
+
394
+ # Install develop version
395
+ pnpm add @compfest-18/oppenheimer-schema@develop
396
+
397
+ # Install specific version
398
+ pnpm add @compfest-18/oppenheimer-schema@1.2.3
399
+ ```
400
+
401
+ ### Version Format
402
+
403
+ - **Production (`main`)**: `MAJOR.MINOR.PATCH` (e.g., `1.0.0`)
404
+ - **Pre-release (`develop`/`staging`)**: `BASEVERSION-BRANCH.SHORT_SHA` (e.g., `1.0.0-develop.a1b2c3d`)
405
+
406
+ ---
407
+
408
+ ## CI/CD Pipeline
409
+
410
+ The schema package is automatically published when:
411
+
412
+ 1. **Trigger**: Push to `develop`, `staging`, or `main` branch
413
+ 2. **Condition**: Schema files changed in `src/infrastructure/database/drizzle/schema/`
414
+ 3. **Action**:
415
+ - Install dependencies
416
+ - Build with tsup
417
+ - Bump version
418
+ - Publish to GitHub Packages with branch tag
419
+
420
+ ### Workflow File
421
+
422
+ See [`.github/workflows/npm-publish.yml`](../../.github/workflows/npm-publish.yml)
423
+
424
+ ### Version Bump Logic
425
+
426
+ ```yaml
427
+ # main branch: Increment patch version
428
+ # Example: 1.0.0 → 1.0.1
429
+
430
+ # develop/staging: Create prerelease version
431
+ # Example: 1.0.0 → 1.0.0-develop.a1b2c3d
432
+ ```
433
+
434
+ ---
435
+
436
+ ## Development
437
+
438
+ ### Building Locally
439
+
440
+ ```bash
441
+ cd src/infrastructure/database/drizzle/schema
442
+
443
+ # Install dependencies
444
+ pnpm install
445
+
446
+ # Build the package
447
+ pnpm build
448
+
449
+ # Run typecheck
450
+ pnpm typecheck
451
+ ```
452
+
453
+ ### Testing Changes Before Publishing
454
+
455
+ 1. Make schema changes
456
+ 2. Build locally: `pnpm build`
457
+ 3. Test in Oppenheimer by adding as local dependency:
458
+ ```bash
459
+ # In Oppenheimer project
460
+ pnpm add file:../oppenheimer/src/infrastructure/database/drizzle/schema
461
+ ```
462
+ 4. Verify types work correctly
463
+ 5. Commit and push to trigger CI/CD
464
+
465
+ ---
466
+
467
+ ## Publishing
468
+
469
+ ### Automatic Publishing
470
+
471
+ The package is automatically published via GitHub Actions when schemas change.
472
+
473
+ ### Manual Publishing (if needed)
474
+
475
+ ```bash
476
+ cd src/infrastructure/database/drizzle/schema
477
+
478
+ # Login to GitHub Packages
479
+ echo "//npm.pkg.github.com/:_authToken=YOUR_TOKEN" > .npmrc
480
+
481
+ # Build and publish
482
+ pnpm build
483
+ pnpm publish --tag develop
484
+ ```
485
+
486
+ ### Pre-release vs Production
487
+
488
+ | Action | Tag | Usage |
489
+ |--------|-----|-------|
490
+ | Merge to `develop` | `@develop` | Testing in development |
491
+ | Merge to `staging` | `@staging` | Testing in staging |
492
+ | Merge to `main` | `@latest` | Production release |
493
+
494
+ ---
495
+
496
+ ## Troubleshooting
497
+
498
+ ### "Cannot find module '@compfest-18/oppenheimer-schema'"
499
+
500
+ 1. Verify `.npmrc` is configured correctly
501
+ 2. Ensure `GITHUB_TOKEN` is set as environment variable
502
+ 3. Check you have access to COMPFEST GitHub Packages
503
+
504
+ ### "Package version not found"
505
+
506
+ 1. Check if the package was actually published
507
+ 2. Verify you're using the correct tag (`@latest`, `@develop`, `@staging`)
508
+ 3. Check GitHub Actions logs for publish status
509
+
510
+ ### Type Errors After Update
511
+
512
+ 1. Clear node_modules and reinstall:
513
+ ```bash
514
+ rm -rf node_modules
515
+ pnpm install
516
+ ```
517
+
518
+ 2. If types are outdated, you may need to wait for CI/CD to complete
519
+
520
+ ### Build Errors in Consumer Project
521
+
522
+ Make sure you have the peer dependencies installed:
523
+
524
+ ```bash
525
+ pnpm add drizzle-orm
526
+ ```
527
+
528
+ ---
529
+
530
+ ## License
531
+
532
+ UNLICENSED - Private. All rights reserved, COMPFEST.
533
+
534
+ ---
535
+
536
+ ## Support
537
+
538
+ For issues or questions:
539
+ - Open an issue on GitHub: [COMPFEST/oppenheimer](https://github.com/COMPFEST/oppenheimer/issues)
540
+ - Contact the backend team