-- Make username uniqueness case-insensitive. -- -- The 0001 schema declared `username text NOT NULL UNIQUE`, which let -- "Alice" and "alice" both register and then race for who gets which -- session cookie on subsequent logins. Adding a partial / functional -- unique index over `lower(username)` blocks the conflict at the DB -- layer regardless of how the application normalises the input. -- -- The original `username UNIQUE` constraint is kept — it now overlaps -- with the new index but the duplication is cheap and removing the -- inline constraint would require a multi-step destructive migration -- on existing data. CREATE UNIQUE INDEX users_username_lower_uniq ON users (lower(username));