create extension if not exists "postgis" with schema "extensions";


create sequence "public"."logs_id_seq";

create table "public"."app_user" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "mobile_number" text,
    "first_name" text,
    "last_name" text,
    "sites" text,
    "kaching" bigint,
    "active_last" timestamp without time zone,
    "profile_image_url" text,
    "email" text,
    "user_id" uuid,
    "additional_channels" text[]
);


create table "public"."app_user_duplicate" (
    "created_at" timestamp with time zone not null default now(),
    "mobile_number" text,
    "first_name" text,
    "last_name" text,
    "sites" text,
    "kaching" bigint,
    "active_last" timestamp without time zone,
    "profile_image_url" text,
    "email" text,
    "app_user_id" uuid not null
);


create table "public"."callsheet" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "region" character varying,
    "channel" character varying,
    "division" character varying,
    "names" character varying,
    "calling_name" character varying,
    "surname" character varying,
    "rep_full_name" character varying,
    "rep_cell_number" character varying,
    "chain" character varying,
    "store_name" character varying,
    "week" character varying,
    "monday" character varying,
    "tuesday" character varying,
    "wednesday" character varying,
    "thursday" character varying,
    "friday" character varying,
    "managers_contact_number" character varying,
    "manager_ms_no" character varying,
    "manager" character varying,
    "comments" text,
    "division_code" character varying,
    "branch" character varying,
    "row" bigint,
    "file" text,
    "sheetname" text,
    "day" character varying
);


create table "public"."callsheet_20240606" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "region" character varying,
    "channel" character varying,
    "division" character varying,
    "names" character varying,
    "calling_name" character varying,
    "surname" character varying,
    "rep_full_name" character varying,
    "rep_cell_number" character varying,
    "chain" character varying,
    "store_name" character varying,
    "week" character varying,
    "monday" character varying,
    "tuesday" character varying,
    "wednesday" character varying,
    "thursday" character varying,
    "friday" character varying,
    "managers_contact_number" character varying,
    "manager_ms_no" character varying,
    "manager" character varying,
    "comments" text,
    "division_code" character varying,
    "branch" character varying
);


create table "public"."callsheet_test" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "region" character varying,
    "channel" character varying,
    "division" character varying,
    "names" character varying,
    "calling_name" character varying,
    "surname" character varying,
    "rep_full_name" character varying,
    "rep_cell_number" character varying,
    "chain" character varying,
    "store_name" character varying,
    "week" character varying,
    "monday" character varying,
    "tuesday" character varying,
    "wednesday" character varying,
    "thursday" character varying,
    "friday" character varying,
    "managers_contact_number" character varying,
    "manager_ms_no" character varying,
    "manager" character varying,
    "comments" text,
    "division_code" character varying,
    "branch" character varying,
    "row" bigint,
    "file" text,
    "sheetname" text
);


create table "public"."client" (
    "id" integer not null,
    "name" character varying,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:09.693425+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:09.693425+00'::timestamp with time zone
);


create table "public"."customer" (
    "id" integer not null,
    "name" character varying,
    "logo_name" text,
    "email" character varying,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:10.018351+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:10.018351+00'::timestamp with time zone
);


create table "public"."customer_client" (
    "id" bigint not null,
    "customer_id" integer,
    "client_id" integer,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:10.388209+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:10.388209+00'::timestamp with time zone
);


create table "public"."file" (
    "id" integer not null,
    "name" character varying,
    "results" json,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:10.707142+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:10.707142+00'::timestamp with time zone
);


create table "public"."file_upload" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "bucket" character varying,
    "path" character varying,
    "name" text,
    "last_row" bigint default '0'::bigint,
    "processed" smallint default '0'::smallint,
    "storage_id" uuid
);


create table "public"."log" (
    "id" uuid not null,
    "customer_id" integer,
    "client_id" integer,
    "task_id" integer,
    "user_id" uuid not null,
    "type" smallint,
    "results" json,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:12.579302+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:12.579302+00'::timestamp with time zone
);


create table "public"."logs" (
    "id" integer not null default nextval('logs_id_seq'::regclass),
    "table_name" text not null,
    "operation" text not null,
    "old_data" jsonb,
    "new_data" jsonb,
    "changed_at" timestamp with time zone default CURRENT_TIMESTAMP
);


create table "public"."mock_data" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "channel" text,
    "store_name" text,
    "product" text,
    "category" text,
    "brand" text,
    "variant" text
);


alter table "public"."mock_data" enable row level security;

create table "public"."product" (
    "id" bigint generated by default as identity not null,
    "customer_id" smallint,
    "name" character varying,
    "type" smallint,
    "weight" integer,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 20:56:02.341431+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 20:56:02.341431+00'::timestamp with time zone,
    "category" text,
    "brand" text,
    "product" text,
    "variant" text,
    "size" text,
    "barcode_ending" text,
    "article" text,
    "image_path" text,
    "notes" text,
    "product_test" text,
    "variant_test" text
);


create table "public"."sjreport" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "date" text,
    "region" character varying,
    "cluster" character varying,
    "geography" character varying,
    "channel" character varying,
    "store_name" character varying,
    "category" character varying,
    "brand" character varying,
    "product" character varying,
    "variant" character varying,
    "size" character varying,
    "barcode_ending" character varying,
    "issue_for_feedback" text,
    "notes" text,
    "article" text,
    "banner" character varying,
    "last_sold" character varying,
    "month" character varying,
    "rsp_value_loss" character varying,
    "status" character varying,
    "store_code" character varying,
    "store_soh" character varying,
    "system_dros" character varying,
    "week" character varying,
    "row" bigint,
    "file" text,
    "sheetname" text,
    "week_1" character varying,
    "due_date" text,
    "score" text,
    "rebate" character varying,
    "oos_place_order" integer,
    "7_days_cover" bigint,
    "soh_no_sales" bigint,
    "negative_stock" bigint,
    "no_sales_100" bigint,
    "date_viewed" text,
    "name" text,
    "check" text,
    "active_count" text,
    "checked_by" text,
    "march" text,
    "fixed" text,
    "not_ranged" text,
    "feedback_due_by" text,
    "instruction" text,
    "barcode" text,
    "no_stock" text,
    "issues_reported" text,
    "qc_check" text,
    "insruction" text,
    "instructions" text,
    "ranged_and_selling" text,
    "published_date" text,
    "undefined" text
);


create table "public"."sjreport_20240606" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "date" text,
    "region" character varying,
    "cluster" character varying,
    "geography" character varying,
    "channel" character varying,
    "store_name" character varying,
    "category" character varying,
    "brand" character varying,
    "product" character varying,
    "variant" character varying,
    "size" character varying,
    "barcode_ending" character varying,
    "issue_for_feedback" text,
    "notes" text,
    "article" text,
    "banner" character varying,
    "last_sold" character varying,
    "month" character varying,
    "rsp_value_loss" character varying,
    "status" character varying,
    "store_code" character varying,
    "store_soh" character varying,
    "system_dros" character varying,
    "week" character varying,
    "row" bigint,
    "file" text,
    "sheetname" text,
    "week_1" character varying,
    "due_date" text,
    "score" text,
    "rebate" character varying,
    "oos_place_order" integer,
    "7_days_cover" bigint,
    "soh_no_sales" bigint,
    "negative_stock" bigint,
    "no_sales_100" bigint,
    "date_viewed" text,
    "name" text,
    "check" text,
    "active_count" text,
    "checked_by" text,
    "march" text,
    "fixed" text,
    "not_ranged" text,
    "feedback_due_by" text,
    "instruction" text,
    "barcode" text,
    "no_stock" text,
    "issues_reported" text,
    "qc_check" text,
    "insruction" text,
    "instructions" text,
    "ranged_and_selling" text,
    "published_date" text,
    "undefined" text,
    "task_type" text,
    "kaching" text,
    "image_url" text,
    "price" integer,
    "count" integer
);


create table "public"."store" (
    "id" bigint generated by default as identity not null,
    "name" text,
    "address" text,
    "client_id" integer,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:11.031302+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:11.031302+00'::timestamp with time zone,
    "gps" text,
    "lat" text,
    "region" text,
    "channel" text,
    "store_code" text,
    "channel_test" text,
    "name_test" text,
    "suburb" text,
    "banner" text,
    "google_link" text,
    "town" text,
    "location" geography,
    "file" text,
    "row" bigint,
    "sheetname" text
);


create table "public"."store_product" (
    "id" bigint generated by default as identity not null,
    "customer_id" smallint,
    "store_name" character varying,
    "region" character varying,
    "cluster" character varying,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 20:56:02.341431+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 20:56:02.341431+00'::timestamp with time zone,
    "category" text,
    "brand" text,
    "product" text,
    "variant" text,
    "size" text,
    "barcode" text,
    "geography" text,
    "store_code" bigint,
    "issues" text,
    "status" character varying,
    "active_count" bigint,
    "not_ranged" bigint,
    "ranged_and_selling" bigint,
    "no_stock" bigint,
    "score" character varying,
    "file" text,
    "row" bigint,
    "sheetname" character varying,
    "channel" character varying,
    "date" character varying,
    "name" character varying
);


create table "public"."task" (
    "id" integer generated by default as identity not null,
    "name" text,
    "status" character varying,
    "file_id" bigint,
    "client_id" integer,
    "customer_id" integer,
    "user_id" uuid,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "sites" text,
    "callsheet_id" bigint,
    "sjreport_id" bigint,
    "app_user_mobile" text,
    "type" character varying,
    "day" character varying,
    "week" character varying,
    "note" text,
    "price" bigint,
    "count" bigint,
    "barcode" character varying,
    "share" text,
    "store_id" bigint,
    "approve" smallint default '1'::smallint,
    "rep_full_name" text,
    "chain" text,
    "store_name" text,
    "category" text,
    "brand" text,
    "product" text,
    "variant" text,
    "size" text,
    "image_url" text,
    "week_number" integer
);


create table "public"."task_20240618" (
    "id" integer generated by default as identity not null,
    "name" text,
    "status" character varying,
    "file_id" bigint,
    "client_id" integer,
    "customer_id" integer,
    "user_id" uuid,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "sites" text,
    "callsheet_id" bigint,
    "sjreport_id" bigint,
    "app_user_mobile" text,
    "type" character varying,
    "day" character varying,
    "week" character varying,
    "note" text,
    "price" bigint,
    "count" bigint,
    "barcode" character varying,
    "share" text,
    "store_id" bigint,
    "approve" smallint default '1'::smallint,
    "rep_full_name" text,
    "chain" text,
    "store_name" text,
    "category" text,
    "brand" text,
    "product" text,
    "variant" text,
    "size" text
);


create table "public"."task_file" (
    "id" integer not null,
    "sites_id" integer,
    "file_id" integer,
    "type" integer,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:11.683257+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:11.683257+00'::timestamp with time zone
);


create table "public"."task_test" (
    "id" integer generated by default as identity not null,
    "name" text,
    "status" character varying,
    "file_id" bigint,
    "client_id" integer,
    "customer_id" integer,
    "user_id" uuid,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:11.358345+00'::timestamp with time zone,
    "sites" text,
    "callsheet_id" bigint,
    "sjreport_id" bigint,
    "app_user_mobile" text,
    "type" character varying,
    "day" character varying,
    "week" character varying
);


create table "public"."user" (
    "id" uuid not null,
    "first_name" character varying,
    "last_name" character varying,
    "mobile_number" character varying,
    "active" smallint,
    "created_by" uuid,
    "updated_by" uuid,
    "updated_at" timestamp with time zone not null default '2024-03-10 05:22:12.001949+00'::timestamp with time zone,
    "created_at" timestamp with time zone not null default '2024-03-10 05:22:12.001949+00'::timestamp with time zone,
    "email" text,
    "kaching" bigint,
    "region" text,
    "stores" text,
    "full_name" text
);


alter sequence "public"."logs_id_seq" owned by "public"."logs"."id";

CREATE UNIQUE INDEX app_user_duplicate_pkey ON public.app_user_duplicate USING btree (app_user_id);

CREATE UNIQUE INDEX app_user_pkey ON public.app_user USING btree (id);

CREATE UNIQUE INDEX callsheet_20240606_pkey ON public.callsheet_20240606 USING btree (id);

CREATE UNIQUE INDEX callsheet_pkey ON public.callsheet USING btree (id);

CREATE UNIQUE INDEX callsheet_test_pkey ON public.callsheet_test USING btree (id);

CREATE UNIQUE INDEX client_pkey ON public.client USING btree (id);

CREATE UNIQUE INDEX customer_client_pkey ON public.customer_client USING btree (id);

CREATE UNIQUE INDEX customer_pkey ON public.customer USING btree (id);

CREATE UNIQUE INDEX file_pkey ON public.file USING btree (id);

CREATE UNIQUE INDEX file_uploaded_pkey ON public.file_upload USING btree (id);

CREATE UNIQUE INDEX log_pkey ON public.log USING btree (id);

CREATE UNIQUE INDEX logs_pkey ON public.logs USING btree (id);

CREATE UNIQUE INDEX mock_data_pkey ON public.mock_data USING btree (id);

CREATE UNIQUE INDEX product_id_key ON public.product USING btree (id);

CREATE UNIQUE INDEX product_pkey ON public.product USING btree (id);

CREATE UNIQUE INDEX sites_pkey ON public.store USING btree (id);

CREATE UNIQUE INDEX sjreport_duplicate_pkey ON public.sjreport_20240606 USING btree (id);

CREATE UNIQUE INDEX sjreport_pkey ON public.sjreport USING btree (id);

CREATE INDEX store_geo_index ON public.store USING gist (location);

CREATE UNIQUE INDEX store_id_key ON public.store USING btree (id);

CREATE UNIQUE INDEX store_product_id_key ON public.store_product USING btree (id);

CREATE UNIQUE INDEX store_product_pkey ON public.store_product USING btree (id);

CREATE UNIQUE INDEX task_20240618_id_key ON public.task_20240618 USING btree (id);

CREATE UNIQUE INDEX task_20240618_pkey ON public.task_20240618 USING btree (id);

CREATE UNIQUE INDEX task_file_pkey ON public.task_file USING btree (id);

CREATE UNIQUE INDEX task_id_key ON public.task USING btree (id);

CREATE UNIQUE INDEX task_test_id_key ON public.task_test USING btree (id);

CREATE UNIQUE INDEX task_test_pkey ON public.task_test USING btree (id);

CREATE UNIQUE INDEX tasks_pkey ON public.task USING btree (id);

CREATE UNIQUE INDEX user_pkey ON public."user" USING btree (id);

alter table "public"."app_user" add constraint "app_user_pkey" PRIMARY KEY using index "app_user_pkey";

alter table "public"."app_user_duplicate" add constraint "app_user_duplicate_pkey" PRIMARY KEY using index "app_user_duplicate_pkey";

alter table "public"."callsheet" add constraint "callsheet_pkey" PRIMARY KEY using index "callsheet_pkey";

alter table "public"."callsheet_20240606" add constraint "callsheet_20240606_pkey" PRIMARY KEY using index "callsheet_20240606_pkey";

alter table "public"."callsheet_test" add constraint "callsheet_test_pkey" PRIMARY KEY using index "callsheet_test_pkey";

alter table "public"."client" add constraint "client_pkey" PRIMARY KEY using index "client_pkey";

alter table "public"."customer" add constraint "customer_pkey" PRIMARY KEY using index "customer_pkey";

alter table "public"."customer_client" add constraint "customer_client_pkey" PRIMARY KEY using index "customer_client_pkey";

alter table "public"."file" add constraint "file_pkey" PRIMARY KEY using index "file_pkey";

alter table "public"."file_upload" add constraint "file_uploaded_pkey" PRIMARY KEY using index "file_uploaded_pkey";

alter table "public"."log" add constraint "log_pkey" PRIMARY KEY using index "log_pkey";

alter table "public"."logs" add constraint "logs_pkey" PRIMARY KEY using index "logs_pkey";

alter table "public"."mock_data" add constraint "mock_data_pkey" PRIMARY KEY using index "mock_data_pkey";

alter table "public"."product" add constraint "product_pkey" PRIMARY KEY using index "product_pkey";

alter table "public"."sjreport" add constraint "sjreport_pkey" PRIMARY KEY using index "sjreport_pkey";

alter table "public"."sjreport_20240606" add constraint "sjreport_duplicate_pkey" PRIMARY KEY using index "sjreport_duplicate_pkey";

alter table "public"."store" add constraint "sites_pkey" PRIMARY KEY using index "sites_pkey";

alter table "public"."store_product" add constraint "store_product_pkey" PRIMARY KEY using index "store_product_pkey";

alter table "public"."task" add constraint "tasks_pkey" PRIMARY KEY using index "tasks_pkey";

alter table "public"."task_20240618" add constraint "task_20240618_pkey" PRIMARY KEY using index "task_20240618_pkey";

alter table "public"."task_file" add constraint "task_file_pkey" PRIMARY KEY using index "task_file_pkey";

alter table "public"."task_test" add constraint "task_test_pkey" PRIMARY KEY using index "task_test_pkey";

alter table "public"."user" add constraint "user_pkey" PRIMARY KEY using index "user_pkey";

alter table "public"."app_user" add constraint "app_user_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) not valid;

alter table "public"."app_user" validate constraint "app_user_user_id_fkey";

alter table "public"."client" add constraint "public_client_created_by_fkey" FOREIGN KEY (created_by) REFERENCES auth.users(id) not valid;

alter table "public"."client" validate constraint "public_client_created_by_fkey";

alter table "public"."customer" add constraint "public_customer_created_by_fkey" FOREIGN KEY (created_by) REFERENCES auth.users(id) not valid;

alter table "public"."customer" validate constraint "public_customer_created_by_fkey";

alter table "public"."customer_client" add constraint "customer_client_customer_id_fkey" FOREIGN KEY (customer_id) REFERENCES customer(id) not valid;

alter table "public"."customer_client" validate constraint "customer_client_customer_id_fkey";

alter table "public"."customer_client" add constraint "customer_client_customer_id_fkey1" FOREIGN KEY (customer_id) REFERENCES customer(id) not valid;

alter table "public"."customer_client" validate constraint "customer_client_customer_id_fkey1";

alter table "public"."customer_client" add constraint "public_customer_client_created_by_fkey" FOREIGN KEY (created_by) REFERENCES auth.users(id) not valid;

alter table "public"."customer_client" validate constraint "public_customer_client_created_by_fkey";

alter table "public"."product" add constraint "product_id_key" UNIQUE using index "product_id_key";

alter table "public"."store" add constraint "sites_client_id_fkey" FOREIGN KEY (client_id) REFERENCES client(id) not valid;

alter table "public"."store" validate constraint "sites_client_id_fkey";

alter table "public"."store" add constraint "sites_client_id_fkey1" FOREIGN KEY (client_id) REFERENCES client(id) not valid;

alter table "public"."store" validate constraint "sites_client_id_fkey1";

alter table "public"."store" add constraint "sites_client_id_fkey2" FOREIGN KEY (client_id) REFERENCES client(id) not valid;

alter table "public"."store" validate constraint "sites_client_id_fkey2";

alter table "public"."store" add constraint "sites_client_id_fkey3" FOREIGN KEY (client_id) REFERENCES client(id) not valid;

alter table "public"."store" validate constraint "sites_client_id_fkey3";

alter table "public"."store" add constraint "sites_client_id_fkey4" FOREIGN KEY (client_id) REFERENCES client(id) not valid;

alter table "public"."store" validate constraint "sites_client_id_fkey4";

alter table "public"."store" add constraint "store_id_key" UNIQUE using index "store_id_key";

alter table "public"."store_product" add constraint "store_product_id_key" UNIQUE using index "store_product_id_key";

alter table "public"."task" add constraint "task_client_id_fkey" FOREIGN KEY (client_id) REFERENCES client(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task" validate constraint "task_client_id_fkey";

alter table "public"."task" add constraint "task_customer_id_fkey" FOREIGN KEY (customer_id) REFERENCES customer(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task" validate constraint "task_customer_id_fkey";

alter table "public"."task" add constraint "task_customer_id_fkey1" FOREIGN KEY (customer_id) REFERENCES customer(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task" validate constraint "task_customer_id_fkey1";

alter table "public"."task" add constraint "task_id_key" UNIQUE using index "task_id_key";

alter table "public"."task" add constraint "task_store_id_fkey" FOREIGN KEY (store_id) REFERENCES store(id) not valid;

alter table "public"."task" validate constraint "task_store_id_fkey";

alter table "public"."task" add constraint "task_user_id_fkey1" FOREIGN KEY (user_id) REFERENCES auth.users(id) not valid;

alter table "public"."task" validate constraint "task_user_id_fkey1";

alter table "public"."task_20240618" add constraint "task_20240618_client_id_fkey" FOREIGN KEY (client_id) REFERENCES client(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task_20240618" validate constraint "task_20240618_client_id_fkey";

alter table "public"."task_20240618" add constraint "task_20240618_customer_id_fkey" FOREIGN KEY (customer_id) REFERENCES customer(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task_20240618" validate constraint "task_20240618_customer_id_fkey";

alter table "public"."task_20240618" add constraint "task_20240618_customer_id_fkey1" FOREIGN KEY (customer_id) REFERENCES customer(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task_20240618" validate constraint "task_20240618_customer_id_fkey1";

alter table "public"."task_20240618" add constraint "task_20240618_id_key" UNIQUE using index "task_20240618_id_key";

alter table "public"."task_20240618" add constraint "task_20240618_store_id_fkey" FOREIGN KEY (store_id) REFERENCES store(id) not valid;

alter table "public"."task_20240618" validate constraint "task_20240618_store_id_fkey";

alter table "public"."task_20240618" add constraint "task_20240618_user_id_fkey" FOREIGN KEY (user_id) REFERENCES app_user_duplicate(app_user_id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."task_20240618" validate constraint "task_20240618_user_id_fkey";

alter table "public"."task_test" add constraint "task_test_id_key" UNIQUE using index "task_test_id_key";

alter table "public"."user" add constraint "public_user_id_fkey" FOREIGN KEY (id) REFERENCES auth.users(id) not valid;

alter table "public"."user" validate constraint "public_user_id_fkey";

set check_function_bodies = off;

create or replace view "public"."app_user_additional_channels_view" as  SELECT app_user.id,
    app_user.mobile_number,
    unnest(app_user.additional_channels) AS additional_channel
   FROM app_user;


create or replace view "public"."brand_view" as  SELECT DISTINCT sjreport.brand
   FROM sjreport;


create or replace view "public"."category_view" as  SELECT DISTINCT sjreport.category
   FROM sjreport;


create or replace view "public"."chain_view" as  SELECT DISTINCT sjreport.channel
   FROM sjreport;


CREATE OR REPLACE FUNCTION public.get_all_auth_users()
 RETURNS TABLE(user_id uuid, email text, phone text)
 LANGUAGE plpgsql
AS $function$
BEGIN
    RETURN QUERY
    SELECT users.id, users.email, users.phone
    FROM auth.users AS users;
END;
$function$
;

CREATE OR REPLACE FUNCTION public.get_all_auth_users2()
 RETURNS TABLE(user_id uuid, email character varying, phone text)
 LANGUAGE plpgsql
AS $function$
BEGIN
    RETURN QUERY
    SELECT users.id, users.email, users.phone
    FROM auth.users AS users;
END;
$function$
;

CREATE OR REPLACE FUNCTION public.get_callsheet_day(dayvar text)
 RETURNS SETOF record
 LANGUAGE sql
AS $function$
    SELECT id, chain, region, rep_full_name, rep_cell_number, day, store_name
    FROM callsheet
    where day ilike dayVar
    group by id, chain, region, rep_full_name, rep_cell_number, day, store_name
$function$
;

CREATE OR REPLACE FUNCTION public.get_grouped_tasks()
 RETURNS TABLE(store_name text, task_count integer)
 LANGUAGE plpgsql
AS $function$
BEGIN
  RETURN QUERY
  SELECT t.store_name, COUNT(*) as task_count
  FROM task t
  GROUP BY t.store_name;
END;
$function$
;

CREATE OR REPLACE FUNCTION public.get_list_callsheet()
 RETURNS TABLE(id bigint, chain text, channel text, store_name text, week text, rep_cell_number text, day text, rep_full_name text)
 LANGUAGE sql
AS $function$
  SELECT id, chain, channel, store_name,week,rep_cell_number,day,rep_full_name
  FROM callsheet
  group by id, chain, channel, store_name,week,rep_cell_number,day,rep_full_name
$function$
;

CREATE OR REPLACE FUNCTION public.group_by_items()
 RETURNS TABLE(category text, brand text, product text, variant text, size text, barcode_ending text, article text)
 LANGUAGE sql
AS $function$
  SELECT category, brand, product, variant, size, barcode_ending, article
  FROM sjreport
  group by category, brand, product, variant, size, barcode_ending, article
$function$
;

CREATE OR REPLACE FUNCTION public.group_by_stores()
 RETURNS TABLE(region text, channel text, store_name text, store_code text)
 LANGUAGE sql
AS $function$
  SELECT region, channel, store_name, store_code
  FROM sjreport
  group by region, channel, store_name, store_code
$function$
;

CREATE OR REPLACE FUNCTION public.group_by_users()
 RETURNS TABLE(rep_full_name text, rep_cell_number text)
 LANGUAGE sql
AS $function$
  SELECT rep_full_name, rep_cell_number
  FROM callsheet
  group by rep_full_name,rep_cell_number
$function$
;

CREATE OR REPLACE FUNCTION public.group_tasks_by_store_name()
 RETURNS TABLE(store_name character varying, total_tasks integer)
 LANGUAGE plpgsql
AS $function$
BEGIN
    RETURN QUERY
    SELECT task.store_name, COUNT(*) AS total_tasks
    FROM task
    GROUP BY task.store_name;
END;
$function$
;

create or replace view "public"."grouped_store_info" as  SELECT task.chain,
    task.store_name,
    task.app_user_mobile,
    task.day,
    task.status,
    task.week_number,
    count(*) AS task_count
   FROM task
  GROUP BY task.chain, task.store_name, task.app_user_mobile, task.status, task.week_number, task.day;


create or replace view "public"."grouped_store_info_status_week" as  SELECT task.chain,
    task.store_name,
    task.app_user_mobile,
    task.day,
    task.status,
    task.week_number,
    count(*) AS task_count
   FROM task
  GROUP BY task.chain, task.store_name, task.app_user_mobile, task.status, task.week_number, task.day;


CREATE OR REPLACE FUNCTION public.log_changes()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
BEGIN
  insert into logs (table_name, operation, old_data, new_data)
  values (TG_TABLE_NAME, TG_OP, row_to_json(OLD), row_to_json(NEW));
  return null;
END  
$function$
;

create or replace view "public"."product_view" as  SELECT DISTINCT sjreport.product
   FROM sjreport;


create or replace view "public"."store_names_view" as  SELECT DISTINCT task.store_name
   FROM task;


create or replace view "public"."store_view" as  SELECT DISTINCT sjreport.store_name
   FROM sjreport;


create or replace view "public"."variant_view" as  SELECT DISTINCT sjreport.variant
   FROM sjreport;


grant delete on table "public"."app_user" to "anon";

grant insert on table "public"."app_user" to "anon";

grant references on table "public"."app_user" to "anon";

grant select on table "public"."app_user" to "anon";

grant trigger on table "public"."app_user" to "anon";

grant truncate on table "public"."app_user" to "anon";

grant update on table "public"."app_user" to "anon";

grant delete on table "public"."app_user" to "authenticated";

grant insert on table "public"."app_user" to "authenticated";

grant references on table "public"."app_user" to "authenticated";

grant select on table "public"."app_user" to "authenticated";

grant trigger on table "public"."app_user" to "authenticated";

grant truncate on table "public"."app_user" to "authenticated";

grant update on table "public"."app_user" to "authenticated";

grant delete on table "public"."app_user" to "service_role";

grant insert on table "public"."app_user" to "service_role";

grant references on table "public"."app_user" to "service_role";

grant select on table "public"."app_user" to "service_role";

grant trigger on table "public"."app_user" to "service_role";

grant truncate on table "public"."app_user" to "service_role";

grant update on table "public"."app_user" to "service_role";

grant delete on table "public"."app_user_duplicate" to "anon";

grant insert on table "public"."app_user_duplicate" to "anon";

grant references on table "public"."app_user_duplicate" to "anon";

grant select on table "public"."app_user_duplicate" to "anon";

grant trigger on table "public"."app_user_duplicate" to "anon";

grant truncate on table "public"."app_user_duplicate" to "anon";

grant update on table "public"."app_user_duplicate" to "anon";

grant delete on table "public"."app_user_duplicate" to "authenticated";

grant insert on table "public"."app_user_duplicate" to "authenticated";

grant references on table "public"."app_user_duplicate" to "authenticated";

grant select on table "public"."app_user_duplicate" to "authenticated";

grant trigger on table "public"."app_user_duplicate" to "authenticated";

grant truncate on table "public"."app_user_duplicate" to "authenticated";

grant update on table "public"."app_user_duplicate" to "authenticated";

grant delete on table "public"."app_user_duplicate" to "service_role";

grant insert on table "public"."app_user_duplicate" to "service_role";

grant references on table "public"."app_user_duplicate" to "service_role";

grant select on table "public"."app_user_duplicate" to "service_role";

grant trigger on table "public"."app_user_duplicate" to "service_role";

grant truncate on table "public"."app_user_duplicate" to "service_role";

grant update on table "public"."app_user_duplicate" to "service_role";

grant delete on table "public"."callsheet" to "anon";

grant insert on table "public"."callsheet" to "anon";

grant references on table "public"."callsheet" to "anon";

grant select on table "public"."callsheet" to "anon";

grant trigger on table "public"."callsheet" to "anon";

grant truncate on table "public"."callsheet" to "anon";

grant update on table "public"."callsheet" to "anon";

grant delete on table "public"."callsheet" to "authenticated";

grant insert on table "public"."callsheet" to "authenticated";

grant references on table "public"."callsheet" to "authenticated";

grant select on table "public"."callsheet" to "authenticated";

grant trigger on table "public"."callsheet" to "authenticated";

grant truncate on table "public"."callsheet" to "authenticated";

grant update on table "public"."callsheet" to "authenticated";

grant delete on table "public"."callsheet" to "service_role";

grant insert on table "public"."callsheet" to "service_role";

grant references on table "public"."callsheet" to "service_role";

grant select on table "public"."callsheet" to "service_role";

grant trigger on table "public"."callsheet" to "service_role";

grant truncate on table "public"."callsheet" to "service_role";

grant update on table "public"."callsheet" to "service_role";

grant delete on table "public"."callsheet_20240606" to "anon";

grant insert on table "public"."callsheet_20240606" to "anon";

grant references on table "public"."callsheet_20240606" to "anon";

grant select on table "public"."callsheet_20240606" to "anon";

grant trigger on table "public"."callsheet_20240606" to "anon";

grant truncate on table "public"."callsheet_20240606" to "anon";

grant update on table "public"."callsheet_20240606" to "anon";

grant delete on table "public"."callsheet_20240606" to "authenticated";

grant insert on table "public"."callsheet_20240606" to "authenticated";

grant references on table "public"."callsheet_20240606" to "authenticated";

grant select on table "public"."callsheet_20240606" to "authenticated";

grant trigger on table "public"."callsheet_20240606" to "authenticated";

grant truncate on table "public"."callsheet_20240606" to "authenticated";

grant update on table "public"."callsheet_20240606" to "authenticated";

grant delete on table "public"."callsheet_20240606" to "service_role";

grant insert on table "public"."callsheet_20240606" to "service_role";

grant references on table "public"."callsheet_20240606" to "service_role";

grant select on table "public"."callsheet_20240606" to "service_role";

grant trigger on table "public"."callsheet_20240606" to "service_role";

grant truncate on table "public"."callsheet_20240606" to "service_role";

grant update on table "public"."callsheet_20240606" to "service_role";

grant delete on table "public"."callsheet_test" to "anon";

grant insert on table "public"."callsheet_test" to "anon";

grant references on table "public"."callsheet_test" to "anon";

grant select on table "public"."callsheet_test" to "anon";

grant trigger on table "public"."callsheet_test" to "anon";

grant truncate on table "public"."callsheet_test" to "anon";

grant update on table "public"."callsheet_test" to "anon";

grant delete on table "public"."callsheet_test" to "authenticated";

grant insert on table "public"."callsheet_test" to "authenticated";

grant references on table "public"."callsheet_test" to "authenticated";

grant select on table "public"."callsheet_test" to "authenticated";

grant trigger on table "public"."callsheet_test" to "authenticated";

grant truncate on table "public"."callsheet_test" to "authenticated";

grant update on table "public"."callsheet_test" to "authenticated";

grant delete on table "public"."callsheet_test" to "service_role";

grant insert on table "public"."callsheet_test" to "service_role";

grant references on table "public"."callsheet_test" to "service_role";

grant select on table "public"."callsheet_test" to "service_role";

grant trigger on table "public"."callsheet_test" to "service_role";

grant truncate on table "public"."callsheet_test" to "service_role";

grant update on table "public"."callsheet_test" to "service_role";

grant delete on table "public"."client" to "anon";

grant insert on table "public"."client" to "anon";

grant references on table "public"."client" to "anon";

grant select on table "public"."client" to "anon";

grant trigger on table "public"."client" to "anon";

grant truncate on table "public"."client" to "anon";

grant update on table "public"."client" to "anon";

grant delete on table "public"."client" to "authenticated";

grant insert on table "public"."client" to "authenticated";

grant references on table "public"."client" to "authenticated";

grant select on table "public"."client" to "authenticated";

grant trigger on table "public"."client" to "authenticated";

grant truncate on table "public"."client" to "authenticated";

grant update on table "public"."client" to "authenticated";

grant delete on table "public"."client" to "service_role";

grant insert on table "public"."client" to "service_role";

grant references on table "public"."client" to "service_role";

grant select on table "public"."client" to "service_role";

grant trigger on table "public"."client" to "service_role";

grant truncate on table "public"."client" to "service_role";

grant update on table "public"."client" to "service_role";

grant delete on table "public"."customer" to "anon";

grant insert on table "public"."customer" to "anon";

grant references on table "public"."customer" to "anon";

grant select on table "public"."customer" to "anon";

grant trigger on table "public"."customer" to "anon";

grant truncate on table "public"."customer" to "anon";

grant update on table "public"."customer" to "anon";

grant delete on table "public"."customer" to "authenticated";

grant insert on table "public"."customer" to "authenticated";

grant references on table "public"."customer" to "authenticated";

grant select on table "public"."customer" to "authenticated";

grant trigger on table "public"."customer" to "authenticated";

grant truncate on table "public"."customer" to "authenticated";

grant update on table "public"."customer" to "authenticated";

grant delete on table "public"."customer" to "service_role";

grant insert on table "public"."customer" to "service_role";

grant references on table "public"."customer" to "service_role";

grant select on table "public"."customer" to "service_role";

grant trigger on table "public"."customer" to "service_role";

grant truncate on table "public"."customer" to "service_role";

grant update on table "public"."customer" to "service_role";

grant delete on table "public"."customer_client" to "anon";

grant insert on table "public"."customer_client" to "anon";

grant references on table "public"."customer_client" to "anon";

grant select on table "public"."customer_client" to "anon";

grant trigger on table "public"."customer_client" to "anon";

grant truncate on table "public"."customer_client" to "anon";

grant update on table "public"."customer_client" to "anon";

grant delete on table "public"."customer_client" to "authenticated";

grant insert on table "public"."customer_client" to "authenticated";

grant references on table "public"."customer_client" to "authenticated";

grant select on table "public"."customer_client" to "authenticated";

grant trigger on table "public"."customer_client" to "authenticated";

grant truncate on table "public"."customer_client" to "authenticated";

grant update on table "public"."customer_client" to "authenticated";

grant delete on table "public"."customer_client" to "service_role";

grant insert on table "public"."customer_client" to "service_role";

grant references on table "public"."customer_client" to "service_role";

grant select on table "public"."customer_client" to "service_role";

grant trigger on table "public"."customer_client" to "service_role";

grant truncate on table "public"."customer_client" to "service_role";

grant update on table "public"."customer_client" to "service_role";

grant delete on table "public"."file" to "anon";

grant insert on table "public"."file" to "anon";

grant references on table "public"."file" to "anon";

grant select on table "public"."file" to "anon";

grant trigger on table "public"."file" to "anon";

grant truncate on table "public"."file" to "anon";

grant update on table "public"."file" to "anon";

grant delete on table "public"."file" to "authenticated";

grant insert on table "public"."file" to "authenticated";

grant references on table "public"."file" to "authenticated";

grant select on table "public"."file" to "authenticated";

grant trigger on table "public"."file" to "authenticated";

grant truncate on table "public"."file" to "authenticated";

grant update on table "public"."file" to "authenticated";

grant delete on table "public"."file" to "service_role";

grant insert on table "public"."file" to "service_role";

grant references on table "public"."file" to "service_role";

grant select on table "public"."file" to "service_role";

grant trigger on table "public"."file" to "service_role";

grant truncate on table "public"."file" to "service_role";

grant update on table "public"."file" to "service_role";

grant delete on table "public"."file_upload" to "anon";

grant insert on table "public"."file_upload" to "anon";

grant references on table "public"."file_upload" to "anon";

grant select on table "public"."file_upload" to "anon";

grant trigger on table "public"."file_upload" to "anon";

grant truncate on table "public"."file_upload" to "anon";

grant update on table "public"."file_upload" to "anon";

grant delete on table "public"."file_upload" to "authenticated";

grant insert on table "public"."file_upload" to "authenticated";

grant references on table "public"."file_upload" to "authenticated";

grant select on table "public"."file_upload" to "authenticated";

grant trigger on table "public"."file_upload" to "authenticated";

grant truncate on table "public"."file_upload" to "authenticated";

grant update on table "public"."file_upload" to "authenticated";

grant delete on table "public"."file_upload" to "service_role";

grant insert on table "public"."file_upload" to "service_role";

grant references on table "public"."file_upload" to "service_role";

grant select on table "public"."file_upload" to "service_role";

grant trigger on table "public"."file_upload" to "service_role";

grant truncate on table "public"."file_upload" to "service_role";

grant update on table "public"."file_upload" to "service_role";

grant delete on table "public"."log" to "anon";

grant insert on table "public"."log" to "anon";

grant references on table "public"."log" to "anon";

grant select on table "public"."log" to "anon";

grant trigger on table "public"."log" to "anon";

grant truncate on table "public"."log" to "anon";

grant update on table "public"."log" to "anon";

grant delete on table "public"."log" to "authenticated";

grant insert on table "public"."log" to "authenticated";

grant references on table "public"."log" to "authenticated";

grant select on table "public"."log" to "authenticated";

grant trigger on table "public"."log" to "authenticated";

grant truncate on table "public"."log" to "authenticated";

grant update on table "public"."log" to "authenticated";

grant delete on table "public"."log" to "service_role";

grant insert on table "public"."log" to "service_role";

grant references on table "public"."log" to "service_role";

grant select on table "public"."log" to "service_role";

grant trigger on table "public"."log" to "service_role";

grant truncate on table "public"."log" to "service_role";

grant update on table "public"."log" to "service_role";

grant delete on table "public"."logs" to "anon";

grant insert on table "public"."logs" to "anon";

grant references on table "public"."logs" to "anon";

grant select on table "public"."logs" to "anon";

grant trigger on table "public"."logs" to "anon";

grant truncate on table "public"."logs" to "anon";

grant update on table "public"."logs" to "anon";

grant delete on table "public"."logs" to "authenticated";

grant insert on table "public"."logs" to "authenticated";

grant references on table "public"."logs" to "authenticated";

grant select on table "public"."logs" to "authenticated";

grant trigger on table "public"."logs" to "authenticated";

grant truncate on table "public"."logs" to "authenticated";

grant update on table "public"."logs" to "authenticated";

grant delete on table "public"."logs" to "service_role";

grant insert on table "public"."logs" to "service_role";

grant references on table "public"."logs" to "service_role";

grant select on table "public"."logs" to "service_role";

grant trigger on table "public"."logs" to "service_role";

grant truncate on table "public"."logs" to "service_role";

grant update on table "public"."logs" to "service_role";

grant delete on table "public"."mock_data" to "anon";

grant insert on table "public"."mock_data" to "anon";

grant references on table "public"."mock_data" to "anon";

grant select on table "public"."mock_data" to "anon";

grant trigger on table "public"."mock_data" to "anon";

grant truncate on table "public"."mock_data" to "anon";

grant update on table "public"."mock_data" to "anon";

grant delete on table "public"."mock_data" to "authenticated";

grant insert on table "public"."mock_data" to "authenticated";

grant references on table "public"."mock_data" to "authenticated";

grant select on table "public"."mock_data" to "authenticated";

grant trigger on table "public"."mock_data" to "authenticated";

grant truncate on table "public"."mock_data" to "authenticated";

grant update on table "public"."mock_data" to "authenticated";

grant delete on table "public"."mock_data" to "service_role";

grant insert on table "public"."mock_data" to "service_role";

grant references on table "public"."mock_data" to "service_role";

grant select on table "public"."mock_data" to "service_role";

grant trigger on table "public"."mock_data" to "service_role";

grant truncate on table "public"."mock_data" to "service_role";

grant update on table "public"."mock_data" to "service_role";

grant delete on table "public"."product" to "anon";

grant insert on table "public"."product" to "anon";

grant references on table "public"."product" to "anon";

grant select on table "public"."product" to "anon";

grant trigger on table "public"."product" to "anon";

grant truncate on table "public"."product" to "anon";

grant update on table "public"."product" to "anon";

grant delete on table "public"."product" to "authenticated";

grant insert on table "public"."product" to "authenticated";

grant references on table "public"."product" to "authenticated";

grant select on table "public"."product" to "authenticated";

grant trigger on table "public"."product" to "authenticated";

grant truncate on table "public"."product" to "authenticated";

grant update on table "public"."product" to "authenticated";

grant delete on table "public"."product" to "service_role";

grant insert on table "public"."product" to "service_role";

grant references on table "public"."product" to "service_role";

grant select on table "public"."product" to "service_role";

grant trigger on table "public"."product" to "service_role";

grant truncate on table "public"."product" to "service_role";

grant update on table "public"."product" to "service_role";

grant delete on table "public"."sjreport" to "anon";

grant insert on table "public"."sjreport" to "anon";

grant references on table "public"."sjreport" to "anon";

grant select on table "public"."sjreport" to "anon";

grant trigger on table "public"."sjreport" to "anon";

grant truncate on table "public"."sjreport" to "anon";

grant update on table "public"."sjreport" to "anon";

grant delete on table "public"."sjreport" to "authenticated";

grant insert on table "public"."sjreport" to "authenticated";

grant references on table "public"."sjreport" to "authenticated";

grant select on table "public"."sjreport" to "authenticated";

grant trigger on table "public"."sjreport" to "authenticated";

grant truncate on table "public"."sjreport" to "authenticated";

grant update on table "public"."sjreport" to "authenticated";

grant delete on table "public"."sjreport" to "service_role";

grant insert on table "public"."sjreport" to "service_role";

grant references on table "public"."sjreport" to "service_role";

grant select on table "public"."sjreport" to "service_role";

grant trigger on table "public"."sjreport" to "service_role";

grant truncate on table "public"."sjreport" to "service_role";

grant update on table "public"."sjreport" to "service_role";

grant delete on table "public"."sjreport_20240606" to "anon";

grant insert on table "public"."sjreport_20240606" to "anon";

grant references on table "public"."sjreport_20240606" to "anon";

grant select on table "public"."sjreport_20240606" to "anon";

grant trigger on table "public"."sjreport_20240606" to "anon";

grant truncate on table "public"."sjreport_20240606" to "anon";

grant update on table "public"."sjreport_20240606" to "anon";

grant delete on table "public"."sjreport_20240606" to "authenticated";

grant insert on table "public"."sjreport_20240606" to "authenticated";

grant references on table "public"."sjreport_20240606" to "authenticated";

grant select on table "public"."sjreport_20240606" to "authenticated";

grant trigger on table "public"."sjreport_20240606" to "authenticated";

grant truncate on table "public"."sjreport_20240606" to "authenticated";

grant update on table "public"."sjreport_20240606" to "authenticated";

grant delete on table "public"."sjreport_20240606" to "service_role";

grant insert on table "public"."sjreport_20240606" to "service_role";

grant references on table "public"."sjreport_20240606" to "service_role";

grant select on table "public"."sjreport_20240606" to "service_role";

grant trigger on table "public"."sjreport_20240606" to "service_role";

grant truncate on table "public"."sjreport_20240606" to "service_role";

grant update on table "public"."sjreport_20240606" to "service_role";

grant delete on table "public"."store" to "anon";

grant insert on table "public"."store" to "anon";

grant references on table "public"."store" to "anon";

grant select on table "public"."store" to "anon";

grant trigger on table "public"."store" to "anon";

grant truncate on table "public"."store" to "anon";

grant update on table "public"."store" to "anon";

grant delete on table "public"."store" to "authenticated";

grant insert on table "public"."store" to "authenticated";

grant references on table "public"."store" to "authenticated";

grant select on table "public"."store" to "authenticated";

grant trigger on table "public"."store" to "authenticated";

grant truncate on table "public"."store" to "authenticated";

grant update on table "public"."store" to "authenticated";

grant delete on table "public"."store" to "service_role";

grant insert on table "public"."store" to "service_role";

grant references on table "public"."store" to "service_role";

grant select on table "public"."store" to "service_role";

grant trigger on table "public"."store" to "service_role";

grant truncate on table "public"."store" to "service_role";

grant update on table "public"."store" to "service_role";

grant delete on table "public"."store_product" to "anon";

grant insert on table "public"."store_product" to "anon";

grant references on table "public"."store_product" to "anon";

grant select on table "public"."store_product" to "anon";

grant trigger on table "public"."store_product" to "anon";

grant truncate on table "public"."store_product" to "anon";

grant update on table "public"."store_product" to "anon";

grant delete on table "public"."store_product" to "authenticated";

grant insert on table "public"."store_product" to "authenticated";

grant references on table "public"."store_product" to "authenticated";

grant select on table "public"."store_product" to "authenticated";

grant trigger on table "public"."store_product" to "authenticated";

grant truncate on table "public"."store_product" to "authenticated";

grant update on table "public"."store_product" to "authenticated";

grant delete on table "public"."store_product" to "service_role";

grant insert on table "public"."store_product" to "service_role";

grant references on table "public"."store_product" to "service_role";

grant select on table "public"."store_product" to "service_role";

grant trigger on table "public"."store_product" to "service_role";

grant truncate on table "public"."store_product" to "service_role";

grant update on table "public"."store_product" to "service_role";

grant delete on table "public"."task" to "anon";

grant insert on table "public"."task" to "anon";

grant references on table "public"."task" to "anon";

grant select on table "public"."task" to "anon";

grant trigger on table "public"."task" to "anon";

grant truncate on table "public"."task" to "anon";

grant update on table "public"."task" to "anon";

grant delete on table "public"."task" to "authenticated";

grant insert on table "public"."task" to "authenticated";

grant references on table "public"."task" to "authenticated";

grant select on table "public"."task" to "authenticated";

grant trigger on table "public"."task" to "authenticated";

grant truncate on table "public"."task" to "authenticated";

grant update on table "public"."task" to "authenticated";

grant delete on table "public"."task" to "service_role";

grant insert on table "public"."task" to "service_role";

grant references on table "public"."task" to "service_role";

grant select on table "public"."task" to "service_role";

grant trigger on table "public"."task" to "service_role";

grant truncate on table "public"."task" to "service_role";

grant update on table "public"."task" to "service_role";

grant delete on table "public"."task_20240618" to "anon";

grant insert on table "public"."task_20240618" to "anon";

grant references on table "public"."task_20240618" to "anon";

grant select on table "public"."task_20240618" to "anon";

grant trigger on table "public"."task_20240618" to "anon";

grant truncate on table "public"."task_20240618" to "anon";

grant update on table "public"."task_20240618" to "anon";

grant delete on table "public"."task_20240618" to "authenticated";

grant insert on table "public"."task_20240618" to "authenticated";

grant references on table "public"."task_20240618" to "authenticated";

grant select on table "public"."task_20240618" to "authenticated";

grant trigger on table "public"."task_20240618" to "authenticated";

grant truncate on table "public"."task_20240618" to "authenticated";

grant update on table "public"."task_20240618" to "authenticated";

grant delete on table "public"."task_20240618" to "service_role";

grant insert on table "public"."task_20240618" to "service_role";

grant references on table "public"."task_20240618" to "service_role";

grant select on table "public"."task_20240618" to "service_role";

grant trigger on table "public"."task_20240618" to "service_role";

grant truncate on table "public"."task_20240618" to "service_role";

grant update on table "public"."task_20240618" to "service_role";

grant delete on table "public"."task_file" to "anon";

grant insert on table "public"."task_file" to "anon";

grant references on table "public"."task_file" to "anon";

grant select on table "public"."task_file" to "anon";

grant trigger on table "public"."task_file" to "anon";

grant truncate on table "public"."task_file" to "anon";

grant update on table "public"."task_file" to "anon";

grant delete on table "public"."task_file" to "authenticated";

grant insert on table "public"."task_file" to "authenticated";

grant references on table "public"."task_file" to "authenticated";

grant select on table "public"."task_file" to "authenticated";

grant trigger on table "public"."task_file" to "authenticated";

grant truncate on table "public"."task_file" to "authenticated";

grant update on table "public"."task_file" to "authenticated";

grant delete on table "public"."task_file" to "service_role";

grant insert on table "public"."task_file" to "service_role";

grant references on table "public"."task_file" to "service_role";

grant select on table "public"."task_file" to "service_role";

grant trigger on table "public"."task_file" to "service_role";

grant truncate on table "public"."task_file" to "service_role";

grant update on table "public"."task_file" to "service_role";

grant delete on table "public"."task_test" to "anon";

grant insert on table "public"."task_test" to "anon";

grant references on table "public"."task_test" to "anon";

grant select on table "public"."task_test" to "anon";

grant trigger on table "public"."task_test" to "anon";

grant truncate on table "public"."task_test" to "anon";

grant update on table "public"."task_test" to "anon";

grant delete on table "public"."task_test" to "authenticated";

grant insert on table "public"."task_test" to "authenticated";

grant references on table "public"."task_test" to "authenticated";

grant select on table "public"."task_test" to "authenticated";

grant trigger on table "public"."task_test" to "authenticated";

grant truncate on table "public"."task_test" to "authenticated";

grant update on table "public"."task_test" to "authenticated";

grant delete on table "public"."task_test" to "service_role";

grant insert on table "public"."task_test" to "service_role";

grant references on table "public"."task_test" to "service_role";

grant select on table "public"."task_test" to "service_role";

grant trigger on table "public"."task_test" to "service_role";

grant truncate on table "public"."task_test" to "service_role";

grant update on table "public"."task_test" to "service_role";

grant delete on table "public"."user" to "anon";

grant insert on table "public"."user" to "anon";

grant references on table "public"."user" to "anon";

grant select on table "public"."user" to "anon";

grant trigger on table "public"."user" to "anon";

grant truncate on table "public"."user" to "anon";

grant update on table "public"."user" to "anon";

grant delete on table "public"."user" to "authenticated";

grant insert on table "public"."user" to "authenticated";

grant references on table "public"."user" to "authenticated";

grant select on table "public"."user" to "authenticated";

grant trigger on table "public"."user" to "authenticated";

grant truncate on table "public"."user" to "authenticated";

grant update on table "public"."user" to "authenticated";

grant delete on table "public"."user" to "service_role";

grant insert on table "public"."user" to "service_role";

grant references on table "public"."user" to "service_role";

grant select on table "public"."user" to "service_role";

grant trigger on table "public"."user" to "service_role";

grant truncate on table "public"."user" to "service_role";

grant update on table "public"."user" to "service_role";

create policy "Insert own app_user"
on "public"."app_user"
as permissive
for insert
to public
with check ((auth.role() = 'authenticated'::text));


create policy "Select app_user"
on "public"."app_user"
as permissive
for select
to public
using ((auth.role() = 'authenticated'::text));


create policy "Update own app_user"
on "public"."app_user"
as permissive
for update
to public
using ((auth.role() = 'authenticated'::text));


create policy "task_delete"
on "public"."task"
as permissive
for delete
to public
using ((auth.role() = 'authenticated'::text));


create policy "task_insert"
on "public"."task"
as permissive
for insert
to public
with check ((auth.role() = 'authenticated'::text));


create policy "task_update"
on "public"."task"
as permissive
for update
to public
using ((auth.role() = 'authenticated'::text));


CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.app_user FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.app_user_duplicate FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.callsheet FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.callsheet_20240606 FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.callsheet_test FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.client FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.customer FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.customer_client FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.file FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.file_upload FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.log FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.logs FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.mock_data FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.product FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.sjreport FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.sjreport_20240606 FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.store FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.store_product FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.task FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.task_20240618 FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.task_file FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public.task_test FOR EACH ROW EXECUTE FUNCTION log_changes();

CREATE TRIGGER log_changes_trigger AFTER INSERT OR DELETE OR UPDATE ON public."user" FOR EACH ROW EXECUTE FUNCTION log_changes();


create schema if not exists "test_data";


