-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
29 lines (28 loc) · 1.21 KB
/
Copy pathschema.sql
File metadata and controls
29 lines (28 loc) · 1.21 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
-- bsvbounties D1 (Phase C) — isolates account reads from the KV JSON files.
-- Database name: bsvbounties (per CEO decision).
--
-- Provision:
-- wrangler d1 create bsvbounties
-- wrangler d1 execute bsvbounties --file=schema.sql --remote (from apps/api or repo root)
-- uncomment the d1_databases block in wrangler.jsonc (binding BSVB_D1)
-- node scripts/backfill-d1.mjs ./data/accounts.json > backfill.sql
-- wrangler d1 execute bsvbounties --file=backfill.sql --remote
--
-- KV JSON files remain the source of truth until the cutover release;
-- the worker dual-writes every account mutation to bb_accounts.
CREATE TABLE IF NOT EXISTS bb_accounts (
number INTEGER PRIMARY KEY,
controller_key TEXT NOT NULL DEFAULT '',
kind TEXT NOT NULL DEFAULT 'human',
for_sale INTEGER NOT NULL DEFAULT 0,
stats_json TEXT NOT NULL DEFAULT '{}',
twetch_sub TEXT,
body_json TEXT NOT NULL DEFAULT '{}',
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_bb_accounts_controller ON bb_accounts(controller_key);
CREATE INDEX IF NOT EXISTS idx_bb_accounts_forsale ON bb_accounts(for_sale);
CREATE TABLE IF NOT EXISTS bb_meta (
key TEXT PRIMARY KEY,
value TEXT NOT NULL DEFAULT ''
);