schema: relax email UNIQUE to partial unique index for non-guest users

Allows multiple guest accounts to share an email while enforcing
uniqueness for registered users. Enables the disposable guest account pattern.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-04-30 11:44:27 +01:00
co-authored by Sisyphus
parent 16095ea372
commit 91dbdb199e
+6 -1
View File
@@ -88,7 +88,8 @@ CREATE TABLE users (
n_first_name VARCHAR(50) NOT NULL, -- vCard N.given
n_last_name VARCHAR(50) NOT NULL, -- vCard N.family
fn VARCHAR(120) GENERATED ALWAYS AS (n_first_name || ' ' || n_last_name) STORED, -- vCard FN
email VARCHAR(255) UNIQUE, -- vCard EMAIL (nullable for social-only/guest)
email VARCHAR(255), -- vCard EMAIL (nullable for social-only/guest)
-- Uniqueness enforced only for non-guest users via partial index
phone VARCHAR(20) NOT NULL, -- vCard TEL
date_of_birth DATE NOT NULL, -- vCard BDAY
profile_pic_url TEXT, -- vCard PHOTO
@@ -131,6 +132,10 @@ CREATE TABLE user_social_logins (
CREATE INDEX idx_users_email_lower ON users (LOWER(email));
CREATE INDEX idx_users_account_role ON users (account_role);
-- Enforce unique email only for registered (non-guest) users
-- Guest accounts can share emails; registered accounts cannot
CREATE UNIQUE INDEX idx_users_email_registered ON users (email) WHERE account_role != 'guest';
-- =======================================
-- VERIFICATION CODES TABLE
-- =======================================