···11+create table "public"."entities" (
22+ "id" uuid not null default gen_random_uuid(),
33+ "created_at" timestamp with time zone not null default now()
44+);
55+66+77+alter table "public"."entities" enable row level security;
88+99+create table "public"."facts" (
1010+ "id" uuid not null default gen_random_uuid(),
1111+ "entity" uuid not null,
1212+ "attribute" text not null,
1313+ "data" jsonb not null,
1414+ "created_at" timestamp without time zone not null default now(),
1515+ "updated_at" timestamp without time zone,
1616+ "version" bigint not null default '0'::bigint
1717+);
1818+1919+2020+alter table "public"."facts" enable row level security;
2121+2222+create table "public"."replicache_clients" (
2323+ "client_id" text not null,
2424+ "client_group" text not null,
2525+ "last_mutation" bigint not null
2626+);
2727+2828+2929+alter table "public"."replicache_clients" enable row level security;
3030+3131+CREATE UNIQUE INDEX client_pkey ON public.replicache_clients USING btree (client_id);
3232+3333+CREATE UNIQUE INDEX entities_pkey ON public.entities USING btree (id);
3434+3535+CREATE INDEX facts_expr_idx ON public.facts USING btree (((data ->> 'value'::text))) WHERE ((data ->> 'type'::text) = 'reference'::text);
3636+3737+CREATE UNIQUE INDEX facts_pkey ON public.facts USING btree (id);
3838+3939+alter table "public"."entities" add constraint "entities_pkey" PRIMARY KEY using index "entities_pkey";
4040+4141+alter table "public"."facts" add constraint "facts_pkey" PRIMARY KEY using index "facts_pkey";
4242+4343+alter table "public"."replicache_clients" add constraint "client_pkey" PRIMARY KEY using index "client_pkey";
4444+4545+alter table "public"."facts" add constraint "facts_entity_fkey" FOREIGN KEY (entity) REFERENCES entities(id) ON UPDATE RESTRICT ON DELETE CASCADE not valid;
4646+4747+alter table "public"."facts" validate constraint "facts_entity_fkey";
4848+4949+set check_function_bodies = off;
5050+5151+CREATE OR REPLACE FUNCTION public.get_facts(root uuid)
5252+ RETURNS SETOF facts
5353+ LANGUAGE sql
5454+AS $function$
5555+ WITH RECURSIVE all_facts as (
5656+ select
5757+ *
5858+ from
5959+ facts
6060+ where
6161+ entity = root
6262+ union
6363+ select
6464+ f.*
6565+ from
6666+ facts f
6767+ inner join all_facts f1 on (
6868+ uuid(f1.data ->> 'value') = f.entity
6969+ ) where f1.data ->> 'type' = 'reference'
7070+ )
7171+select
7272+ *
7373+from
7474+ all_facts;
7575+ $function$
7676+;
7777+7878+grant delete on table "public"."entities" to "anon";
7979+8080+grant insert on table "public"."entities" to "anon";
8181+8282+grant references on table "public"."entities" to "anon";
8383+8484+grant select on table "public"."entities" to "anon";
8585+8686+grant trigger on table "public"."entities" to "anon";
8787+8888+grant truncate on table "public"."entities" to "anon";
8989+9090+grant update on table "public"."entities" to "anon";
9191+9292+grant delete on table "public"."entities" to "authenticated";
9393+9494+grant insert on table "public"."entities" to "authenticated";
9595+9696+grant references on table "public"."entities" to "authenticated";
9797+9898+grant select on table "public"."entities" to "authenticated";
9999+100100+grant trigger on table "public"."entities" to "authenticated";
101101+102102+grant truncate on table "public"."entities" to "authenticated";
103103+104104+grant update on table "public"."entities" to "authenticated";
105105+106106+grant delete on table "public"."entities" to "service_role";
107107+108108+grant insert on table "public"."entities" to "service_role";
109109+110110+grant references on table "public"."entities" to "service_role";
111111+112112+grant select on table "public"."entities" to "service_role";
113113+114114+grant trigger on table "public"."entities" to "service_role";
115115+116116+grant truncate on table "public"."entities" to "service_role";
117117+118118+grant update on table "public"."entities" to "service_role";
119119+120120+grant delete on table "public"."facts" to "anon";
121121+122122+grant insert on table "public"."facts" to "anon";
123123+124124+grant references on table "public"."facts" to "anon";
125125+126126+grant select on table "public"."facts" to "anon";
127127+128128+grant trigger on table "public"."facts" to "anon";
129129+130130+grant truncate on table "public"."facts" to "anon";
131131+132132+grant update on table "public"."facts" to "anon";
133133+134134+grant delete on table "public"."facts" to "authenticated";
135135+136136+grant insert on table "public"."facts" to "authenticated";
137137+138138+grant references on table "public"."facts" to "authenticated";
139139+140140+grant select on table "public"."facts" to "authenticated";
141141+142142+grant trigger on table "public"."facts" to "authenticated";
143143+144144+grant truncate on table "public"."facts" to "authenticated";
145145+146146+grant update on table "public"."facts" to "authenticated";
147147+148148+grant delete on table "public"."facts" to "service_role";
149149+150150+grant insert on table "public"."facts" to "service_role";
151151+152152+grant references on table "public"."facts" to "service_role";
153153+154154+grant select on table "public"."facts" to "service_role";
155155+156156+grant trigger on table "public"."facts" to "service_role";
157157+158158+grant truncate on table "public"."facts" to "service_role";
159159+160160+grant update on table "public"."facts" to "service_role";
161161+162162+grant delete on table "public"."replicache_clients" to "anon";
163163+164164+grant insert on table "public"."replicache_clients" to "anon";
165165+166166+grant references on table "public"."replicache_clients" to "anon";
167167+168168+grant select on table "public"."replicache_clients" to "anon";
169169+170170+grant trigger on table "public"."replicache_clients" to "anon";
171171+172172+grant truncate on table "public"."replicache_clients" to "anon";
173173+174174+grant update on table "public"."replicache_clients" to "anon";
175175+176176+grant delete on table "public"."replicache_clients" to "authenticated";
177177+178178+grant insert on table "public"."replicache_clients" to "authenticated";
179179+180180+grant references on table "public"."replicache_clients" to "authenticated";
181181+182182+grant select on table "public"."replicache_clients" to "authenticated";
183183+184184+grant trigger on table "public"."replicache_clients" to "authenticated";
185185+186186+grant truncate on table "public"."replicache_clients" to "authenticated";
187187+188188+grant update on table "public"."replicache_clients" to "authenticated";
189189+190190+grant delete on table "public"."replicache_clients" to "service_role";
191191+192192+grant insert on table "public"."replicache_clients" to "service_role";
193193+194194+grant references on table "public"."replicache_clients" to "service_role";
195195+196196+grant select on table "public"."replicache_clients" to "service_role";
197197+198198+grant trigger on table "public"."replicache_clients" to "service_role";
199199+200200+grant truncate on table "public"."replicache_clients" to "service_role";
201201+202202+grant update on table "public"."replicache_clients" to "service_role";