@davoodmehraban89 / VELYQOR / commits / c207524
Fork 0

Intelligence, Advanced Charting & Trading Platform

chore(db): version least-privilege Neon ECB history reader role definition

davoodmehraban89 committed Oct 11, 2026 at 23:40 UTC c20752438f9b6c785ab076bdf73d6664c0e963e2
1 file changed +30
db/roles/chartnova_history_ro.sql new
+30
@@ -0,0 +1,30 @@
1 +-- ChartNova: reconstruct the *least-privilege* ECB history reader only.
2 +-- Intentionally does NOT recreate privileged legacy role chartnova_history_reader.
3 +-- NOT an auto-run migration. Execute only after an authorized review in the target Neon database.
4 +-- Secret/password is never stored in GitHub. NOLOGIN is deliberate until secure activation.
5 +DO $chartnova$
6 +BEGIN
7 + IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'chartnova_history_ro') THEN
8 + CREATE ROLE chartnova_history_ro
9 + NOLOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE
10 + NOREPLICATION NOBYPASSRLS NOINHERIT;
11 + END IF;
12 + IF EXISTS (
13 + SELECT 1 FROM pg_roles
14 + WHERE rolname='chartnova_history_ro'
15 + AND (rolsuper OR rolcreatedb OR rolcreaterole OR rolreplication OR rolbypassrls OR rolinherit)
16 + ) THEN
17 + RAISE EXCEPTION 'chartnova_history_ro has excessive privileges; halt and review';
18 + END IF;
19 + IF EXISTS (
20 + SELECT 1 FROM pg_auth_members m JOIN pg_roles r ON r.oid=m.member
21 + WHERE r.rolname='chartnova_history_ro'
22 + ) THEN
23 + RAISE EXCEPTION 'chartnova_history_ro inherits a role; halt and review';
24 + END IF;
25 +END
26 +$chartnova$;
27 +GRANT USAGE ON SCHEMA public TO chartnova_history_ro;
28 +GRANT SELECT ON TABLE public.chartnova_history_public TO chartnova_history_ro;
29 +-- Do not grant privileges on market_ticks, candles, providers, instruments, or other tables.
30 +-- Enabling LOGIN and provisioning Cloudflare secret require a separate, secure authorization.