@bash-app/bash-common 30.116.0 → 30.118.0

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.
Files changed (31) hide show
  1. package/dist/extendedSchemas.d.ts +54 -0
  2. package/dist/extendedSchemas.d.ts.map +1 -1
  3. package/dist/extendedSchemas.js +10 -1
  4. package/dist/extendedSchemas.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/utils/__tests__/paymentUtils.test.d.ts +6 -0
  9. package/dist/utils/__tests__/paymentUtils.test.d.ts.map +1 -0
  10. package/dist/utils/__tests__/paymentUtils.test.js +77 -0
  11. package/dist/utils/__tests__/paymentUtils.test.js.map +1 -0
  12. package/dist/utils/discountEngine/__tests__/bestPriceResolver.test.d.ts +2 -0
  13. package/dist/utils/discountEngine/__tests__/bestPriceResolver.test.d.ts.map +1 -0
  14. package/dist/utils/discountEngine/__tests__/bestPriceResolver.test.js +457 -0
  15. package/dist/utils/discountEngine/__tests__/bestPriceResolver.test.js.map +1 -0
  16. package/dist/utils/discountEngine/__tests__/eligibilityValidator.test.d.ts +2 -0
  17. package/dist/utils/discountEngine/__tests__/eligibilityValidator.test.d.ts.map +1 -0
  18. package/dist/utils/discountEngine/__tests__/eligibilityValidator.test.js +480 -0
  19. package/dist/utils/discountEngine/__tests__/eligibilityValidator.test.js.map +1 -0
  20. package/package.json +2 -2
  21. package/prisma/COMPREHENSIVE-MIGRATION-README.md +295 -0
  22. package/prisma/MIGRATION-FILES-GUIDE.md +76 -0
  23. package/prisma/comprehensive-migration-20260120.sql +5751 -0
  24. package/prisma/delta-migration-20260120.sql +302 -0
  25. package/prisma/schema.prisma +253 -13
  26. package/prisma/verify-migration.sql +132 -0
  27. package/src/extendedSchemas.ts +10 -1
  28. package/src/index.ts +4 -0
  29. package/src/utils/__tests__/paymentUtils.test.ts +95 -0
  30. package/src/utils/discountEngine/__tests__/bestPriceResolver.test.ts +558 -0
  31. package/src/utils/discountEngine/__tests__/eligibilityValidator.test.ts +655 -0
@@ -0,0 +1,295 @@
1
+ # Comprehensive Database Migration - January 20, 2026
2
+
3
+ ## 📋 Overview
4
+
5
+ This migration script contains the **complete database schema** for the Bash application as defined in `schema.prisma`.
6
+
7
+ **Generated:** January 20, 2026
8
+ **File:** `comprehensive-migration-20260120.sql`
9
+ **Size:** 227KB
10
+ **Lines:** 5,751
11
+
12
+ ---
13
+
14
+ ## ⚠️ IMPORTANT - Read Before Running
15
+
16
+ ### This is a FULL SCHEMA script
17
+
18
+ This script creates the **entire database from scratch**. It is designed for:
19
+
20
+ ✅ **New/Empty databases**
21
+ ✅ **QA environments** that need to match production schema
22
+ ✅ **Production databases** that are significantly out of sync
23
+
24
+ ❌ **DO NOT run on existing production databases** unless you:
25
+ - Have a complete backup
26
+ - Understand it will create all tables/enums if they don't exist
27
+ - Know it uses `IF NOT EXISTS` so it's safe for incremental updates
28
+
29
+ ---
30
+
31
+ ## 🚀 How to Apply This Migration
32
+
33
+ ### Option 1: Vercel Postgres Dashboard (Recommended for QA/Prod)
34
+
35
+ ```bash
36
+ 1. Open: https://vercel.com/dashboard
37
+ 2. Navigate to: Your Project > Storage > Postgres > Query tab
38
+ 3. Copy contents of: bash-common/prisma/comprehensive-migration-20260120.sql
39
+ 4. Paste into query editor
40
+ 5. Execute (may take 30-60 seconds)
41
+ 6. Verify completion (check for errors in output)
42
+ ```
43
+
44
+ ### Option 2: Command Line (psql)
45
+
46
+ ```bash
47
+ # Make sure you have the correct DATABASE_URL set
48
+ export DATABASE_URL="your_qa_or_prod_database_url"
49
+
50
+ # Run the migration
51
+ psql $DATABASE_URL -f bash-common/prisma/comprehensive-migration-20260120.sql
52
+
53
+ # Check for errors
54
+ echo $? # Should return 0 if successful
55
+ ```
56
+
57
+ ### Option 3: Database GUI Tools (TablePlus, DBeaver, etc.)
58
+
59
+ ```bash
60
+ 1. Connect to your QA/Prod database
61
+ 2. Open SQL query window
62
+ 3. Load: bash-common/prisma/comprehensive-migration-20260120.sql
63
+ 4. Execute
64
+ 5. Commit transaction
65
+ ```
66
+
67
+ ### Option 4: Prisma (Recommended for Dev, Use Caution for Prod)
68
+
69
+ ```bash
70
+ cd bash-common
71
+
72
+ # For development/local:
73
+ npx prisma db push
74
+
75
+ # For production (if you want Prisma to handle it):
76
+ # WARNING: Always test in QA first!
77
+ npx prisma db push --accept-data-loss
78
+ ```
79
+
80
+ ---
81
+
82
+ ## 📊 What This Migration Includes
83
+
84
+ ### Enums (69 total)
85
+ - ClubAdminRole, ClubMemberStatus, TaskStatus
86
+ - NotificationType, NotificationPriority
87
+ - BashEventType, Privacy, BashStatus
88
+ - ServiceStatus, ServiceCondition
89
+ - All business logic enums
90
+
91
+ ### Tables (100+ tables)
92
+ - **Core:** User, BashEvent, Service, Ticket
93
+ - **Social:** BashFeedPost, BashFeedComment, BashFeedLike
94
+ - **Competitions:** Competition, Prize, Participant, Bracket
95
+ - **Tasks:** EventTask, TaskComment, TaskInvitation
96
+ - **Organizations:** Organization, OrganizationMember, OrganizationEvent
97
+ - **Services:** Service booking, payments, analytics
98
+ - **Payments:** BashCash, Stripe integrations
99
+ - **Audit:** AuditLog, error tracking
100
+ - And many more...
101
+
102
+ ### Indexes
103
+ - All necessary indexes for performance
104
+ - Foreign key relationships
105
+ - Unique constraints
106
+
107
+ ### Relationships
108
+ - All foreign keys properly configured
109
+ - Cascade delete rules where appropriate
110
+ - Referential integrity enforced
111
+
112
+ ---
113
+
114
+ ## ✅ Post-Migration Verification
115
+
116
+ After running the migration, verify it worked:
117
+
118
+ ```sql
119
+ -- 1. Check all tables exist
120
+ SELECT COUNT(*) as table_count
121
+ FROM information_schema.tables
122
+ WHERE table_schema = 'public';
123
+ -- Expected: 100+ tables
124
+
125
+ -- 2. Check all enums exist
126
+ SELECT COUNT(*) as enum_count
127
+ FROM pg_type
128
+ WHERE typtype = 'e';
129
+ -- Expected: 69+ enums
130
+
131
+ -- 3. Check specific critical tables
132
+ SELECT table_name
133
+ FROM information_schema.tables
134
+ WHERE table_schema = 'public'
135
+ AND table_name IN ('User', 'BashEvent', 'Service', 'BashFeedPost', 'Competition')
136
+ ORDER BY table_name;
137
+ -- Expected: All 5 tables listed
138
+
139
+ -- 4. Check indexes
140
+ SELECT COUNT(*) as index_count
141
+ FROM pg_indexes
142
+ WHERE schemaname = 'public';
143
+ -- Expected: 200+ indexes
144
+ ```
145
+
146
+ ---
147
+
148
+ ## 🔄 If You Already Have Data
149
+
150
+ ### Scenario 1: QA Database with Old Schema
151
+ ✅ **Safe to run** - Uses `IF NOT EXISTS` so existing data won't be affected
152
+
153
+ ### Scenario 2: Production Database with Partial Schema
154
+ ⚠️ **Use Caution** - Run in a transaction first:
155
+
156
+ ```sql
157
+ BEGIN;
158
+ -- Paste migration SQL here
159
+ -- Check results
160
+ ROLLBACK; -- If issues found
161
+ -- OR
162
+ COMMIT; -- If everything looks good
163
+ ```
164
+
165
+ ### Scenario 3: Completely New Database
166
+ ✅ **Perfect use case** - Run the entire script
167
+
168
+ ---
169
+
170
+ ## 🔙 Rollback Strategy
171
+
172
+ If something goes wrong:
173
+
174
+ ### Option 1: Restore from Backup
175
+ ```bash
176
+ # Always have a backup before running migrations!
177
+ pg_restore -d your_database your_backup.dump
178
+ ```
179
+
180
+ ### Option 2: Point-in-Time Recovery (if using Vercel/AWS/GCP)
181
+ - Use your cloud provider's snapshot/restore feature
182
+ - Restore to just before migration
183
+
184
+ ### Option 3: Transaction Rollback (if you wrapped in BEGIN/COMMIT)
185
+ ```sql
186
+ ROLLBACK;
187
+ ```
188
+
189
+ ---
190
+
191
+ ## 📝 Comparison with Previous Migrations
192
+
193
+ ### Previous Migration Files (November 2025):
194
+ - `quick-migration.sql` - 47 lines (Task system only)
195
+ - `manual-migration-add-missing-columns.sql` - 183 lines (Task system only)
196
+
197
+ ### This Migration (January 2026):
198
+ - `comprehensive-migration-20260120.sql` - **5,751 lines** (ENTIRE SCHEMA)
199
+
200
+ **Key Differences:**
201
+ - ✅ Includes ALL tables (not just Task system)
202
+ - ✅ Includes ALL enums
203
+ - ✅ Includes ALL indexes
204
+ - ✅ Includes ALL relationships
205
+ - ✅ Current as of January 20, 2026
206
+
207
+ ---
208
+
209
+ ## 🛡️ Safety Features
210
+
211
+ This migration script is designed with safety in mind:
212
+
213
+ ✅ Uses `IF NOT EXISTS` for tables, enums, indexes
214
+ ✅ Won't drop existing data
215
+ ✅ Won't fail if tables already exist
216
+ ✅ Idempotent - safe to run multiple times
217
+ ✅ Proper foreign key constraints
218
+ ✅ No data deletion commands
219
+
220
+ ---
221
+
222
+ ## 🔍 Troubleshooting
223
+
224
+ ### Error: "type already exists"
225
+ **Solution:** Ignore - this is expected if enum already exists
226
+
227
+ ### Error: "relation already exists"
228
+ **Solution:** Ignore - this is expected if table already exists
229
+
230
+ ### Error: "permission denied"
231
+ **Solution:** Ensure your database user has CREATE privileges:
232
+ ```sql
233
+ GRANT CREATE ON DATABASE your_db TO your_user;
234
+ ```
235
+
236
+ ### Error: "out of memory"
237
+ **Solution:** Run script in smaller chunks or increase database memory
238
+
239
+ ### Migration takes too long
240
+ **Solution:** Normal for first run (30-60 seconds). Break into chunks if needed.
241
+
242
+ ---
243
+
244
+ ## 📞 Support
245
+
246
+ If you encounter issues:
247
+
248
+ 1. **Check Logs:** Vercel Dashboard > Logs
249
+ 2. **Verify Syntax:** Ensure no copy/paste errors
250
+ 3. **Check Permissions:** Ensure database user has necessary permissions
251
+ 4. **Rollback:** Use backup if something goes wrong
252
+ 5. **Test First:** Always run in QA before production
253
+
254
+ ---
255
+
256
+ ## ✨ Next Steps After Migration
257
+
258
+ 1. ✅ Verify migration completed successfully (run verification queries above)
259
+ 2. ✅ Restart API servers
260
+ 3. ✅ Run `npx prisma generate` in bash-common to sync Prisma client
261
+ 4. ✅ Clear any Redis/cache
262
+ 5. ✅ Test critical endpoints
263
+ 6. ✅ Monitor for errors in production logs
264
+
265
+ ---
266
+
267
+ ## 📅 Migration History
268
+
269
+ | Date | File | Description | Lines |
270
+ |------|------|-------------|-------|
271
+ | Nov 2025 | quick-migration.sql | Task system tables | 47 |
272
+ | Nov 2025 | manual-migration-add-missing-columns.sql | Task system detailed | 183 |
273
+ | **Jan 20, 2026** | **comprehensive-migration-20260120.sql** | **Full schema** | **5,751** |
274
+
275
+ ---
276
+
277
+ ## 🎯 Production Deployment Checklist
278
+
279
+ Before running in production:
280
+
281
+ - [ ] Full database backup completed
282
+ - [ ] Tested in QA environment
283
+ - [ ] Verified no data loss in QA
284
+ - [ ] Notified team of maintenance window
285
+ - [ ] API servers ready to restart
286
+ - [ ] Rollback plan prepared
287
+ - [ ] Monitoring/alerts configured
288
+ - [ ] Post-migration verification queries ready
289
+
290
+ ---
291
+
292
+ **Generated by:** Prisma Migrate Diff
293
+ **Command:** `npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script`
294
+ **Source:** bash-common/prisma/schema.prisma
295
+ **Date:** January 20, 2026
@@ -0,0 +1,76 @@
1
+ # Database Migration Files - Quick Reference
2
+
3
+ ## 📁 Available Migration Scripts
4
+
5
+ ### 1. **comprehensive-migration-20260120.sql** (✨ NEWEST - USE THIS)
6
+ - **Size:** 227KB (5,751 lines)
7
+ - **Date:** January 20, 2026
8
+ - **Scope:** COMPLETE SCHEMA (all tables, enums, indexes)
9
+ - **Use For:** QA/Prod deployment, new databases, full schema sync
10
+ - **Safety:** Uses `IF NOT EXISTS` - safe to run on existing databases
11
+
12
+ ### 2. **quick-migration.sql** (⚠️ OLD - November 2025)
13
+ - **Size:** 47 lines
14
+ - **Scope:** Task system only (TaskComment, TaskInvitation tables)
15
+ - **Status:** Outdated - does not include recent schema changes
16
+
17
+ ### 3. **manual-migration-add-missing-columns.sql** (⚠️ OLD - November 2025)
18
+ - **Size:** 183 lines
19
+ - **Scope:** Task system only with detailed comments
20
+ - **Status:** Outdated - does not include recent schema changes
21
+
22
+ ---
23
+
24
+ ## 🎯 Which File Should I Use?
25
+
26
+ | Scenario | File to Use | Why |
27
+ |----------|-------------|-----|
28
+ | **QA Database needs full sync** | `comprehensive-migration-20260120.sql` | Complete, up-to-date schema |
29
+ | **Production needs full sync** | `comprehensive-migration-20260120.sql` | Complete, up-to-date schema |
30
+ | **New empty database** | `comprehensive-migration-20260120.sql` | Creates everything from scratch |
31
+ | **Only need task tables** | ❌ Use comprehensive instead | Old files are outdated |
32
+
33
+ ---
34
+
35
+ ## 🚀 Quick Start
36
+
37
+ ```bash
38
+ # 1. Navigate to the file
39
+ cd bash-common/prisma
40
+
41
+ # 2. Apply to your database (choose one method):
42
+
43
+ # Method A: Vercel Dashboard
44
+ # Copy comprehensive-migration-20260120.sql to Vercel Query Editor
45
+
46
+ # Method B: Command line
47
+ psql $DATABASE_URL -f comprehensive-migration-20260120.sql
48
+
49
+ # Method C: Prisma
50
+ cd .. && npx prisma db push
51
+ ```
52
+
53
+ ---
54
+
55
+ ## 📖 Documentation
56
+
57
+ See [`COMPREHENSIVE-MIGRATION-README.md`](./COMPREHENSIVE-MIGRATION-README.md) for:
58
+ - Detailed instructions
59
+ - Verification queries
60
+ - Rollback procedures
61
+ - Troubleshooting guide
62
+ - Safety checklist
63
+
64
+ ---
65
+
66
+ ## ⚠️ Important Notes
67
+
68
+ 1. **Always backup before running migrations**
69
+ 2. **Test in QA before production**
70
+ 3. **The comprehensive script is idempotent** (safe to run multiple times)
71
+ 4. **Old migration files (quick-migration.sql, manual-migration-add-missing-columns.sql) are outdated**
72
+
73
+ ---
74
+
75
+ **Last Updated:** January 20, 2026
76
+ **Current Schema Version:** comprehensive-migration-20260120.sql