Partner emails are stored with inconsistent casing (e.g., 'Alice@Example.COM' vs 'alice@example.com'), which breaks duplicate detection and causes the same organization to appear multiple times in the system. Two parts to this fix: **Part 1 — Migration:** Write a database migration (using Drizzle `migrate`) that lowercases all existing `partner.email` values in place. The migration must be idempotent (safe to run twice). **Part 2 — Validation:** Add normalization at the input layer so new and updated partner records always save emails in lowercase: - In the zod schema for partner creation/update, add `.toLowerCase()` transform on the email field - Add a PostgreSQL check constraint as a safety net: `CHECK (email = lower(email))` Write tests that confirm: 1. Submitting 'User@EXAMPLE.com' saves as 'user@example.com' 2. A uniqueness check correctly identifies 'User@EXAMPLE.com' as a duplicate of an existing 'user@example.com' record 3. The migration does not error on already-lowercase emails
No contributions yet.