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
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | uuid | No | gen_random_uuid() | Primary key |
code | text | No | generate_invite_code() | Unique shareable code |
created_by | uuid | No | -- | User who created the invite |
max_uses | integer | No | 1 | Maximum number of times code can be used |
current_uses | integer | No | 0 | Times code has been used |
expires_at | timestamptz | No | NOW() + 7 days | Expiration timestamp |
is_active | boolean | No | TRUE | Whether code is still usable |
note | text | Yes | -- | Personal note about who this is for |
created_at | timestamptz | No | NOW() | 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);
Related
- profiles -- Invite creator
- friendships -- Auto-created on invite use
Last updated: 2026-02-07