Skip to content

Commit

Permalink
feat: initial spike on referrals service
Browse files Browse the repository at this point in the history
extracted from original implementation in storacha/console#142
  • Loading branch information
travis committed Nov 8, 2024
1 parent c177f82 commit f21b15a
Show file tree
Hide file tree
Showing 6 changed files with 2,005 additions and 97 deletions.
17 changes: 17 additions & 0 deletions migrations/0001_create_referrals_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Migration number: 0001 2024-10-21T15:14:46.268Z

-- users identified by email. each user has a refcode they can use to invite other users
CREATE TABLE IF NOT EXISTS users (
email TEXT PRIMARY KEY,
refcode TEXT UNIQUE
);

-- referrals identified by email. each referral tracks the refcode it was referred by.
-- "reward" tracks whether the referee has paid long enough for the referrer to be rewarded
CREATE TABLE IF NOT EXISTS referrals (
email TEXT PRIMARY KEY,
refcode TEXT UNIQUE,
referred_at DATETIME DEFAULT CURRENT_TIMESTAMP,
reward BOOLEAN,
FOREIGN KEY(refcode) REFERENCES users(refcode)
);
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"dev": "wrangler dev --port 4000",
"start": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types"
"cf-typegen": "wrangler types",
"db:local:clear": "rm -rf .wrangler/state/v3/d1",
"db:local:init": "pnpm wrangler d1 migrations apply referrals --local",
"db:local:reset": "pnpm db:local:clear && pnpm db:local:init"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.5.2",
"@cloudflare/workers-types": "^4.20241106.0",
"typescript": "^5.5.2",
"vitest": "2.0.5",
"wrangler": "^3.60.3"
},
"dependencies": {
"@tsndr/cloudflare-worker-router": "^3.2.10"
}
}
Loading

0 comments on commit f21b15a

Please sign in to comment.