Barazo AppView backend
barazo.forum
1CREATE TABLE "community_rules" (
2 "id" serial PRIMARY KEY NOT NULL,
3 "community_did" text NOT NULL,
4 "title" text NOT NULL,
5 "description" text NOT NULL,
6 "display_order" integer NOT NULL,
7 "created_at" timestamp with time zone DEFAULT now() NOT NULL,
8 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
9 "archived_at" timestamp with time zone
10);
11--> statement-breakpoint
12ALTER TABLE "community_rules" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
13CREATE TABLE "community_rule_versions" (
14 "id" serial PRIMARY KEY NOT NULL,
15 "rule_id" integer NOT NULL,
16 "title" text NOT NULL,
17 "description" text NOT NULL,
18 "created_at" timestamp with time zone DEFAULT now() NOT NULL
19);
20--> statement-breakpoint
21ALTER TABLE "community_rule_versions" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
22CREATE TABLE "moderation_action_rules" (
23 "id" serial PRIMARY KEY NOT NULL,
24 "warning_id" integer,
25 "moderation_action_id" integer,
26 "rule_version_id" integer NOT NULL,
27 "community_did" text NOT NULL,
28 CONSTRAINT "exactly_one_parent" CHECK ((warning_id IS NOT NULL AND moderation_action_id IS NULL) OR (warning_id IS NULL AND moderation_action_id IS NOT NULL))
29);
30--> statement-breakpoint
31ALTER TABLE "moderation_action_rules" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
32CREATE INDEX "community_rules_community_did_idx" ON "community_rules" USING btree ("community_did");--> statement-breakpoint
33CREATE INDEX "community_rules_display_order_idx" ON "community_rules" USING btree ("display_order");--> statement-breakpoint
34CREATE INDEX "community_rule_versions_rule_id_idx" ON "community_rule_versions" USING btree ("rule_id");--> statement-breakpoint
35CREATE INDEX "mod_action_rules_warning_id_idx" ON "moderation_action_rules" USING btree ("warning_id");--> statement-breakpoint
36CREATE INDEX "mod_action_rules_moderation_action_id_idx" ON "moderation_action_rules" USING btree ("moderation_action_id");--> statement-breakpoint
37CREATE INDEX "mod_action_rules_rule_version_id_idx" ON "moderation_action_rules" USING btree ("rule_version_id");--> statement-breakpoint
38CREATE INDEX "mod_action_rules_community_did_idx" ON "moderation_action_rules" USING btree ("community_did");--> statement-breakpoint
39CREATE POLICY "tenant_isolation" ON "community_rules" AS PERMISSIVE FOR ALL TO "barazo_app" USING (community_did = current_setting('app.current_community_did', true)) WITH CHECK (community_did = current_setting('app.current_community_did', true));--> statement-breakpoint
40CREATE POLICY "tenant_isolation" ON "community_rule_versions" AS PERMISSIVE FOR ALL TO "barazo_app" USING (rule_id IN (SELECT id FROM community_rules WHERE community_did = current_setting('app.current_community_did', true))) WITH CHECK (rule_id IN (SELECT id FROM community_rules WHERE community_did = current_setting('app.current_community_did', true)));--> statement-breakpoint
41CREATE POLICY "tenant_isolation" ON "moderation_action_rules" AS PERMISSIVE FOR ALL TO "barazo_app" USING (community_did = current_setting('app.current_community_did', true)) WITH CHECK (community_did = current_setting('app.current_community_did', true));