Sync workflow, asst extra input, excel + ppt support and modal updates

This commit is contained in:
willchen96 2026-07-04 23:24:31 +08:00
parent 93f921be90
commit a5fe6d6e04
140 changed files with 13508 additions and 16700 deletions

View file

@ -12,6 +12,7 @@ create extension if not exists "pgcrypto";
create table if not exists public.user_profiles (
id uuid primary key default gen_random_uuid(),
user_id uuid not null unique references auth.users(id) on delete cascade,
email text,
display_name text,
organisation text,
tier text not null default 'Free',
@ -29,6 +30,13 @@ create table if not exists public.user_profiles (
create index if not exists idx_user_profiles_user
on public.user_profiles(user_id);
create unique index if not exists user_profiles_email_lower_unique
on public.user_profiles (lower(email))
where email is not null and btrim(email) <> '';
create index if not exists idx_user_profiles_email
on public.user_profiles(email);
create or replace function public.handle_new_user()
returns trigger
language plpgsql
@ -36,9 +44,11 @@ security definer
set search_path = public
as $$
begin
insert into public.user_profiles (user_id)
values (new.id)
on conflict (user_id) do nothing;
insert into public.user_profiles (user_id, email)
values (new.id, lower(new.email))
on conflict (user_id) do update
set email = excluded.email,
updated_at = now();
return new;
exception when others then
-- Never block signup if the profile insert fails.
@ -186,6 +196,7 @@ create table if not exists public.projects (
user_id text not null,
name text not null,
cm_number text,
practice text,
visibility text not null default 'private',
shared_with jsonb not null default '[]'::jsonb,
created_at timestamptz not null default now(),
@ -323,8 +334,9 @@ create table if not exists public.workflows (
type text not null,
prompt_md text,
columns_config jsonb,
practice text,
is_system boolean not null default false,
language text default 'English',
practice text default 'General Transactions',
jurisdictions text[] default array['General']::text[],
created_at timestamptz not null default now()
);
@ -371,7 +383,9 @@ returns table (
type text,
prompt_md text,
columns_config jsonb,
language text,
practice text,
jurisdictions text[],
is_system boolean,
created_at timestamptz,
allow_edit boolean,
@ -383,19 +397,38 @@ stable
as $$
with owned as (
select
w.*,
w.id,
w.user_id::text as user_id,
w.title,
w.type,
w.prompt_md,
w.columns_config,
w.language,
w.practice,
w.jurisdictions,
false as is_system,
w.created_at,
true as allow_edit,
true as is_owner,
null::text as shared_by_name,
0 as sort_bucket
from public.workflows w
where w.user_id = p_user_id
and w.is_system = false
where w.user_id::text = p_user_id
and (p_type is null or w.type = p_type)
),
shared as (
select
w.*,
w.id,
w.user_id::text as user_id,
w.title,
w.type,
w.prompt_md,
w.columns_config,
w.language,
w.practice,
w.jurisdictions,
false as is_system,
w.created_at,
ws.allow_edit,
false as is_owner,
nullif(trim(up.display_name), '') as shared_by_name,
@ -404,7 +437,7 @@ as $$
join public.workflows w
on w.id = ws.workflow_id
left join public.user_profiles up
on up.user_id::text = ws.shared_by_user_id
on up.user_id::text = ws.shared_by_user_id::text
where lower(ws.shared_with_email) = lower(coalesce(p_user_email, ''))
and (p_type is null or w.type = p_type)
),
@ -420,7 +453,9 @@ as $$
vw.type,
vw.prompt_md,
vw.columns_config,
vw.language,
vw.practice,
vw.jurisdictions,
vw.is_system,
vw.created_at,
vw.allow_edit,
@ -489,7 +524,7 @@ create table if not exists public.chat_messages (
role text not null,
content jsonb,
files jsonb,
annotations jsonb,
citations jsonb,
created_at timestamptz not null default now()
);
@ -549,6 +584,7 @@ returns table (
user_id text,
name text,
cm_number text,
practice text,
shared_with jsonb,
created_at timestamptz,
updated_at timestamptz,
@ -595,6 +631,7 @@ as $$
vp.user_id,
vp.name,
vp.cm_number,
vp.practice,
vp.shared_with,
vp.created_at,
vp.updated_at,