28 lines
1.1 KiB
SQL
28 lines
1.1 KiB
SQL
-- Platform control-plane user invitations.
|
|
-- Separate from access_request_invitations because these users belong to OmniOil/Kyrbot,
|
|
-- not to customer onboarding requests or projects.
|
|
|
|
CREATE TABLE IF NOT EXISTS platform_user_invitations (
|
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
token_hash TEXT NOT NULL UNIQUE,
|
|
email_status VARCHAR(30) NOT NULL DEFAULT 'pending'
|
|
CHECK (email_status IN ('pending', 'sent', 'failed')),
|
|
email_sent_at TIMESTAMPTZ,
|
|
email_error TEXT,
|
|
expires_at TIMESTAMPTZ NOT NULL,
|
|
consumed_at TIMESTAMPTZ,
|
|
revoked_at TIMESTAMPTZ,
|
|
revoked_reason TEXT,
|
|
created_by UUID REFERENCES users(id) ON DELETE SET NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_platform_user_invitations_user_latest
|
|
ON platform_user_invitations(user_id, created_at DESC);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_platform_user_invitations_token_hash_open
|
|
ON platform_user_invitations(token_hash)
|
|
WHERE consumed_at IS NULL AND revoked_at IS NULL;
|