-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
82 lines (69 loc) · 2.52 KB
/
Copy pathschema.sql
File metadata and controls
82 lines (69 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
-- LENS Intelligence Database Schema
-- Run this in Supabase SQL Editor
-- Table: bankr_launches
-- Stores all Bankrbot token launches with X username mapping
CREATE TABLE IF NOT EXISTS bankr_launches (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
token_address text UNIQUE NOT NULL,
token_name text,
token_symbol text,
chain text DEFAULT 'base',
status text DEFAULT 'deployed',
deployer_wallet text,
fee_recipient_wallet text,
x_username text,
x_user_id text,
image_url text,
launched_at timestamptz,
indexed_at timestamptz DEFAULT now(),
updated_at timestamptz DEFAULT now()
);
-- Index for fast lookup by X username
CREATE INDEX IF NOT EXISTS idx_bankr_launches_x_username
ON bankr_launches(lower(x_username));
-- Index for wallet lookups
CREATE INDEX IF NOT EXISTS idx_bankr_launches_deployer
ON bankr_launches(lower(deployer_wallet));
CREATE INDEX IF NOT EXISTS idx_bankr_launches_fee_recipient
ON bankr_launches(lower(fee_recipient_wallet));
-- Table: bankr_fees_cache
-- Cache fees data per token (refreshed every 5 min)
CREATE TABLE IF NOT EXISTS bankr_fees_cache (
token_address text PRIMARY KEY,
claimed_usd numeric DEFAULT 0,
claimable_usd numeric DEFAULT 0,
claim_count integer DEFAULT 0,
last_fetched timestamptz DEFAULT now()
);
-- Table: bankr_dev_sells
-- Cache dev sell events per token
CREATE TABLE IF NOT EXISTS bankr_dev_sells (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
token_address text NOT NULL,
deployer_wallet text NOT NULL,
sell_count integer DEFAULT 0,
total_sold text,
pct_sold text,
first_sell_date text,
last_sell_date text,
last_fetched timestamptz DEFAULT now(),
UNIQUE(token_address, deployer_wallet)
);
-- Enable RLS
ALTER TABLE bankr_launches ENABLE ROW LEVEL SECURITY;
ALTER TABLE bankr_fees_cache ENABLE ROW LEVEL SECURITY;
ALTER TABLE bankr_dev_sells ENABLE ROW LEVEL SECURITY;
-- Allow public read (anon key can read)
CREATE POLICY "Public read bankr_launches" ON bankr_launches
FOR SELECT USING (true);
CREATE POLICY "Public read bankr_fees_cache" ON bankr_fees_cache
FOR SELECT USING (true);
CREATE POLICY "Public read bankr_dev_sells" ON bankr_dev_sells
FOR SELECT USING (true);
-- Allow service role to write
CREATE POLICY "Service write bankr_launches" ON bankr_launches
FOR ALL USING (auth.role() = 'service_role');
CREATE POLICY "Service write bankr_fees_cache" ON bankr_fees_cache
FOR ALL USING (auth.role() = 'service_role');
CREATE POLICY "Service write bankr_dev_sells" ON bankr_dev_sells
FOR ALL USING (auth.role() = 'service_role');