first commit

Made-with: Cursor
This commit is contained in:
Michaël
2026-02-26 18:33:00 -03:00
commit 3734365463
76 changed files with 14133 additions and 0 deletions

70
backend/src/db/schema.sql Normal file
View File

@@ -0,0 +1,70 @@
-- SQLite schema
CREATE TABLE IF NOT EXISTS users (
pubkey TEXT PRIMARY KEY,
nostr_first_seen_at INTEGER,
notes_count INTEGER DEFAULT 0,
followers_count INTEGER DEFAULT 0,
following_count INTEGER DEFAULT 0,
activity_score INTEGER DEFAULT 0,
last_metadata_fetch_at INTEGER,
lightning_address TEXT,
name TEXT,
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
);
CREATE TABLE IF NOT EXISTS claims (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pubkey TEXT NOT NULL,
claimed_at INTEGER NOT NULL,
payout_sats INTEGER NOT NULL,
ip_hash TEXT NOT NULL,
payout_destination_hash TEXT,
status TEXT NOT NULL CHECK(status IN ('pending','paid','failed')),
lnbits_payment_hash TEXT,
error_message TEXT,
FOREIGN KEY (pubkey) REFERENCES users(pubkey)
);
CREATE TABLE IF NOT EXISTS ip_limits (
ip_hash TEXT PRIMARY KEY,
last_claimed_at INTEGER NOT NULL,
claim_count_period INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS quotes (
quote_id TEXT PRIMARY KEY,
pubkey TEXT NOT NULL,
payout_sats INTEGER NOT NULL,
lightning_address TEXT,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
status TEXT NOT NULL CHECK(status IN ('active','consumed','expired'))
);
CREATE TABLE IF NOT EXISTS daily_stats (
date TEXT PRIMARY KEY,
total_paid_sats INTEGER NOT NULL DEFAULT 0,
total_claims INTEGER NOT NULL DEFAULT 0,
unique_pubkeys INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS nonces (
nonce TEXT PRIMARY KEY,
expires_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS deposits (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_at INTEGER NOT NULL,
amount_sats INTEGER NOT NULL,
source TEXT NOT NULL CHECK(source IN ('lightning','cashu')),
lnbits_payment_hash TEXT
);
CREATE INDEX IF NOT EXISTS idx_claims_pubkey ON claims(pubkey);
CREATE INDEX IF NOT EXISTS idx_claims_claimed_at ON claims(claimed_at);
CREATE INDEX IF NOT EXISTS idx_quotes_expires_at ON quotes(expires_at);
CREATE INDEX IF NOT EXISTS idx_quotes_status ON quotes(status);
CREATE INDEX IF NOT EXISTS idx_deposits_created_at ON deposits(created_at);
CREATE INDEX IF NOT EXISTS idx_deposits_lnbits_payment_hash ON deposits(lnbits_payment_hash);