From e7b60c0c175fdbc3f12ab68d70f9de88881b0ebd Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Sat, 28 Feb 2026 15:39:16 +0100 Subject: [PATCH] Update squashed SQLs. --- public/supabase_broker/squashed.sql | 671 ++++++++++++++++++-- supabase_artemis/squashed.sql | 906 ++++++++++++++++++++++++++-- 2 files changed, 1457 insertions(+), 120 deletions(-) diff --git a/public/supabase_broker/squashed.sql b/public/supabase_broker/squashed.sql index 117c39f5..bd6a2e3f 100644 --- a/public/supabase_broker/squashed.sql +++ b/public/supabase_broker/squashed.sql @@ -1,4 +1,5 @@ + SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0; @@ -10,32 +11,73 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; -CREATE EXTENSION IF NOT EXISTS "pg_cron" WITH SCHEMA "extensions"; + +CREATE EXTENSION IF NOT EXISTS "pg_cron" WITH SCHEMA "pg_catalog"; + + + + + CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions"; -CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium"; -CREATE SCHEMA IF NOT EXISTS "supabase_migrations"; -ALTER SCHEMA "supabase_migrations" OWNER TO "postgres"; + + + +COMMENT ON SCHEMA "public" IS 'standard public schema'; + + CREATE SCHEMA IF NOT EXISTS "toit_artemis"; + ALTER SCHEMA "toit_artemis" OWNER TO "postgres"; + CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql"; + + + + + CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "pgcrypto" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "pgjwt" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "supabase_vault" WITH SCHEMA "vault"; + + + + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions"; + + + + + CREATE TYPE "toit_artemis"."pod" AS ( "id" "uuid", "pod_description_id" bigint, @@ -44,16 +86,20 @@ CREATE TYPE "toit_artemis"."pod" AS ( "tags" "text"[] ); + ALTER TYPE "toit_artemis"."pod" OWNER TO "postgres"; + CREATE TYPE "toit_artemis"."poddescription" AS ( "id" bigint, "name" "text", "description" "text" ); + ALTER TYPE "toit_artemis"."poddescription" OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_old_events"() RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -63,8 +109,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_old_events"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -77,8 +125,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -89,8 +139,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -103,8 +155,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) RETURNS TABLE("device_id" "uuid", "goal" "jsonb", "state" "jsonb") LANGUAGE "plpgsql" AS $$ @@ -125,8 +179,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone DEFAULT '1970-01-01 00:00:00+00'::timestamp with time zone) RETURNS TABLE("device_id" "uuid", "type" "text", "ts" timestamp with time zone, "data" "jsonb") LANGUAGE "plpgsql" AS $$ @@ -188,8 +244,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -199,8 +257,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" AS $$ @@ -209,8 +269,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -230,8 +292,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -243,8 +307,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -292,8 +358,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) RETURNS SETOF "toit_artemis"."pod" LANGUAGE "plpgsql" AS $$ @@ -321,8 +389,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) RETURNS SETOF "toit_artemis"."pod" LANGUAGE "plpgsql" AS $$ @@ -350,8 +420,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") RETURNS TABLE("pod_id" "uuid", "name" "text", "revision" integer, "tag" "text") LANGUAGE "plpgsql" AS $$ @@ -376,8 +448,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" AS $$ @@ -386,8 +460,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -417,16 +493,20 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."max_event_age"() RETURNS interval LANGUAGE "sql" IMMUTABLE AS $$ SELECT INTERVAL '30 days'; $$; + ALTER FUNCTION "toit_artemis"."max_event_age"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -436,8 +516,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -446,8 +528,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") RETURNS "void" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -457,8 +541,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -470,8 +556,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -485,8 +573,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -510,8 +600,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") RETURNS "void" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -523,8 +615,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") RETURNS bigint LANGUAGE "plpgsql" AS $$ @@ -541,27 +635,23 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") OWNER TO "postgres"; SET default_tablespace = ''; SET default_table_access_method = "heap"; -CREATE TABLE IF NOT EXISTS "supabase_migrations"."schema_migrations" ( - "version" "text" NOT NULL, - "statements" "text"[], - "name" "text" -); - -ALTER TABLE "supabase_migrations"."schema_migrations" OWNER TO "postgres"; CREATE TABLE IF NOT EXISTS "toit_artemis"."devices" ( "id" "uuid" NOT NULL, "state" "jsonb" NOT NULL ); + ALTER TABLE "toit_artemis"."devices" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "toit_artemis"."events" ( "id" integer NOT NULL, "device_id" "uuid" NOT NULL, @@ -570,8 +660,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."events" ( "data" "jsonb" NOT NULL ); + ALTER TABLE "toit_artemis"."events" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."events_id_seq" AS integer START WITH 1 @@ -580,17 +672,23 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."events_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."events_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."events_id_seq" OWNED BY "toit_artemis"."events"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."goals" ( "device_id" "uuid" NOT NULL, "goal" "jsonb" ); + ALTER TABLE "toit_artemis"."goals" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_descriptions" ( "id" bigint NOT NULL, "fleet_id" "uuid" NOT NULL, @@ -600,8 +698,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_descriptions" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pod_descriptions" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_descriptions_id_seq" START WITH 1 INCREMENT BY 1 @@ -609,10 +709,14 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_descriptions_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."pod_descriptions_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."pod_descriptions_id_seq" OWNED BY "toit_artemis"."pod_descriptions"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_tags" ( "id" bigint NOT NULL, "pod_id" "uuid" NOT NULL, @@ -622,8 +726,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_tags" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pod_tags" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_tags_id_seq" START WITH 1 INCREMENT BY 1 @@ -631,10 +737,14 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_tags_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."pod_tags_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."pod_tags_id_seq" OWNED BY "toit_artemis"."pod_tags"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."pods" ( "id" "uuid" NOT NULL, "fleet_id" "uuid" NOT NULL, @@ -643,273 +753,706 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pods" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pods" OWNER TO "postgres"; + ALTER TABLE ONLY "toit_artemis"."events" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."events_id_seq"'::"regclass"); + + ALTER TABLE ONLY "toit_artemis"."pod_descriptions" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."pod_descriptions_id_seq"'::"regclass"); + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."pod_tags_id_seq"'::"regclass"); -ALTER TABLE ONLY "supabase_migrations"."schema_migrations" - ADD CONSTRAINT "schema_migrations_pkey" PRIMARY KEY ("version"); + ALTER TABLE ONLY "toit_artemis"."devices" ADD CONSTRAINT "devices_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."events" ADD CONSTRAINT "events_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."goals" ADD CONSTRAINT "goals_pkey" PRIMARY KEY ("device_id"); + + ALTER TABLE ONLY "toit_artemis"."pod_descriptions" ADD CONSTRAINT "pod_descriptions_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."pods" ADD CONSTRAINT "pods_pkey" PRIMARY KEY ("id", "fleet_id"); + + CREATE INDEX "events_device_id" ON "toit_artemis"."events" USING "btree" ("device_id"); + + CREATE INDEX "events_device_id_timestamp_idx" ON "toit_artemis"."events" USING "btree" ("device_id", "timestamp" DESC); + + CREATE INDEX "events_device_id_type_timestamp_idx" ON "toit_artemis"."events" USING "btree" ("device_id", "type", "timestamp" DESC); + + CREATE INDEX "pod_descriptions_name_idx" ON "toit_artemis"."pod_descriptions" USING "btree" ("name"); + + CREATE UNIQUE INDEX "pod_tags_pod_description_id_tag_idx" ON "toit_artemis"."pod_tags" USING "btree" ("pod_description_id", "tag"); + + CREATE INDEX "pod_tags_pod_id_idx" ON "toit_artemis"."pod_tags" USING "btree" ("pod_id"); + + CREATE INDEX "pod_tags_tag_idx" ON "toit_artemis"."pod_tags" USING "btree" ("tag"); + + CREATE INDEX "pods_created_at_idx" ON "toit_artemis"."pods" USING "btree" ("created_at" DESC); + + CREATE UNIQUE INDEX "pods_fleet_id_name_idx" ON "toit_artemis"."pod_descriptions" USING "btree" ("fleet_id", "name"); + + CREATE INDEX "pods_id_idx" ON "toit_artemis"."pods" USING "btree" ("id"); + + CREATE INDEX "pods_pod_description_id_created_at_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id", "created_at" DESC); + + CREATE INDEX "pods_pod_description_id_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id"); + + CREATE UNIQUE INDEX "pods_pod_description_id_revision_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id", "revision"); + + ALTER TABLE ONLY "toit_artemis"."events" ADD CONSTRAINT "events_device_id_fkey" FOREIGN KEY ("device_id") REFERENCES "toit_artemis"."devices"("id") ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."goals" ADD CONSTRAINT "goals_device_id_fkey" FOREIGN KEY ("device_id") REFERENCES "toit_artemis"."devices"("id") ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pod_description_id_fkey" FOREIGN KEY ("pod_description_id") REFERENCES "toit_artemis"."pod_descriptions"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pod_id_fleet_id_fkey" FOREIGN KEY ("pod_id", "fleet_id") REFERENCES "toit_artemis"."pods"("id", "fleet_id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pods" ADD CONSTRAINT "pods_pod_description_id_fkey" FOREIGN KEY ("pod_description_id") REFERENCES "toit_artemis"."pod_descriptions"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + CREATE POLICY "Authenticated have full access to devices table" ON "toit_artemis"."devices" TO "authenticated" USING (true) WITH CHECK (true); + + CREATE POLICY "Authenticated have full access to events table" ON "toit_artemis"."events" TO "authenticated" USING (true) WITH CHECK (true); + + CREATE POLICY "Authenticated have full access to goals table" ON "toit_artemis"."goals" TO "authenticated" USING (true) WITH CHECK (true); + + CREATE POLICY "Authenticated have full access to pod_descriptions table" ON "toit_artemis"."pod_descriptions" TO "authenticated" USING (true) WITH CHECK (true); + + CREATE POLICY "Authenticated have full access to pod_tags table" ON "toit_artemis"."pod_tags" TO "authenticated" USING (true) WITH CHECK (true); + + CREATE POLICY "Authenticated have full access to pods table" ON "toit_artemis"."pods" TO "authenticated" USING (true) WITH CHECK (true); + + ALTER TABLE "toit_artemis"."devices" ENABLE ROW LEVEL SECURITY; + ALTER TABLE "toit_artemis"."events" ENABLE ROW LEVEL SECURITY; + ALTER TABLE "toit_artemis"."goals" ENABLE ROW LEVEL SECURITY; + ALTER TABLE "toit_artemis"."pod_descriptions" ENABLE ROW LEVEL SECURITY; + ALTER TABLE "toit_artemis"."pod_tags" ENABLE ROW LEVEL SECURITY; + ALTER TABLE "toit_artemis"."pods" ENABLE ROW LEVEL SECURITY; + + + +ALTER PUBLICATION "supabase_realtime" OWNER TO "postgres"; + + + + + + + + GRANT USAGE ON SCHEMA "public" TO "postgres"; GRANT USAGE ON SCHEMA "public" TO "anon"; GRANT USAGE ON SCHEMA "public" TO "authenticated"; GRANT USAGE ON SCHEMA "public" TO "service_role"; + + GRANT USAGE ON SCHEMA "toit_artemis" TO "anon"; GRANT USAGE ON SCHEMA "toit_artemis" TO "authenticated"; GRANT USAGE ON SCHEMA "toit_artemis" TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "authenticated"; -GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "service_role"; -GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "anon"; -GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "authenticated"; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "authenticated"; +GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "service_role"; + + + +GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "anon"; +GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "service_role"; + + + + + + + + + + + + + + + + + + + + + + + GRANT ALL ON TABLE "toit_artemis"."devices" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."devices" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."devices" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."events" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."events" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."events" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."goals" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."goals" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."goals" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pods" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pods" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pods" TO "service_role"; + + + + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "service_role"; + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "service_role"; + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "service_role"; -RESET ALL; + + + + + + + + + + + + + + + + + + + + + + + + + + + +-- +-- Dumped schema changes for auth and storage +-- + +CREATE POLICY "Authenticated have full access to pod storage" ON "storage"."objects" TO "authenticated" USING (("bucket_id" = 'toit-artemis-pods'::"text")) WITH CHECK (("bucket_id" = 'toit-artemis-pods'::"text")); + + + +CREATE POLICY "Authenticated have full access to storage" ON "storage"."objects" TO "authenticated" USING (("bucket_id" = 'toit-artemis-assets'::"text")) WITH CHECK (("bucket_id" = 'toit-artemis-assets'::"text")); + + + diff --git a/supabase_artemis/squashed.sql b/supabase_artemis/squashed.sql index 49e41546..5b9e38a4 100644 --- a/supabase_artemis/squashed.sql +++ b/supabase_artemis/squashed.sql @@ -1,4 +1,5 @@ + SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0; @@ -10,39 +11,82 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; -CREATE EXTENSION IF NOT EXISTS "pg_cron" WITH SCHEMA "extensions"; + +CREATE EXTENSION IF NOT EXISTS "pg_cron" WITH SCHEMA "pg_catalog"; + + + + + CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions"; -CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium"; -CREATE SCHEMA IF NOT EXISTS "supabase_migrations"; -ALTER SCHEMA "supabase_migrations" OWNER TO "postgres"; + + + +COMMENT ON SCHEMA "public" IS 'standard public schema'; + + CREATE SCHEMA IF NOT EXISTS "toit_artemis"; + ALTER SCHEMA "toit_artemis" OWNER TO "postgres"; + CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql"; + + + + + CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "pgcrypto" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "pgjwt" WITH SCHEMA "extensions"; + + + + + CREATE EXTENSION IF NOT EXISTS "supabase_vault" WITH SCHEMA "vault"; + + + + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions"; + + + + + CREATE TYPE "public"."role" AS ENUM ( 'admin', 'member' ); + ALTER TYPE "public"."role" OWNER TO "postgres"; + CREATE TYPE "toit_artemis"."pod" AS ( "id" "uuid", "pod_description_id" bigint, @@ -51,16 +95,20 @@ CREATE TYPE "toit_artemis"."pod" AS ( "tags" "text"[] ); + ALTER TYPE "toit_artemis"."pod" OWNER TO "postgres"; + CREATE TYPE "toit_artemis"."poddescription" AS ( "id" bigint, "name" "text", "description" "text" ); + ALTER TYPE "toit_artemis"."poddescription" OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."create_admin_for_new_organization"() RETURNS "trigger" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -73,8 +121,10 @@ CREATE OR REPLACE FUNCTION "public"."create_admin_for_new_organization"() RETURN END; $$; + ALTER FUNCTION "public"."create_admin_for_new_organization"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."create_profile_for_new_user"() RETURNS "trigger" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -89,8 +139,10 @@ CREATE OR REPLACE FUNCTION "public"."create_profile_for_new_user"() RETURNS "tri END; $$; + ALTER FUNCTION "public"."create_profile_for_new_user"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."email_for_id"("_id" "uuid") RETURNS "text" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -103,8 +155,10 @@ BEGIN END; $$; + ALTER FUNCTION "public"."email_for_id"("_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."is_artemis_admin"() RETURNS boolean LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -113,8 +167,10 @@ BEGIN END; $$; + ALTER FUNCTION "public"."is_artemis_admin"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "uuid") RETURNS boolean LANGUAGE "sql" SECURITY DEFINER AS $$ @@ -127,8 +183,10 @@ CREATE OR REPLACE FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "u ) $$; + ALTER FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."is_auth_in_org_of_alias"("_device_id" "uuid") RETURNS boolean LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -139,8 +197,10 @@ BEGIN END; $$; + ALTER FUNCTION "public"."is_auth_in_org_of_alias"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."is_auth_in_same_org_as"("_id" "uuid") RETURNS boolean LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -158,8 +218,10 @@ BEGIN END; $$; + ALTER FUNCTION "public"."is_auth_in_same_org_as"("_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "public"."is_auth_member_of_org"("_organization_id" "uuid") RETURNS boolean LANGUAGE "sql" SECURITY DEFINER AS $$ @@ -171,8 +233,10 @@ CREATE OR REPLACE FUNCTION "public"."is_auth_member_of_org"("_organization_id" " ) $$; + ALTER FUNCTION "public"."is_auth_member_of_org"("_organization_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_old_events"() RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -182,8 +246,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_old_events"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -196,8 +262,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -208,8 +276,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -222,8 +292,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) RETURNS TABLE("device_id" "uuid", "goal" "jsonb", "state" "jsonb") LANGUAGE "plpgsql" AS $$ @@ -244,8 +316,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone DEFAULT '1970-01-01 00:00:00+00'::timestamp with time zone) RETURNS TABLE("device_id" "uuid", "type" "text", "ts" timestamp with time zone, "data" "jsonb") LANGUAGE "plpgsql" AS $$ @@ -307,8 +381,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -318,8 +394,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" AS $$ @@ -328,8 +406,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -349,8 +429,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -362,8 +444,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) RETURNS SETOF "toit_artemis"."poddescription" LANGUAGE "plpgsql" AS $$ @@ -411,8 +495,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) RETURNS SETOF "toit_artemis"."pod" LANGUAGE "plpgsql" AS $$ @@ -440,8 +526,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) RETURNS SETOF "toit_artemis"."pod" LANGUAGE "plpgsql" AS $$ @@ -469,8 +557,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") RETURNS TABLE("pod_id" "uuid", "name" "text", "revision" integer, "tag" "text") LANGUAGE "plpgsql" AS $$ @@ -495,8 +585,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") RETURNS "json" LANGUAGE "plpgsql" AS $$ @@ -505,8 +597,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -536,16 +630,20 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."max_event_age"() RETURNS interval LANGUAGE "sql" IMMUTABLE AS $$ SELECT INTERVAL '30 days'; $$; + ALTER FUNCTION "toit_artemis"."max_event_age"() OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -555,8 +653,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -565,8 +665,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") RETURNS "void" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -576,8 +678,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -589,8 +693,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -604,8 +710,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) RETURNS "void" LANGUAGE "plpgsql" AS $$ @@ -629,8 +737,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") RETURNS "void" LANGUAGE "plpgsql" SECURITY DEFINER AS $$ @@ -642,8 +752,10 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") OWNER TO "postgres"; + CREATE OR REPLACE FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") RETURNS bigint LANGUAGE "plpgsql" AS $$ @@ -660,12 +772,14 @@ BEGIN END; $$; + ALTER FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") OWNER TO "postgres"; SET default_tablespace = ''; SET default_table_access_method = "heap"; + CREATE TABLE IF NOT EXISTS "public"."devices" ( "id" "uuid" DEFAULT "extensions"."uuid_generate_v4"() NOT NULL, "created_at" timestamp with time zone DEFAULT "now"(), @@ -673,8 +787,10 @@ CREATE TABLE IF NOT EXISTS "public"."devices" ( "organization_id" "uuid" ); + ALTER TABLE "public"."devices" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."events" ( "id" bigint NOT NULL, "created_at" timestamp with time zone DEFAULT "now"(), @@ -682,8 +798,10 @@ CREATE TABLE IF NOT EXISTS "public"."events" ( "data" "jsonb" NOT NULL ); + ALTER TABLE "public"."events" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."organizations" ( "id" "uuid" DEFAULT "extensions"."uuid_generate_v4"() NOT NULL, "created_at" timestamp with time zone DEFAULT "now"(), @@ -691,8 +809,10 @@ CREATE TABLE IF NOT EXISTS "public"."organizations" ( "owner_id" "uuid" DEFAULT "auth"."uid"() ); + ALTER TABLE "public"."organizations" OWNER TO "postgres"; + CREATE OR REPLACE VIEW "public"."active_devices" WITH ("security_invoker"='on') AS WITH "max_created_events" AS ( SELECT "events"."device_id", @@ -704,7 +824,7 @@ CREATE OR REPLACE VIEW "public"."active_devices" WITH ("security_invoker"='on') SELECT "events"."device_id", "min"("events"."created_at") AS "min_created_at" FROM "public"."events" - WHERE ("events"."device_id" IN (SELECT "max_created_events"."device_id" + WHERE ("events"."device_id" IN ( SELECT "max_created_events"."device_id" FROM "max_created_events")) GROUP BY "events"."device_id" ) @@ -719,22 +839,28 @@ CREATE OR REPLACE VIEW "public"."active_devices" WITH ("security_invoker"='on') GROUP BY "o"."name" ORDER BY "o"."name"; + ALTER TABLE "public"."active_devices" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."admins" ( "id" "uuid" NOT NULL ); + ALTER TABLE "public"."admins" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."profiles" ( "id" "uuid" NOT NULL, "created_at" timestamp with time zone DEFAULT "now"(), "name" character varying NOT NULL ); + ALTER TABLE "public"."profiles" OWNER TO "postgres"; + CREATE OR REPLACE VIEW "public"."admin_with_profile" WITH ("security_invoker"='on') AS SELECT "p"."id", "p"."created_at", @@ -745,16 +871,20 @@ CREATE OR REPLACE VIEW "public"."admin_with_profile" WITH ("security_invoker"='o "auth"."users" "u" WHERE (("a"."id" = "p"."id") AND ("a"."id" = "u"."id")); + ALTER TABLE "public"."admin_with_profile" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."artemis_services" ( "id" bigint NOT NULL, "version" "text" NOT NULL, "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "public"."artemis_services" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "public"."artemis_services_id_seq" START WITH 1 INCREMENT BY 1 @@ -762,10 +892,14 @@ CREATE SEQUENCE IF NOT EXISTS "public"."artemis_services_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "public"."artemis_services_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "public"."artemis_services_id_seq" OWNED BY "public"."artemis_services"."id"; + + CREATE SEQUENCE IF NOT EXISTS "public"."events_id_seq" START WITH 1 INCREMENT BY 1 @@ -773,10 +907,14 @@ CREATE SEQUENCE IF NOT EXISTS "public"."events_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "public"."events_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "public"."events_id_seq" OWNED BY "public"."events"."id"; + + CREATE OR REPLACE VIEW "public"."profiles_with_email" WITH ("security_invoker"='on') AS SELECT "p"."id", "p"."created_at", @@ -784,8 +922,10 @@ CREATE OR REPLACE VIEW "public"."profiles_with_email" WITH ("security_invoker"=' "public"."email_for_id"("p"."id") AS "email" FROM "public"."profiles" "p"; + ALTER TABLE "public"."profiles_with_email" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."roles" ( "id" bigint NOT NULL, "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, @@ -794,8 +934,10 @@ CREATE TABLE IF NOT EXISTS "public"."roles" ( "role" "public"."role" DEFAULT 'member'::"public"."role" NOT NULL ); + ALTER TABLE "public"."roles" OWNER TO "postgres"; + CREATE OR REPLACE VIEW "public"."roles_with_profile" WITH ("security_invoker"='on') AS SELECT "r"."organization_id", "o"."name" AS "organization_name", @@ -809,8 +951,10 @@ CREATE OR REPLACE VIEW "public"."roles_with_profile" WITH ("security_invoker"='o "public"."profiles_with_email" "p" WHERE (("r"."user_id" = "p"."id") AND ("r"."organization_id" = "o"."id")); + ALTER TABLE "public"."roles_with_profile" OWNER TO "postgres"; + CREATE OR REPLACE VIEW "public"."organization_admins" WITH ("security_invoker"='on') AS SELECT "o"."id", "o"."name", @@ -823,8 +967,10 @@ CREATE OR REPLACE VIEW "public"."organization_admins" WITH ("security_invoker"=' GROUP BY "o"."id", "o"."name", "r"."name", "u"."email" ORDER BY "o"."name"; + ALTER TABLE "public"."organization_admins" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "public"."roles_id_seq" START WITH 1 INCREMENT BY 1 @@ -832,18 +978,24 @@ CREATE SEQUENCE IF NOT EXISTS "public"."roles_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "public"."roles_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "public"."roles_id_seq" OWNED BY "public"."roles"."id"; + + CREATE TABLE IF NOT EXISTS "public"."sdks" ( "id" bigint NOT NULL, "version" "text" NOT NULL, "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "public"."sdks" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "public"."service_images" ( "id" bigint NOT NULL, "sdk_id" bigint NOT NULL, @@ -853,8 +1005,10 @@ CREATE TABLE IF NOT EXISTS "public"."service_images" ( "organization_id" "uuid" ); + ALTER TABLE "public"."service_images" OWNER TO "postgres"; + CREATE OR REPLACE VIEW "public"."sdk_service_versions" WITH ("security_invoker"='on') AS SELECT "sdks"."version" AS "sdk_version", "artemis_services"."version" AS "service_version", @@ -865,8 +1019,10 @@ CREATE OR REPLACE VIEW "public"."sdk_service_versions" WITH ("security_invoker"= "public"."service_images" "i" WHERE (("sdks"."id" = "i"."sdk_id") AND ("artemis_services"."id" = "i"."service_id")); + ALTER TABLE "public"."sdk_service_versions" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "public"."sdks_id_seq" START WITH 1 INCREMENT BY 1 @@ -874,10 +1030,14 @@ CREATE SEQUENCE IF NOT EXISTS "public"."sdks_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "public"."sdks_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "public"."sdks_id_seq" OWNED BY "public"."sdks"."id"; + + CREATE SEQUENCE IF NOT EXISTS "public"."service_images_id_seq" START WITH 1 INCREMENT BY 1 @@ -885,25 +1045,23 @@ CREATE SEQUENCE IF NOT EXISTS "public"."service_images_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "public"."service_images_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "public"."service_images_id_seq" OWNED BY "public"."service_images"."id"; -CREATE TABLE IF NOT EXISTS "supabase_migrations"."schema_migrations" ( - "version" "text" NOT NULL, - "statements" "text"[], - "name" "text" -); -ALTER TABLE "supabase_migrations"."schema_migrations" OWNER TO "postgres"; CREATE TABLE IF NOT EXISTS "toit_artemis"."devices" ( "id" "uuid" NOT NULL, "state" "jsonb" NOT NULL ); + ALTER TABLE "toit_artemis"."devices" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "toit_artemis"."events" ( "id" integer NOT NULL, "device_id" "uuid" NOT NULL, @@ -912,8 +1070,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."events" ( "data" "jsonb" NOT NULL ); + ALTER TABLE "toit_artemis"."events" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."events_id_seq" AS integer START WITH 1 @@ -922,17 +1082,23 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."events_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."events_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."events_id_seq" OWNED BY "toit_artemis"."events"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."goals" ( "device_id" "uuid" NOT NULL, "goal" "jsonb" ); + ALTER TABLE "toit_artemis"."goals" OWNER TO "postgres"; + CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_descriptions" ( "id" bigint NOT NULL, "fleet_id" "uuid" NOT NULL, @@ -942,8 +1108,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_descriptions" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pod_descriptions" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_descriptions_id_seq" START WITH 1 INCREMENT BY 1 @@ -951,10 +1119,14 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_descriptions_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."pod_descriptions_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."pod_descriptions_id_seq" OWNED BY "toit_artemis"."pod_descriptions"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_tags" ( "id" bigint NOT NULL, "pod_id" "uuid" NOT NULL, @@ -964,8 +1136,10 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pod_tags" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pod_tags" OWNER TO "postgres"; + CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_tags_id_seq" START WITH 1 INCREMENT BY 1 @@ -973,10 +1147,14 @@ CREATE SEQUENCE IF NOT EXISTS "toit_artemis"."pod_tags_id_seq" NO MAXVALUE CACHE 1; + ALTER TABLE "toit_artemis"."pod_tags_id_seq" OWNER TO "postgres"; + ALTER SEQUENCE "toit_artemis"."pod_tags_id_seq" OWNED BY "toit_artemis"."pod_tags"."id"; + + CREATE TABLE IF NOT EXISTS "toit_artemis"."pods" ( "id" "uuid" NOT NULL, "fleet_id" "uuid" NOT NULL, @@ -985,540 +1163,1156 @@ CREATE TABLE IF NOT EXISTS "toit_artemis"."pods" ( "created_at" timestamp with time zone DEFAULT "now"() NOT NULL ); + ALTER TABLE "toit_artemis"."pods" OWNER TO "postgres"; + ALTER TABLE ONLY "public"."artemis_services" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."artemis_services_id_seq"'::"regclass"); + + ALTER TABLE ONLY "public"."events" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."events_id_seq"'::"regclass"); + + ALTER TABLE ONLY "public"."roles" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."roles_id_seq"'::"regclass"); + + ALTER TABLE ONLY "public"."sdks" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."sdks_id_seq"'::"regclass"); + + ALTER TABLE ONLY "public"."service_images" ALTER COLUMN "id" SET DEFAULT "nextval"('"public"."service_images_id_seq"'::"regclass"); + + ALTER TABLE ONLY "toit_artemis"."events" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."events_id_seq"'::"regclass"); + + ALTER TABLE ONLY "toit_artemis"."pod_descriptions" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."pod_descriptions_id_seq"'::"regclass"); + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ALTER COLUMN "id" SET DEFAULT "nextval"('"toit_artemis"."pod_tags_id_seq"'::"regclass"); + + ALTER TABLE ONLY "public"."admins" ADD CONSTRAINT "admins_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."artemis_services" ADD CONSTRAINT "artemis_services_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."artemis_services" ADD CONSTRAINT "artemis_services_version_key" UNIQUE ("version"); + + ALTER TABLE ONLY "public"."devices" ADD CONSTRAINT "devices_alias_key" UNIQUE ("alias"); + + ALTER TABLE ONLY "public"."devices" ADD CONSTRAINT "devices_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."events" ADD CONSTRAINT "events_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."organizations" ADD CONSTRAINT "organizations_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."profiles" ADD CONSTRAINT "profiles_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."roles" ADD CONSTRAINT "roles_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."roles" ADD CONSTRAINT "roles_user_uid_organization_uid_key" UNIQUE ("user_id", "organization_id"); + + ALTER TABLE ONLY "public"."sdks" ADD CONSTRAINT "sdks_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."sdks" ADD CONSTRAINT "sdks_version_key" UNIQUE ("version"); + + ALTER TABLE ONLY "public"."service_images" ADD CONSTRAINT "service_images_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "public"."service_images" ADD CONSTRAINT "service_images_sdk_id_service_id_key" UNIQUE ("sdk_id", "service_id"); -ALTER TABLE ONLY "supabase_migrations"."schema_migrations" - ADD CONSTRAINT "schema_migrations_pkey" PRIMARY KEY ("version"); + ALTER TABLE ONLY "toit_artemis"."devices" ADD CONSTRAINT "devices_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."events" ADD CONSTRAINT "events_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."goals" ADD CONSTRAINT "goals_pkey" PRIMARY KEY ("device_id"); + + ALTER TABLE ONLY "toit_artemis"."pod_descriptions" ADD CONSTRAINT "pod_descriptions_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pkey" PRIMARY KEY ("id"); + + ALTER TABLE ONLY "toit_artemis"."pods" ADD CONSTRAINT "pods_pkey" PRIMARY KEY ("id", "fleet_id"); + + CREATE INDEX "events_device_id_created_at_idx" ON "public"."events" USING "btree" ("device_id", "created_at" DESC); + + CREATE INDEX "events_device_id" ON "toit_artemis"."events" USING "btree" ("device_id"); + + CREATE INDEX "events_device_id_timestamp_idx" ON "toit_artemis"."events" USING "btree" ("device_id", "timestamp" DESC); + + CREATE INDEX "events_device_id_type_timestamp_idx" ON "toit_artemis"."events" USING "btree" ("device_id", "type", "timestamp" DESC); + + CREATE INDEX "pod_descriptions_name_idx" ON "toit_artemis"."pod_descriptions" USING "btree" ("name"); + + CREATE UNIQUE INDEX "pod_tags_pod_description_id_tag_idx" ON "toit_artemis"."pod_tags" USING "btree" ("pod_description_id", "tag"); -CREATE INDEX "pod_tags_pod_id_idx" ON "toit_artemis"."pod_tags" USING "btree" ("pod_id"); + + +CREATE INDEX "pod_tags_pod_id_idx" ON "toit_artemis"."pod_tags" USING "btree" ("pod_id"); + + CREATE INDEX "pod_tags_tag_idx" ON "toit_artemis"."pod_tags" USING "btree" ("tag"); + + CREATE INDEX "pods_created_at_idx" ON "toit_artemis"."pods" USING "btree" ("created_at" DESC); + + CREATE UNIQUE INDEX "pods_fleet_id_name_idx" ON "toit_artemis"."pod_descriptions" USING "btree" ("fleet_id", "name"); + + CREATE INDEX "pods_id_idx" ON "toit_artemis"."pods" USING "btree" ("id"); + + CREATE INDEX "pods_pod_description_id_created_at_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id", "created_at" DESC); + + CREATE INDEX "pods_pod_description_id_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id"); + + CREATE UNIQUE INDEX "pods_pod_description_id_revision_idx" ON "toit_artemis"."pods" USING "btree" ("pod_description_id", "revision"); + + CREATE OR REPLACE TRIGGER "create_admin_after_new_organization" AFTER INSERT ON "public"."organizations" FOR EACH ROW EXECUTE FUNCTION "public"."create_admin_for_new_organization"(); + + ALTER TABLE ONLY "public"."admins" ADD CONSTRAINT "admins_id_fkey" FOREIGN KEY ("id") REFERENCES "auth"."users"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."events" ADD CONSTRAINT "devices_id_fkey" FOREIGN KEY ("device_id") REFERENCES "public"."devices"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."devices" ADD CONSTRAINT "devices_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."organizations" ADD CONSTRAINT "organizations_owner_fkey" FOREIGN KEY ("owner_id") REFERENCES "public"."profiles"("id") ON UPDATE CASCADE ON DELETE SET NULL; + + ALTER TABLE ONLY "public"."profiles" ADD CONSTRAINT "profiles_id_fkey" FOREIGN KEY ("id") REFERENCES "auth"."users"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."roles" ADD CONSTRAINT "roles_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."roles" ADD CONSTRAINT "roles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."profiles"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."service_images" ADD CONSTRAINT "service_images_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id"); + + ALTER TABLE ONLY "public"."service_images" ADD CONSTRAINT "service_images_sdk_id_fkey" FOREIGN KEY ("sdk_id") REFERENCES "public"."sdks"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "public"."service_images" ADD CONSTRAINT "service_images_service_id_fkey" FOREIGN KEY ("service_id") REFERENCES "public"."artemis_services"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."events" ADD CONSTRAINT "events_device_id_fkey" FOREIGN KEY ("device_id") REFERENCES "toit_artemis"."devices"("id") ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."devices" ADD CONSTRAINT "fk_id" FOREIGN KEY ("id") REFERENCES "public"."devices"("alias") ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."goals" ADD CONSTRAINT "goals_device_id_fkey" FOREIGN KEY ("device_id") REFERENCES "toit_artemis"."devices"("id") ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pod_description_id_fkey" FOREIGN KEY ("pod_description_id") REFERENCES "toit_artemis"."pod_descriptions"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pod_tags" ADD CONSTRAINT "pod_tags_pod_id_fleet_id_fkey" FOREIGN KEY ("pod_id", "fleet_id") REFERENCES "toit_artemis"."pods"("id", "fleet_id") ON UPDATE CASCADE ON DELETE CASCADE; + + ALTER TABLE ONLY "toit_artemis"."pods" ADD CONSTRAINT "pods_pod_description_id_fkey" FOREIGN KEY ("pod_description_id") REFERENCES "toit_artemis"."pod_descriptions"("id") ON UPDATE CASCADE ON DELETE CASCADE; + + CREATE POLICY "Admins can do everything to organization" ON "public"."organizations" TO "authenticated" USING ("public"."is_auth_admin_of_org"("id")); + + CREATE POLICY "Admins can modify roles" ON "public"."roles" TO "authenticated" USING ("public"."is_auth_admin_of_org"("organization_id")) WITH CHECK ("public"."is_auth_admin_of_org"("organization_id")); + + CREATE POLICY "Admins can modify the SDK table" ON "public"."sdks" TO "authenticated" USING ("public"."is_artemis_admin"()) WITH CHECK ("public"."is_artemis_admin"()); + + CREATE POLICY "Admins can modify the service table" ON "public"."artemis_services" TO "authenticated" USING ("public"."is_artemis_admin"()) WITH CHECK ("public"."is_artemis_admin"()); + + CREATE POLICY "Admins can modify the service-images table" ON "public"."service_images" TO "authenticated" USING ("public"."is_artemis_admin"()) WITH CHECK ("public"."is_artemis_admin"()); + + CREATE POLICY "Anon and auth users can see the SDK table" ON "public"."sdks" FOR SELECT TO "authenticated", "anon" USING (true); + + CREATE POLICY "Anon and auth users can see the service table" ON "public"."artemis_services" FOR SELECT TO "authenticated", "anon" USING (true); + + CREATE POLICY "Anon and auth users can see the service-images table" ON "public"."service_images" FOR SELECT TO "authenticated", "anon" USING ((("organization_id" IS NULL) OR "public"."is_auth_member_of_org"("organization_id"))); + + CREATE POLICY "Enable insert of events to authenticated" ON "public"."events" FOR INSERT TO "authenticated" WITH CHECK (true); + + CREATE POLICY "Enable insert of events to everyone" ON "public"."events" FOR INSERT TO "anon" WITH CHECK (true); + + CREATE POLICY "Members can read organization" ON "public"."organizations" FOR SELECT TO "authenticated" USING ("public"."is_auth_member_of_org"("id")); + + CREATE POLICY "Organization members can read events" ON "public"."events" FOR SELECT TO "authenticated" USING ("public"."is_auth_member_of_org"(( SELECT "devices"."organization_id" FROM "public"."devices" WHERE ("devices"."id" = "events"."device_id")))); + + CREATE POLICY "Organization members can read profiles" ON "public"."profiles" FOR SELECT TO "authenticated" USING ("public"."is_auth_in_same_org_as"("id")); + + CREATE POLICY "Owner can do everything to organization" ON "public"."organizations" TO "authenticated" USING (("owner_id" = "auth"."uid"())) WITH CHECK (("owner_id" = "auth"."uid"())); + + CREATE POLICY "Profile can only be changed by owner" ON "public"."profiles" FOR UPDATE TO "authenticated" USING (("auth"."uid"() = "id")) WITH CHECK (("auth"."uid"() = "id")); + + CREATE POLICY "Profile can only be seen by owners" ON "public"."profiles" FOR SELECT TO "authenticated" USING (("auth"."uid"() = "id")); + + CREATE POLICY "User must be in org of device" ON "public"."devices" TO "authenticated" USING ("public"."is_auth_member_of_org"("organization_id")) WITH CHECK ("public"."is_auth_member_of_org"("organization_id")); + + CREATE POLICY "Users can remove themselves from an organization" ON "public"."roles" FOR DELETE TO "authenticated" USING (("user_id" = "auth"."uid"())); -CREATE POLICY "Users can see members of the orgs they are a member of" ON "public"."roles" FOR SELECT TO "authenticated" USING ("public"."is_auth_member_of_org"("organization_id")); -ALTER TABLE "public"."admins" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."artemis_services" ENABLE ROW LEVEL SECURITY; +CREATE POLICY "Users can see members of the orgs they are a member of" ON "public"."roles" FOR SELECT TO "authenticated" USING ("public"."is_auth_member_of_org"("organization_id")); + + + +ALTER TABLE "public"."admins" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."artemis_services" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."devices" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."events" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."organizations" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."profiles" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."roles" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."sdks" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "public"."service_images" ENABLE ROW LEVEL SECURITY; + + +CREATE POLICY "Authenticated have full access to devices of the orgs they are " ON "toit_artemis"."devices" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("id")); + + + +CREATE POLICY "Authenticated have full access to events table of devices in th" ON "toit_artemis"."events" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("device_id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("device_id")); + + + +CREATE POLICY "Authenticated have full access to goals table of devices of the" ON "toit_artemis"."goals" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("device_id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("device_id")); + + + +CREATE POLICY "Authenticated have full access to pod_descriptions in the org t" ON "toit_artemis"."pod_descriptions" TO "authenticated" USING ("public"."is_auth_member_of_org"("organization_id")) WITH CHECK ("public"."is_auth_member_of_org"("organization_id")); + + + +CREATE POLICY "Authenticated have full access to pod_tags table for descriptio" ON "toit_artemis"."pod_tags" TO "authenticated" USING ((EXISTS ( SELECT 1 + FROM "toit_artemis"."pod_descriptions" "pd" + WHERE ("pd"."id" = "pod_tags"."pod_description_id")))) WITH CHECK ((EXISTS ( SELECT 1 + FROM "toit_artemis"."pod_descriptions" "pd" + WHERE ("pd"."id" = "pod_tags"."pod_description_id")))); + + + +CREATE POLICY "Authenticated have full access to pods table for descriptions t" ON "toit_artemis"."pods" TO "authenticated" USING ((EXISTS ( SELECT 1 + FROM "toit_artemis"."pod_descriptions" "pd" + WHERE ("pd"."id" = "pods"."pod_description_id")))) WITH CHECK ((EXISTS ( SELECT 1 + FROM "toit_artemis"."pod_descriptions" "pd" + WHERE ("pd"."id" = "pods"."pod_description_id")))); + + + +ALTER TABLE "toit_artemis"."devices" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "toit_artemis"."events" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "toit_artemis"."goals" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "toit_artemis"."pod_descriptions" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "toit_artemis"."pod_tags" ENABLE ROW LEVEL SECURITY; + + +ALTER TABLE "toit_artemis"."pods" ENABLE ROW LEVEL SECURITY; + + + + +ALTER PUBLICATION "supabase_realtime" OWNER TO "postgres"; + + + + + + + + +GRANT USAGE ON SCHEMA "public" TO "postgres"; +GRANT USAGE ON SCHEMA "public" TO "anon"; +GRANT USAGE ON SCHEMA "public" TO "authenticated"; +GRANT USAGE ON SCHEMA "public" TO "service_role"; + + + +GRANT USAGE ON SCHEMA "toit_artemis" TO "anon"; +GRANT USAGE ON SCHEMA "toit_artemis" TO "authenticated"; +GRANT USAGE ON SCHEMA "toit_artemis" TO "service_role"; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -ALTER TABLE "public"."devices" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."events" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."organizations" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."profiles" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."roles" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."sdks" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "public"."service_images" ENABLE ROW LEVEL SECURITY; -CREATE POLICY "Authenticated have full access to devices of the orgs they are " ON "toit_artemis"."devices" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("id")); -CREATE POLICY "Authenticated have full access to events table of devices in th" ON "toit_artemis"."events" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("device_id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("device_id")); -CREATE POLICY "Authenticated have full access to goals table of devices of the" ON "toit_artemis"."goals" TO "authenticated" USING ("public"."is_auth_in_org_of_alias"("device_id")) WITH CHECK ("public"."is_auth_in_org_of_alias"("device_id")); -CREATE POLICY "Authenticated have full access to pod_descriptions in the org t" ON "toit_artemis"."pod_descriptions" TO "authenticated" USING ("public"."is_auth_member_of_org"("organization_id")) WITH CHECK ("public"."is_auth_member_of_org"("organization_id")); -CREATE POLICY "Authenticated have full access to pod_tags table for descriptio" ON "toit_artemis"."pod_tags" TO "authenticated" USING ((EXISTS ( SELECT 1 - FROM "toit_artemis"."pod_descriptions" "pd" - WHERE ("pd"."id" = "pod_tags"."pod_description_id")))) WITH CHECK ((EXISTS ( SELECT 1 - FROM "toit_artemis"."pod_descriptions" "pd" - WHERE ("pd"."id" = "pod_tags"."pod_description_id")))); -CREATE POLICY "Authenticated have full access to pods table for descriptions t" ON "toit_artemis"."pods" TO "authenticated" USING ((EXISTS ( SELECT 1 - FROM "toit_artemis"."pod_descriptions" "pd" - WHERE ("pd"."id" = "pods"."pod_description_id")))) WITH CHECK ((EXISTS ( SELECT 1 - FROM "toit_artemis"."pod_descriptions" "pd" - WHERE ("pd"."id" = "pods"."pod_description_id")))); -ALTER TABLE "toit_artemis"."devices" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "toit_artemis"."events" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "toit_artemis"."goals" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "toit_artemis"."pod_descriptions" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "toit_artemis"."pod_tags" ENABLE ROW LEVEL SECURITY; -ALTER TABLE "toit_artemis"."pods" ENABLE ROW LEVEL SECURITY; -GRANT USAGE ON SCHEMA "public" TO "postgres"; -GRANT USAGE ON SCHEMA "public" TO "anon"; -GRANT USAGE ON SCHEMA "public" TO "authenticated"; -GRANT USAGE ON SCHEMA "public" TO "service_role"; -GRANT USAGE ON SCHEMA "toit_artemis" TO "anon"; -GRANT USAGE ON SCHEMA "toit_artemis" TO "authenticated"; -GRANT USAGE ON SCHEMA "toit_artemis" TO "service_role"; GRANT ALL ON FUNCTION "public"."create_admin_for_new_organization"() TO "anon"; GRANT ALL ON FUNCTION "public"."create_admin_for_new_organization"() TO "authenticated"; GRANT ALL ON FUNCTION "public"."create_admin_for_new_organization"() TO "service_role"; + + GRANT ALL ON FUNCTION "public"."create_profile_for_new_user"() TO "anon"; GRANT ALL ON FUNCTION "public"."create_profile_for_new_user"() TO "authenticated"; GRANT ALL ON FUNCTION "public"."create_profile_for_new_user"() TO "service_role"; + + GRANT ALL ON FUNCTION "public"."email_for_id"("_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "public"."email_for_id"("_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "public"."email_for_id"("_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "public"."is_artemis_admin"() TO "anon"; GRANT ALL ON FUNCTION "public"."is_artemis_admin"() TO "authenticated"; GRANT ALL ON FUNCTION "public"."is_artemis_admin"() TO "service_role"; + + GRANT ALL ON FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "public"."is_auth_admin_of_org"("_organization_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "public"."is_auth_in_org_of_alias"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "public"."is_auth_in_org_of_alias"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "public"."is_auth_in_org_of_alias"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "public"."is_auth_in_same_org_as"("_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "public"."is_auth_in_same_org_as"("_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "public"."is_auth_in_same_org_as"("_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "public"."is_auth_member_of_org"("_organization_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "public"."is_auth_member_of_org"("_organization_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "public"."is_auth_member_of_org"("_organization_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."delete_old_events"() TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_descriptions"("_fleet_id" "uuid", "_description_ids" bigint[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pod_tag"("_pod_description_id" bigint, "_tag" "text") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."delete_pods"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_devices"("_device_ids" "uuid"[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_events"("_device_ids" "uuid"[], "_types" "text"[], "_limit" integer, "_since" timestamp with time zone) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_goal"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_goal_no_event"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions"("_fleet_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_ids"("_description_ids" bigint[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pod_descriptions_by_names"("_fleet_id" "uuid", "_organization_id" "uuid", "_names" "text"[], "_create_if_absent" boolean) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods"("_pod_description_id" bigint, "_limit" bigint, "_offset" bigint) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_ids"("_fleet_id" "uuid", "_pod_ids" "uuid"[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_pods_by_reference"("_fleet_id" "uuid", "_references" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."get_state"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."insert_pod"("_pod_id" "uuid", "_pod_description_id" bigint) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."max_event_age"() TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."new_provisioned"("_device_id" "uuid", "_state" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."remove_device"("_device_id" "uuid") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."report_event"("_device_id" "uuid", "_type" "text", "_data" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_goal"("_device_id" "uuid", "_goal" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_goals"("_device_ids" "uuid"[], "_goals" "jsonb"[]) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."set_pod_tag"("_pod_id" "uuid", "_pod_description_id" bigint, "_tag" "text", "_force" boolean) TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."update_state"("_device_id" "uuid", "_state" "jsonb") TO "service_role"; + + GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "anon"; GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "authenticated"; GRANT ALL ON FUNCTION "toit_artemis"."upsert_pod_description"("_fleet_id" "uuid", "_organization_id" "uuid", "_name" "text", "_description" "text") TO "service_role"; + + + + + + + + + + + + + + + + + + + + + + + GRANT ALL ON TABLE "public"."devices" TO "anon"; GRANT ALL ON TABLE "public"."devices" TO "authenticated"; GRANT ALL ON TABLE "public"."devices" TO "service_role"; + + GRANT ALL ON TABLE "public"."events" TO "anon"; GRANT ALL ON TABLE "public"."events" TO "authenticated"; GRANT ALL ON TABLE "public"."events" TO "service_role"; + + GRANT ALL ON TABLE "public"."organizations" TO "anon"; GRANT ALL ON TABLE "public"."organizations" TO "authenticated"; GRANT ALL ON TABLE "public"."organizations" TO "service_role"; + + GRANT ALL ON TABLE "public"."active_devices" TO "anon"; GRANT ALL ON TABLE "public"."active_devices" TO "authenticated"; GRANT ALL ON TABLE "public"."active_devices" TO "service_role"; + + GRANT ALL ON TABLE "public"."admins" TO "anon"; GRANT ALL ON TABLE "public"."admins" TO "authenticated"; GRANT ALL ON TABLE "public"."admins" TO "service_role"; + + GRANT ALL ON TABLE "public"."profiles" TO "anon"; GRANT ALL ON TABLE "public"."profiles" TO "authenticated"; GRANT ALL ON TABLE "public"."profiles" TO "service_role"; -GRANT ALL ON TABLE "public"."admin_with_profile" TO "anon"; -GRANT ALL ON TABLE "public"."admin_with_profile" TO "authenticated"; + + GRANT ALL ON TABLE "public"."admin_with_profile" TO "service_role"; + + GRANT ALL ON TABLE "public"."artemis_services" TO "anon"; GRANT ALL ON TABLE "public"."artemis_services" TO "authenticated"; GRANT ALL ON TABLE "public"."artemis_services" TO "service_role"; + + GRANT ALL ON SEQUENCE "public"."artemis_services_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "public"."artemis_services_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "public"."artemis_services_id_seq" TO "service_role"; + + GRANT ALL ON SEQUENCE "public"."events_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "public"."events_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "public"."events_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "public"."profiles_with_email" TO "anon"; GRANT ALL ON TABLE "public"."profiles_with_email" TO "authenticated"; GRANT ALL ON TABLE "public"."profiles_with_email" TO "service_role"; + + GRANT ALL ON TABLE "public"."roles" TO "anon"; GRANT ALL ON TABLE "public"."roles" TO "authenticated"; GRANT ALL ON TABLE "public"."roles" TO "service_role"; + + GRANT ALL ON TABLE "public"."roles_with_profile" TO "anon"; GRANT ALL ON TABLE "public"."roles_with_profile" TO "authenticated"; GRANT ALL ON TABLE "public"."roles_with_profile" TO "service_role"; -GRANT ALL ON TABLE "public"."organization_admins" TO "anon"; -GRANT ALL ON TABLE "public"."organization_admins" TO "authenticated"; + + GRANT ALL ON TABLE "public"."organization_admins" TO "service_role"; + + GRANT ALL ON SEQUENCE "public"."roles_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "public"."roles_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "public"."roles_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "public"."sdks" TO "anon"; GRANT ALL ON TABLE "public"."sdks" TO "authenticated"; GRANT ALL ON TABLE "public"."sdks" TO "service_role"; + + GRANT ALL ON TABLE "public"."service_images" TO "anon"; GRANT ALL ON TABLE "public"."service_images" TO "authenticated"; GRANT ALL ON TABLE "public"."service_images" TO "service_role"; + + GRANT ALL ON TABLE "public"."sdk_service_versions" TO "anon"; GRANT ALL ON TABLE "public"."sdk_service_versions" TO "authenticated"; GRANT ALL ON TABLE "public"."sdk_service_versions" TO "service_role"; + + GRANT ALL ON SEQUENCE "public"."sdks_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "public"."sdks_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "public"."sdks_id_seq" TO "service_role"; + + GRANT ALL ON SEQUENCE "public"."service_images_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "public"."service_images_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "public"."service_images_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."devices" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."devices" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."devices" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."events" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."events" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."events" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."events_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."goals" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."goals" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."goals" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pod_descriptions" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_descriptions_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pod_tags" TO "service_role"; + + GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "anon"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "authenticated"; GRANT ALL ON SEQUENCE "toit_artemis"."pod_tags_id_seq" TO "service_role"; + + GRANT ALL ON TABLE "toit_artemis"."pods" TO "anon"; GRANT ALL ON TABLE "toit_artemis"."pods" TO "authenticated"; GRANT ALL ON TABLE "toit_artemis"."pods" TO "service_role"; + + + + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "service_role"; + + + + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON SEQUENCES TO "service_role"; + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON FUNCTIONS TO "service_role"; + + ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "postgres"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "anon"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "authenticated"; ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "toit_artemis" GRANT ALL ON TABLES TO "service_role"; -RESET ALL; + + + + + + + + + + + + + + + + + + + + + + + + + + + +-- +-- Dumped schema changes for auth and storage +-- + +CREATE OR REPLACE TRIGGER "create_profile_after_new_user" AFTER INSERT ON "auth"."users" FOR EACH ROW EXECUTE FUNCTION "public"."create_profile_for_new_user"(); + + + +CREATE POLICY "Admins can change service images" ON "storage"."objects" TO "authenticated" USING ((("bucket_id" = 'service-images'::"text") AND "public"."is_artemis_admin"())) WITH CHECK ((("bucket_id" = 'service-images'::"text") AND "public"."is_artemis_admin"())); + + + +CREATE POLICY "Admins have access to CLI snapshots" ON "storage"."objects" TO "authenticated" USING ((("bucket_id" = 'cli-snapshots'::"text") AND "public"."is_artemis_admin"())) WITH CHECK ((("bucket_id" = 'cli-snapshots'::"text") AND "public"."is_artemis_admin"())); + + + +CREATE POLICY "Admins have access to service snapshots" ON "storage"."objects" TO "authenticated" USING ((("bucket_id" = 'service-snapshots'::"text") AND "public"."is_artemis_admin"())) WITH CHECK ((("bucket_id" = 'service-snapshots'::"text") AND "public"."is_artemis_admin"())); + + + +CREATE POLICY "All users can read service images" ON "storage"."objects" FOR SELECT TO "authenticated", "anon" USING (("bucket_id" = 'service-images'::"text")); + + + +CREATE POLICY "Authenticated have full access to pod storage in their orgs" ON "storage"."objects" TO "authenticated" USING ((("bucket_id" = 'toit-artemis-pods'::"text") AND "public"."is_auth_member_of_org"((("storage"."foldername"("name"))[1])::"uuid"))) WITH CHECK ((("bucket_id" = 'toit-artemis-pods'::"text") AND "public"."is_auth_member_of_org"((("storage"."foldername"("name"))[1])::"uuid"))); + + + +CREATE POLICY "Authenticated have full access to storage in their orgs" ON "storage"."objects" TO "authenticated" USING ((("bucket_id" = 'toit-artemis-assets'::"text") AND "public"."is_auth_member_of_org"((("storage"."foldername"("name"))[1])::"uuid"))) WITH CHECK ((("bucket_id" = 'toit-artemis-assets'::"text") AND "public"."is_auth_member_of_org"((("storage"."foldername"("name"))[1])::"uuid"))); + + +