diff --git a/backend/mpc-system/migrations/001_init_schema.up.sql b/backend/mpc-system/migrations/001_init_schema.up.sql index 76977bb2..285b867a 100644 --- a/backend/mpc-system/migrations/001_init_schema.up.sql +++ b/backend/mpc-system/migrations/001_init_schema.up.sql @@ -114,16 +114,17 @@ CREATE UNIQUE INDEX idx_party_key_shares_unique ON party_key_shares(party_id, se -- ============================================ -- Accounts table +-- Only username is required, all other fields are optional CREATE TABLE accounts ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), username VARCHAR(255) UNIQUE NOT NULL, - email VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255), phone VARCHAR(50), - public_key BYTEA NOT NULL, -- MPC group public key - keygen_session_id UUID NOT NULL, -- Related Keygen session - threshold_n INTEGER NOT NULL, - threshold_t INTEGER NOT NULL, - status VARCHAR(20) NOT NULL, + public_key BYTEA, -- MPC group public key (optional, set after keygen) + keygen_session_id UUID, -- Related Keygen session (optional) + threshold_n INTEGER, + threshold_t INTEGER, + status VARCHAR(20) DEFAULT 'active', created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), last_login_at TIMESTAMP, @@ -132,7 +133,8 @@ CREATE TABLE accounts ( -- Indexes for accounts CREATE INDEX idx_accounts_username ON accounts(username); -CREATE INDEX idx_accounts_email ON accounts(email); +CREATE INDEX idx_accounts_email ON accounts(email) WHERE email IS NOT NULL; +CREATE UNIQUE INDEX idx_accounts_email_unique ON accounts(email) WHERE email IS NOT NULL; CREATE INDEX idx_accounts_public_key ON accounts(public_key); CREATE INDEX idx_accounts_status ON accounts(status); diff --git a/backend/mpc-system/migrations/006_make_email_optional.down.sql b/backend/mpc-system/migrations/006_make_email_optional.down.sql new file mode 100644 index 00000000..8527fd86 --- /dev/null +++ b/backend/mpc-system/migrations/006_make_email_optional.down.sql @@ -0,0 +1,12 @@ +-- Revert email field to NOT NULL + +-- Drop partial unique index +DROP INDEX IF EXISTS idx_accounts_email_unique; + +-- Set email back to NOT NULL (this will fail if there are NULL emails in the table) +ALTER TABLE accounts + ALTER COLUMN email SET NOT NULL; + +-- Add back UNIQUE constraint on email +ALTER TABLE accounts + ADD CONSTRAINT accounts_email_key UNIQUE (email); diff --git a/backend/mpc-system/migrations/006_make_email_optional.up.sql b/backend/mpc-system/migrations/006_make_email_optional.up.sql new file mode 100644 index 00000000..54d9f968 --- /dev/null +++ b/backend/mpc-system/migrations/006_make_email_optional.up.sql @@ -0,0 +1,12 @@ +-- Make email field optional in accounts table +-- Only username is required, other fields are optional + +ALTER TABLE accounts + ALTER COLUMN email DROP NOT NULL; + +-- Drop UNIQUE constraint on email since it can be NULL now +ALTER TABLE accounts + DROP CONSTRAINT IF EXISTS accounts_email_key; + +-- Create partial unique index on email (only for non-NULL values) +CREATE UNIQUE INDEX idx_accounts_email_unique ON accounts(email) WHERE email IS NOT NULL;