Files
sorsfonalak/crates/db/migrations/0026_referrals.sql
T
fecoandClaude Opus 5.5 0e3eaee735
CI / test (push) Successful in 1m33s
CI / build (push) Successful in 6m18s
CI / deploy (push) Skipped
Share rewards: a question for a visit, an analysis for a new user
A click proves little, so the first visit of a shared link now earns a
question (once per user) instead of a natal analysis. A natal analysis is
earned by bringing a new user: the share page remembers the link, the
Google sign-up sends it, and when that user makes their own chart the
sharer gets one, at most three (referrals table, referral_reward). This is
off until sign-up opens (REFERRAL_REWARDS, default false). The share button
and its small print follow; /v1/me tells what was earned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-19 11:24:49 +00:00

20 lines
1.1 KiB
SQL

-- Sharing pays in two steps: the first visit of a shared link earns a
-- question (`share_reward`, see shares.rs), and someone who signs up from a
-- shared link and makes their own chart earns the sharer a natal analysis
-- (`referral_reward`, at most three per user).
ALTER TABLE credit_ledger DROP CONSTRAINT credit_ledger_reason_check;
ALTER TABLE credit_ledger ADD CONSTRAINT credit_ledger_reason_check
CHECK (reason IN ('monthly_grant', 'analysis', 'chat', 'refund', 'admin_adjust', 'purchase', 'person', 'package',
'question', 'share_reward', 'referral_reward'));
-- Who came through whose shared link (one row per new user).
CREATE TABLE referrals (
user_id uuid PRIMARY KEY REFERENCES users (id) ON DELETE CASCADE,
referrer_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
share_id uuid REFERENCES shares (id) ON DELETE SET NULL,
created_at timestamptz NOT NULL DEFAULT now(),
-- Set when the new user made their own chart (rewarded or over the limit).
rewarded_at timestamptz
);
CREATE INDEX referrals_referrer_idx ON referrals (referrer_id);