Skip to content

Feature: refactor/db-constraints to dev - #615

Merged
aamoghS merged 5 commits into
devfrom
refactor/db-constraints
Nov 14, 2026
Merged

aamoghS merged 5 commits into
devfrom
refactor/db-constraints

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Automated PR tracking changes from refactor/db-constraints into dev.


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_challenge composite 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.

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread packages/db/src/schemas/auth.ts Resolved
@aamoghS aamoghS closed this Nov 14, 2026
@aamoghS aamoghS reopened this Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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.
@aamoghS
aamoghS merged commit 6381fe1 into dev Nov 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant