mirror of
https://github.com/willchen96/mike.git
synced 2026-07-26 23:51:08 +02:00
feat: workflow, UI and document support updates
This commit is contained in:
parent
a5fe6d6e04
commit
82dcaefc43
139 changed files with 12554 additions and 2233 deletions
|
|
@ -15,7 +15,6 @@ create table if not exists public.workflow_open_source_submissions (
|
|||
submitted_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now(),
|
||||
reviewed_at timestamptz,
|
||||
reviewed_by_user_id text,
|
||||
review_notes text,
|
||||
constraint workflow_open_source_submissions_status_check
|
||||
check (status in ('pending', 'approved', 'rejected')),
|
||||
|
|
|
|||
41
backend/migrations/20260703_01_user_profile_email.sql
Normal file
41
backend/migrations/20260703_01_user_profile_email.sql
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- Mirror auth.users.email into user_profiles so backend sharing checks can
|
||||
-- resolve one email without scanning Supabase Auth users.
|
||||
|
||||
alter table public.user_profiles
|
||||
add column if not exists email text;
|
||||
|
||||
update public.user_profiles up
|
||||
set email = lower(au.email)
|
||||
from auth.users au
|
||||
where up.user_id = au.id
|
||||
and au.email is not null
|
||||
and (
|
||||
up.email is null
|
||||
or up.email <> lower(au.email)
|
||||
);
|
||||
|
||||
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
|
||||
security definer
|
||||
set search_path = public
|
||||
as $$
|
||||
begin
|
||||
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.
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
84
backend/migrations/20260703_02_project_practice.sql
Normal file
84
backend/migrations/20260703_02_project_practice.sql
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
-- Add optional practice metadata to projects and expose it in the overview RPC.
|
||||
|
||||
alter table public.projects
|
||||
add column if not exists practice text;
|
||||
|
||||
drop function if exists public.get_projects_overview(text, text);
|
||||
|
||||
create or replace function public.get_projects_overview(
|
||||
p_user_id text,
|
||||
p_user_email text default null
|
||||
)
|
||||
returns table (
|
||||
id uuid,
|
||||
user_id text,
|
||||
name text,
|
||||
cm_number text,
|
||||
practice text,
|
||||
shared_with jsonb,
|
||||
created_at timestamptz,
|
||||
updated_at timestamptz,
|
||||
is_owner boolean,
|
||||
owner_display_name text,
|
||||
owner_email text,
|
||||
document_count integer,
|
||||
chat_count integer,
|
||||
review_count integer
|
||||
)
|
||||
language sql
|
||||
stable
|
||||
as $$
|
||||
with visible_projects as (
|
||||
select p.*
|
||||
from public.projects p
|
||||
where p.user_id = p_user_id
|
||||
or (
|
||||
coalesce(p_user_email, '') <> ''
|
||||
and p.user_id <> p_user_id
|
||||
and p.shared_with @> jsonb_build_array(p_user_email)
|
||||
)
|
||||
),
|
||||
document_counts as (
|
||||
select d.project_id, count(*)::integer as document_count
|
||||
from public.documents d
|
||||
where d.project_id in (select vp.id from visible_projects vp)
|
||||
group by d.project_id
|
||||
),
|
||||
chat_counts as (
|
||||
select c.project_id, count(*)::integer as chat_count
|
||||
from public.chats c
|
||||
where c.project_id in (select vp.id from visible_projects vp)
|
||||
group by c.project_id
|
||||
),
|
||||
review_counts as (
|
||||
select tr.project_id, count(*)::integer as review_count
|
||||
from public.tabular_reviews tr
|
||||
where tr.project_id in (select vp.id from visible_projects vp)
|
||||
group by tr.project_id
|
||||
)
|
||||
select
|
||||
vp.id,
|
||||
vp.user_id,
|
||||
vp.name,
|
||||
vp.cm_number,
|
||||
vp.practice,
|
||||
vp.shared_with,
|
||||
vp.created_at,
|
||||
vp.updated_at,
|
||||
vp.user_id = p_user_id as is_owner,
|
||||
nullif(trim(up.display_name), '') as owner_display_name,
|
||||
null::text as owner_email,
|
||||
coalesce(dc.document_count, 0) as document_count,
|
||||
coalesce(cc.chat_count, 0) as chat_count,
|
||||
coalesce(rc.review_count, 0) as review_count
|
||||
from visible_projects vp
|
||||
left join public.user_profiles up
|
||||
on up.user_id::text = vp.user_id
|
||||
left join document_counts dc
|
||||
on dc.project_id = vp.id
|
||||
left join chat_counts cc
|
||||
on cc.project_id = vp.id
|
||||
left join review_counts rc
|
||||
on rc.project_id = vp.id
|
||||
order by vp.created_at desc;
|
||||
$$;
|
||||
19
backend/migrations/20260704_01_chat_message_citations.sql
Normal file
19
backend/migrations/20260704_01_chat_message_citations.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
do $$
|
||||
begin
|
||||
if exists (
|
||||
select 1
|
||||
from information_schema.columns
|
||||
where table_schema = 'public'
|
||||
and table_name = 'chat_messages'
|
||||
and column_name = 'annotations'
|
||||
) and not exists (
|
||||
select 1
|
||||
from information_schema.columns
|
||||
where table_schema = 'public'
|
||||
and table_name = 'chat_messages'
|
||||
and column_name = 'citations'
|
||||
) then
|
||||
alter table public.chat_messages
|
||||
rename column annotations to citations;
|
||||
end if;
|
||||
end $$;
|
||||
Loading…
Add table
Add a link
Reference in a new issue