Barazo AppView backend
barazo.forum
1-- Seed platform age_confirmation field for all initialized communities
2-- that don't already have an admin-created age_confirmation field.
3-- NOTE: assumes single-community mode (P1/P2). Multi-community (P3)
4-- will need per-community unique IDs.
5INSERT INTO community_onboarding_fields (
6 id, community_did, field_type, label, description,
7 is_mandatory, sort_order, source, config, created_at, updated_at
8)
9SELECT
10 'platform:age_confirmation',
11 cs.community_did,
12 'age_confirmation',
13 'Age Declaration',
14 'Please select your age bracket. This determines which content is available to you.',
15 true,
16 -1,
17 'platform',
18 NULL,
19 NOW(),
20 NOW()
21FROM community_settings cs
22WHERE cs.initialized = true
23 AND NOT EXISTS (
24 SELECT 1 FROM community_onboarding_fields cof
25 WHERE cof.community_did = cs.community_did
26 AND cof.field_type = 'age_confirmation'
27 )
28ON CONFLICT DO NOTHING;
29
30-- Backfill user_onboarding_responses for users who already declared age
31-- via the virtual system field (data lives in user_preferences.declared_age).
32INSERT INTO user_onboarding_responses (did, community_did, field_id, response, completed_at)
33SELECT
34 up.did,
35 cs.community_did,
36 'platform:age_confirmation',
37 to_jsonb(up.declared_age),
38 COALESCE(up.updated_at, NOW())
39FROM user_preferences up
40CROSS JOIN community_settings cs
41WHERE up.declared_age IS NOT NULL
42 AND cs.initialized = true
43 AND EXISTS (
44 SELECT 1 FROM community_onboarding_fields cof
45 WHERE cof.id = 'platform:age_confirmation'
46 AND cof.community_did = cs.community_did
47 )
48ON CONFLICT DO NOTHING;