Repository navigation
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.
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.
Feature: refactor/db-constraints to dev
Contributor
Author
Contributor
Author
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
Author
|
Visit the preview URL for this PR (updated for commit 6381fe1): https://hacklytics2027--pr-616-8b8cowlr.web.app (expires Sat, 21 Nov 2026 23:09:52 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: c48ba34db61581e25fe2978355160b5eefe0e83f |
Contributor
Author
|
Visit the preview URL for this PR (updated for commit 6381fe1): https://hacklyticss2026--pr-616-dbqqyct0.web.app (expires Sat, 21 Nov 2026 23:09:53 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 5d238be33273095766c18a8339b7b0c47de8a950 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated PR tracking changes from
devintomain.Note
Medium Risk
Schema migrations add constraints and a case-insensitive email unique index; deploy can fail if existing rows violate the new rules or duplicate emails differ only by case.
Overview
Adds database-level validation across auth, events, hackathons, judging, and points schemas so invalid writes fail at Postgres, not only in the API.
On
user, a newuniqueIndexonlower(email)enforces one account per address regardless of casing—aligned with the auth adapter’s case-insensitive lookups.CHECK constraints now guard date/time ordering (
end≥start), positive caps (maxCheckIns,maxParticipants,maxMembers), non-negative points/prices/stock, judging schedule windows and non-negative slot minutes, appointment time ordering (startsAt≤deadlineAt≤endsAt), rubric ratings 1–5, point adjustment deltas (non-zero, −1000..1000), and store purchase arithmetic (total = unitPrice × quantity,quantity > 0).In judging, the
judging_entry_challengeprimary key is declared with an explicit name and column order matching what drizzle-kit reads from Postgres, stopping migrate-push from repeatedly drop/recreate that key on deploy.Reviewed by Cursor Bugbot for commit 6381fe1. Bugbot is set up for automated code reviews on this repo. Configure here.