Index

public.email_verification_tokens

Description

Stores email verification tokens and codes for two-step authentication. Expired records are automatically filtered in queries and randomly cleaned up (1 in 10 chance) to prevent table bloat.

Columns

Name Type Default Nullable Children Parents Comment
code varchar(6) false One-time 6-digit verification code sent via email
code_sent boolean false false Whether the email with code has been sent
created_at timestamp with time zone now() false Time when the token was created.
deleted_at timestamp with time zone true Timestamp when the record was deleted. If null, the record is not deleted.
email_verification_token varchar(255) false Long random string token (minimum 128 characters) returned to frontend for verification
expires_at timestamp with time zone (now() + ‘00:15:00’::interval) false Time after which the token and code become invalid (default 15 minutes)
id uuid gen_random_uuid() false A unique identifier for this token record
updated_at timestamp with time zone now() false Time when the record was last updated. Automatically set by trigger.
used_at timestamp with time zone true Time when the token was successfully used. Null if unused.
user_id uuid false public.users References the user this token belongs to

Constraints

Name Type Definition
email_verification_token_length CHECK CHECK ((length((email_verification_token)::text) >= 128))
email_verification_tokens_code_not_null n NOT NULL code
email_verification_tokens_code_sent_not_null n NOT NULL code_sent
email_verification_tokens_created_at_not_null n NOT NULL created_at
email_verification_tokens_email_verification_token_not_null n NOT NULL email_verification_token
email_verification_tokens_expires_at_not_null n NOT NULL expires_at
email_verification_tokens_id_not_null n NOT NULL id
email_verification_tokens_pkey PRIMARY KEY PRIMARY KEY (id)
email_verification_tokens_updated_at_not_null n NOT NULL updated_at
email_verification_tokens_user_id_fkey FOREIGN KEY FOREIGN KEY (user_id) REFERENCES users(id)
email_verification_tokens_user_id_not_null n NOT NULL user_id

Indexes

Name Definition
email_verification_tokens_pkey CREATE UNIQUE INDEX email_verification_tokens_pkey ON public.email_verification_tokens USING btree (id)
idx_email_verification_tokens_expires_at CREATE INDEX idx_email_verification_tokens_expires_at ON public.email_verification_tokens USING btree (expires_at)
unique_active_email_verification_token CREATE UNIQUE INDEX unique_active_email_verification_token ON public.email_verification_tokens USING btree (email_verification_token, deleted_at) NULLS NOT DISTINCT WHERE (used_at IS NULL)

Triggers

Name Definition
set_timestamp CREATE TRIGGER set_timestamp BEFORE UPDATE ON public.email_verification_tokens FOR EACH ROW EXECUTE FUNCTION trigger_set_timestamp()

Relations

er

Generated by tbls