Skip to main content

invite_links

Overview

The invite_links table manages shareable invite codes that users can send to bring friends onto the platform. Each link has a unique code, an optional max_uses limit, and an expiration date. Users are rate-limited to 10 active invite links at a time. Using an invite link automatically creates a friendship between the inviter and invitee.

Relevant Invariants

  • Invariant #7: "Human-Scale Social Contexts" -- Invite limits prevent mass onboarding
  • Invariant #11: "System Resists Optimization" -- Rate limiting on invites prevents growth hacking

Schema

-- From 20260202_invite_links.sql
CREATE TABLE invite_links (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
code TEXT UNIQUE NOT NULL DEFAULT generate_invite_code(),
created_by UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
max_uses INTEGER DEFAULT 1,
current_uses INTEGER DEFAULT 0,
expires_at TIMESTAMPTZ DEFAULT (NOW() + INTERVAL '7 days'),
is_active BOOLEAN DEFAULT TRUE,
note TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
codetextNogenerate_invite_code()Unique shareable code
created_byuuidNo--User who created the invite
max_usesintegerNo1Maximum number of times code can be used
current_usesintegerNo0Times code has been used
expires_attimestamptzNoNOW() + 7 daysExpiration timestamp
is_activebooleanNoTRUEWhether code is still usable
notetextYes--Personal note about who this is for
created_attimestamptzNoNOW()Creation timestamp

RLS Policies

-- SELECT: Users can view their own invite links
CREATE POLICY "Users can view own invite links"
ON invite_links FOR SELECT
USING (auth.uid() = created_by);

-- INSERT: Users can create invites (max 10 active)
CREATE POLICY "Users can create invite links"
ON invite_links FOR INSERT
WITH CHECK (auth.uid() = created_by);

-- UPDATE: Users can deactivate their own links
CREATE POLICY "Users can update own invite links"
ON invite_links FOR UPDATE
USING (auth.uid() = created_by);

Last updated: 2026-02-07