You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
synctv/migrations/20260426037_create_auth_ema...

20 lines
742 B
SQL

CREATE TABLE IF NOT EXISTS auth_email_bind_requests (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
email VARCHAR(255) NOT NULL,
token VARCHAR(255) UNIQUE NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
used_at TIMESTAMPTZ NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT auth_email_bind_requests_email_not_empty
CHECK (length(trim(email)) > 0)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_auth_email_bind_requests_user_unused
ON auth_email_bind_requests(user_id)
WHERE used_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_auth_email_bind_requests_expires_at
ON auth_email_bind_requests(expires_at);