heres what I want:
You are the expert. I need a SQL script to be run by supabase cron job. It will be run every hour. Check if the user's time has hit 4am in their local time. If so, for each task that the user has enabled in user_tasks, create a task in user_task_status without a completed_at.
Here are the schemas for the tables:
create table public."Users" (
id uuid not null default gen_random_uuid (),
created_at timestamp with time zone not null default now(),
first_name character varying null,
last_name character varying null,
email character varying null,
phone_number character varying null,
constraint Users_pkey primary key (id),
constraint fk_users_auth_user foreign KEY (id) references auth.users (id) on delete CASCADE
) TABLESPACE pg_default;
create index IF not exists idx_users_auth_id on public."Users" using btree (id) TABLESPACE pg_default;
create trigger create_new_user_tasks_trigger
after INSERT on "Users" for EACH row
execute FUNCTION create_new_user_tasks ();
create table public.user_task_status (
id uuid not null default gen_random_uuid (),
created_at timestamp with time zone not null default now(),
user_id uuid not null,
task_id uuid not null,
completed_at timestamp with time zone null,
completion_data json null,
constraint user_task_status_pkey primary key (id),
constraint user_task_status_task_id_fkey foreign KEY (task_id) references user_tasks (id) on update CASCADE on delete CASCADE,
constraint user_task_status_user_id_fkey foreign KEY (user_id) references "Users" (id) on update CASCADE on delete CASCADE
) TABLESPACE pg_default;
create table public.user_task_status (
id uuid not null default gen_random_uuid (),
created_at timestamp with time zone not null default now(),
user_id uuid not null,
task_id uuid not null,
completed_at timestamp with time zone null,
completion_data json null,
constraint user_task_status_pkey primary key (id),
constraint user_task_status_task_id_fkey foreign KEY (task_id) references user_tasks (id) on update CASCADE on delete CASCADE,
constraint user_task_status_user_id_fkey foreign KEY (user_id) references "Users" (id) on update CASCADE on delete CASCADE
) TABLESPACE pg_default;