Repository navigation
Feature: refactor/db-constraints to dev - #615
Conversation
user.email gets a unique index (the auth adapter already assumed one row per address), and 14 CHECK constraints hold ranges the API enforces today: ratings 1-5, end after start on hackathons, events and judging schedules, appointment times in order, positive caps, non-negative prices, stock and points, purchase totals equal to unit price times quantity, and point adjustments non-zero within -1000..1000. The production preflight (packages/db/sql/preflight-2026-11-constraints.sql) found no row breaking any of these. It found one initiative with max_members = 0, so that check is left out until the row is corrected.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c7cc72e. Configure here.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
Visit the preview URL for this PR (updated for commit a2c5fdf): https://hacklyticss2026--pr-615-t195d76c.web.app (expires Sat, 21 Nov 2026 23:06:17 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 5d238be33273095766c18a8339b7b0c47de8a950 |
|
Visit the preview URL for this PR (updated for commit a2c5fdf): https://hacklytics2027--pr-615-pgqxbl6x.web.app (expires Sat, 21 Nov 2026 23:06:22 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: c48ba34db61581e25fe2978355160b5eefe0e83f |
drizzle-kit reads a primary key's columns from constraint_column_usage, which lists them by name (challenge_id, entry_id), and compared that with the declared entry-first order. Every deploy's push dropped and re-added the key. Declare it in the order drizzle-kit reads, under the name it already has; the key in the database is unchanged.
The auth adapter looks users up by lower(email), and providers keep the casing an address was typed in, so a unique index on the raw column still allowed Ada@x.com and ada@x.com as two accounts. Index lower(email) instead, and keep the plain email index the exact-match lookups use. Production has no two addresses that collide once lowercased.

Automated PR tracking changes from
refactor/db-constraintsintodev.Note
Medium Risk
Schema deploy may reject existing bad data and block sign-up if duplicate emails differ only by case; the judging PK reorder is metadata-only but still touches a migration path.
Overview
Adds PostgreSQL CHECK constraints across auth-adjacent and hackathon/judging/points tables so invalid rows fail at the database (date/time ordering, positive caps, non-zero point deltas, purchase totals, judging schedule windows, 1–5 ratings, etc.), matching rules that were previously API-only.
Introduces a case-insensitive unique index on
lower(user.email)so one account exists per address, consistent with how the auth adapter resolves users.Fixes drizzle-kit drift: reorders and names the
judging_entry_challengecomposite primary key to match what Postgres already has, avoiding drop/recreate on every deploy.Reviewed by Cursor Bugbot for commit a2c5fdf. Bugbot is set up for automated code reviews on this repo. Configure here.