@nextblock-cms/db 0.8.11 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
-- 00000000000030_setup_system_configuration.sql
|
|
2
|
+
-- First-Boot Setup Wizard: global system configuration.
|
|
3
|
+
--
|
|
4
|
+
-- Adds a dedicated, RLS-locked `system_configuration` table that holds settings the
|
|
5
|
+
-- browser /setup wizard manages and that don't belong in the public key-value
|
|
6
|
+
-- `site_settings` store. It is a singleton (exactly one row, id = 1).
|
|
7
|
+
--
|
|
8
|
+
-- Shape:
|
|
9
|
+
-- auto_accept_signups boolean -- when true, new public sign-ups skip outbound email
|
|
10
|
+
-- verification (the signup route uses a service-role
|
|
11
|
+
-- admin.createUser({ email_confirm: true }) path).
|
|
12
|
+
-- settings jsonb -- forward-compatible catch-all for future feature
|
|
13
|
+
-- toggles ({} by default). Do NOT store true secrets
|
|
14
|
+
-- here (Turnstile/AI secrets keep living in their
|
|
15
|
+
-- existing site_settings sensitive keys).
|
|
16
|
+
--
|
|
17
|
+
-- Access is locked to the ADMIN role for normal clients (NextBlock has no separate
|
|
18
|
+
-- "super-admin" tier — ADMIN is the top level). The service_role retains full access
|
|
19
|
+
-- so the wizard can seed/read it before any admin exists.
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS public.system_configuration (
|
|
22
|
+
id integer PRIMARY KEY DEFAULT 1,
|
|
23
|
+
auto_accept_signups boolean NOT NULL DEFAULT false,
|
|
24
|
+
settings jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
25
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
26
|
+
CONSTRAINT system_configuration_singleton CHECK (id = 1)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
COMMENT ON TABLE public.system_configuration IS
|
|
30
|
+
'Singleton (id = 1) of global setup-wizard configuration. ADMIN-only via RLS; never store secrets in settings.';
|
|
31
|
+
|
|
32
|
+
-- Seed the single row so reads always find it.
|
|
33
|
+
INSERT INTO public.system_configuration (id, auto_accept_signups, settings)
|
|
34
|
+
VALUES (1, false, '{}'::jsonb)
|
|
35
|
+
ON CONFLICT (id) DO NOTHING;
|
|
36
|
+
|
|
37
|
+
ALTER TABLE public.system_configuration ENABLE ROW LEVEL SECURITY;
|
|
38
|
+
|
|
39
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON public.system_configuration TO authenticated;
|
|
40
|
+
GRANT ALL ON public.system_configuration TO service_role;
|
|
41
|
+
|
|
42
|
+
-- ADMIN-only for every operation by authenticated clients.
|
|
43
|
+
DROP POLICY IF EXISTS system_configuration_admin_select ON public.system_configuration;
|
|
44
|
+
CREATE POLICY system_configuration_admin_select
|
|
45
|
+
ON public.system_configuration
|
|
46
|
+
FOR SELECT
|
|
47
|
+
TO authenticated
|
|
48
|
+
USING ((SELECT public.get_current_user_role()) = 'ADMIN');
|
|
49
|
+
|
|
50
|
+
DROP POLICY IF EXISTS system_configuration_admin_insert ON public.system_configuration;
|
|
51
|
+
CREATE POLICY system_configuration_admin_insert
|
|
52
|
+
ON public.system_configuration
|
|
53
|
+
FOR INSERT
|
|
54
|
+
TO authenticated
|
|
55
|
+
WITH CHECK ((SELECT public.get_current_user_role()) = 'ADMIN');
|
|
56
|
+
|
|
57
|
+
DROP POLICY IF EXISTS system_configuration_admin_update ON public.system_configuration;
|
|
58
|
+
CREATE POLICY system_configuration_admin_update
|
|
59
|
+
ON public.system_configuration
|
|
60
|
+
FOR UPDATE
|
|
61
|
+
TO authenticated
|
|
62
|
+
USING ((SELECT public.get_current_user_role()) = 'ADMIN')
|
|
63
|
+
WITH CHECK ((SELECT public.get_current_user_role()) = 'ADMIN');
|
|
64
|
+
|
|
65
|
+
DROP POLICY IF EXISTS system_configuration_admin_delete ON public.system_configuration;
|
|
66
|
+
CREATE POLICY system_configuration_admin_delete
|
|
67
|
+
ON public.system_configuration
|
|
68
|
+
FOR DELETE
|
|
69
|
+
TO authenticated
|
|
70
|
+
USING ((SELECT public.get_current_user_role()) = 'ADMIN');
|
|
71
|
+
|
|
72
|
+
-- Service role bypasses the ADMIN checks (used by the wizard before an admin exists,
|
|
73
|
+
-- and by the signup route to read auto_accept_signups as an anonymous visitor).
|
|
74
|
+
DROP POLICY IF EXISTS system_configuration_service_role_all ON public.system_configuration;
|
|
75
|
+
CREATE POLICY system_configuration_service_role_all
|
|
76
|
+
ON public.system_configuration
|
|
77
|
+
FOR ALL
|
|
78
|
+
TO service_role
|
|
79
|
+
USING (true)
|
|
80
|
+
WITH CHECK (true);
|