Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/database/supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ schema_paths = [
'./schemas/concept.sql',
'./schemas/contributor.sql',
'./schemas/sync.sql',
'./schemas/upload_temp.sql',
'./schemas/access_token.sql',
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
drop function if exists "public"."alpha_delete_by_source_local_ids"(p_space_name text, p_source_local_ids text[]);

drop function if exists "public"."alpha_get_last_update_time"(p_space_name text);

drop function if exists "public"."alpha_upsert_discourse_nodes"(p_space_name text, p_user_email text, p_user_name text, p_nodes jsonb);

drop function if exists "public"."upsert_discourse_nodes"(p_space_name text, p_user_email text, p_user_name text, p_nodes jsonb, p_platform_name text, p_platform_url text, p_space_url text, p_agent_type text, p_content_scale text, p_embedding_model text, p_document_source_id text);

drop function if exists "public"."get_nodes_needing_sync"(nodes_from_roam jsonb);
2 changes: 1 addition & 1 deletion packages/database/supabase/schemas/embedding.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ ALTER TABLE public."ContentEmbedding_openai_text_embedding_3_small_1536" ENABLE

DROP POLICY IF EXISTS embedding_openai_te3s_1536_policy ON public."ContentEmbedding_openai_text_embedding_3_small_1536" ;
CREATE POLICY embedding_openai_te3s_1536_policy ON public."ContentEmbedding_openai_text_embedding_3_small_1536"
FOR ALL USING (public.content_in_space (target_id)) ;
FOR ALL USING (public.content_in_space (target_id)) ;
43 changes: 0 additions & 43 deletions packages/database/supabase/schemas/sync.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,45 +169,6 @@ ALTER FUNCTION public.propose_sync_task(
"task_interval" interval
) OWNER TO "postgres";

CREATE OR REPLACE FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb)
RETURNS TABLE (uid_to_sync text)
SET search_path = ''
LANGUAGE plpgsql
AS $function$
DECLARE
node_info jsonb;
roam_node_uid TEXT;
roam_node_edit_epoch_ms BIGINT;
content_db_last_modified_epoch_ms BIGINT;
BEGIN
FOR node_info IN SELECT * FROM jsonb_array_elements(nodes_from_roam)
LOOP
roam_node_uid := (node_info->>'uid')::text;
roam_node_edit_epoch_ms := (node_info->>'roam_edit_time')::bigint;

-- Get the last_modified time from your Content table for the current node, converting it to epoch milliseconds
-- Assumes your 'last_modified' column in 'Content' is a timestamp type
SELECT EXTRACT(EPOCH FROM c.last_modified) * 1000
INTO content_db_last_modified_epoch_ms
FROM public."Content" c -- Ensure "Content" matches your table name exactly (case-sensitive if quoted)
WHERE c.source_local_id = roam_node_uid;

IF NOT FOUND THEN
-- Node does not exist in Supabase Content table, so it needs sync
uid_to_sync := roam_node_uid;
RETURN NEXT;
ELSE
-- Node exists, compare timestamps
IF roam_node_edit_epoch_ms > content_db_last_modified_epoch_ms THEN
uid_to_sync := roam_node_uid;
RETURN NEXT;
END IF;
END IF;
END LOOP;
RETURN;
END;
$function$
;

GRANT ALL ON TABLE public.sync_info TO "anon";
GRANT ALL ON TABLE public.sync_info TO "authenticated";
Expand Down Expand Up @@ -258,10 +219,6 @@ GRANT ALL ON FUNCTION public.propose_sync_task(
"task_interval" interval
) TO "service_role";

GRANT ALL ON FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb) TO "anon";
GRANT ALL ON FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb) TO "authenticated";
GRANT ALL ON FUNCTION public.get_nodes_needing_sync(nodes_from_roam jsonb) TO "service_role";


CREATE OR REPLACE FUNCTION public.generic_entity_access(target_id BIGINT, target_type public."EntityType") RETURNS boolean
STABLE SECURITY DEFINER
Expand Down
Loading