SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
CREATE EXTENSION IF NOT EXISTS "pgsodium";
COMMENT ON SCHEMA "public" IS 'standard public schema';
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"."crime_rates" AS ENUM (
    'low',
    'medium',
    'high'
);
ALTER TYPE "public"."crime_rates" OWNER TO "prisma";
CREATE TYPE "public"."crime_status" AS ENUM (
    'new',
    'in_progress',
    'resolved'
);
ALTER TYPE "public"."crime_status" OWNER TO "prisma";
CREATE TYPE "public"."roles" AS ENUM (
    'admin',
    'staff',
    'user'
);
ALTER TYPE "public"."roles" OWNER TO "prisma";
CREATE TYPE "public"."status_contact_messages" AS ENUM (
    'new',
    'read',
    'replied',
    'resolved'
);
ALTER TYPE "public"."status_contact_messages" OWNER TO "prisma";
SET default_tablespace = '';
SET default_table_access_method = "heap";
CREATE TABLE IF NOT EXISTS "public"."_prisma_migrations" (
    "id" character varying(36) NOT NULL,
    "checksum" character varying(64) NOT NULL,
    "finished_at" timestamp with time zone,
    "migration_name" character varying(255) NOT NULL,
    "logs" "text",
    "rolled_back_at" timestamp with time zone,
    "started_at" timestamp with time zone DEFAULT "now"() NOT NULL,
    "applied_steps_count" integer DEFAULT 0 NOT NULL
);
ALTER TABLE "public"."_prisma_migrations" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."cities" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "geographic_id" "uuid",
    "name" character varying(100) NOT NULL,
    "code" character varying(10) NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."cities" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."contact_messages" (
    "name" character varying(255),
    "email" character varying(255),
    "phone" character varying(20),
    "message_type" character varying(50),
    "message_type_label" character varying(50),
    "message" "text",
    "status" "public"."status_contact_messages" DEFAULT 'new'::"public"."status_contact_messages" NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone NOT NULL,
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL
);
ALTER TABLE "public"."contact_messages" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."crime_cases" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "crime_id" "uuid",
    "crime_category_id" "uuid",
    "date" timestamp(6) with time zone NOT NULL,
    "time" timestamp(6) with time zone NOT NULL,
    "location" character varying(255) NOT NULL,
    "latitude" double precision NOT NULL,
    "longitude" double precision NOT NULL,
    "description" "text" NOT NULL,
    "victim_count" integer NOT NULL,
    "status" "public"."crime_status" DEFAULT 'new'::"public"."crime_status" NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."crime_cases" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."crime_categories" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "name" character varying(255) NOT NULL,
    "description" "text" NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."crime_categories" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."crimes" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "district_id" "uuid",
    "city_id" "uuid",
    "year" integer NOT NULL,
    "number_of_crime" integer NOT NULL,
    "rate" "public"."crime_rates" DEFAULT 'low'::"public"."crime_rates" NOT NULL,
    "heat_map" "jsonb",
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."crimes" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."demographics" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "district_id" "uuid",
    "city_id" "uuid",
    "province_id" "uuid",
    "year" integer NOT NULL,
    "population" integer NOT NULL,
    "population_density" double precision NOT NULL,
    "poverty_rate" double precision NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."demographics" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."districts" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "city_id" "uuid" NOT NULL,
    "name" character varying(100) NOT NULL,
    "code" character varying(10) NOT NULL,
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."districts" OWNER TO "prisma";
CREATE TABLE IF NOT EXISTS "public"."geographics" (
    "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
    "district_id" "uuid",
    "latitude" double precision,
    "longitude" double precision,
    "land_area" double precision,
    "polygon" "jsonb",
    "created_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL,
    "updated_at" timestamp(6) with time zone DEFAULT "now"() NOT NULL
);
ALTER TABLE "public"."geographics" OWNER TO "prisma";
ALTER TABLE ONLY "public"."_prisma_migrations"
    ADD CONSTRAINT "_prisma_migrations_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."cities"
    ADD CONSTRAINT "cities_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."contact_messages"
    ADD CONSTRAINT "contact_messages_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."crime_cases"
    ADD CONSTRAINT "crime_cases_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."crime_categories"
    ADD CONSTRAINT "crime_categories_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."crimes"
    ADD CONSTRAINT "crimes_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."demographics"
    ADD CONSTRAINT "demographics_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."districts"
    ADD CONSTRAINT "districts_pkey" PRIMARY KEY ("id");
ALTER TABLE ONLY "public"."geographics"
    ADD CONSTRAINT "geographics_pkey" PRIMARY KEY ("id");
CREATE INDEX "cities_name_idx" ON "public"."cities" USING "btree" ("name");
CREATE UNIQUE INDEX "crimes_city_id_year_key" ON "public"."crimes" USING "btree" ("city_id", "year");
CREATE UNIQUE INDEX "crimes_district_id_year_key" ON "public"."crimes" USING "btree" ("district_id", "year");
CREATE UNIQUE INDEX "demographics_city_id_year_key" ON "public"."demographics" USING "btree" ("city_id", "year");
CREATE UNIQUE INDEX "demographics_district_id_year_key" ON "public"."demographics" USING "btree" ("district_id", "year");
CREATE INDEX "districts_name_idx" ON "public"."districts" USING "btree" ("name");
CREATE UNIQUE INDEX "geographics_district_id_key" ON "public"."geographics" USING "btree" ("district_id");
ALTER TABLE ONLY "public"."cities"
    ADD CONSTRAINT "cities_geographic_id_fkey" FOREIGN KEY ("geographic_id") REFERENCES "public"."geographics"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."crime_cases"
    ADD CONSTRAINT "crime_cases_crime_category_id_fkey" FOREIGN KEY ("crime_category_id") REFERENCES "public"."crime_categories"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."crime_cases"
    ADD CONSTRAINT "crime_cases_crime_id_fkey" FOREIGN KEY ("crime_id") REFERENCES "public"."crimes"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."crimes"
    ADD CONSTRAINT "crimes_city_id_fkey" FOREIGN KEY ("city_id") REFERENCES "public"."cities"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."crimes"
    ADD CONSTRAINT "crimes_district_id_fkey" FOREIGN KEY ("district_id") REFERENCES "public"."districts"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."demographics"
    ADD CONSTRAINT "demographics_city_id_fkey" FOREIGN KEY ("city_id") REFERENCES "public"."cities"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."demographics"
    ADD CONSTRAINT "demographics_district_id_fkey" FOREIGN KEY ("district_id") REFERENCES "public"."districts"("id") ON UPDATE CASCADE ON DELETE SET NULL;
ALTER TABLE ONLY "public"."districts"
    ADD CONSTRAINT "districts_city_id_fkey" FOREIGN KEY ("city_id") REFERENCES "public"."cities"("id") ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE ONLY "public"."geographics"
    ADD CONSTRAINT "geographics_district_id_fkey" FOREIGN KEY ("district_id") REFERENCES "public"."districts"("id") ON UPDATE CASCADE ON DELETE SET NULL;
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 ALL ON SCHEMA "public" TO "prisma";
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 SEQUENCES  TO "prisma";
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 FUNCTIONS  TO "prisma";
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 "public" GRANT ALL ON TABLES  TO "prisma";
RESET ALL;
