summaryrefslogtreecommitdiff
path: root/supabase/schema.sql
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 01:28:18 -0800
committerFuwn <[email protected]>2026-02-12 01:52:32 -0800
commit6d8f7ea8b30e229cc0662db8dc3438828feb6880 (patch)
tree9e9270f6f7d6d3cb9c11fb5393eb44e1a44ad418 /supabase/schema.sql
parentfix: invalidate unread counts when toggling individual entry read state (diff)
downloadasa.news-6d8f7ea8b30e229cc0662db8dc3438828feb6880.tar.xz
asa.news-6d8f7ea8b30e229cc0662db8dc3438828feb6880.zip
feat: add drag-and-drop reordering for feeds, folders, and custom feeds
Diffstat (limited to 'supabase/schema.sql')
-rw-r--r--supabase/schema.sql53
1 files changed, 53 insertions, 0 deletions
diff --git a/supabase/schema.sql b/supabase/schema.sql
index 3f91444..fde7232 100644
--- a/supabase/schema.sql
+++ b/supabase/schema.sql
@@ -1030,6 +1030,51 @@ $$;
ALTER FUNCTION "public"."search_entries"("p_query" "text", "p_result_limit" integer) OWNER TO "postgres";
--
+-- Name: reorder_items("text", "uuid"[], integer[]); Type: FUNCTION; Schema: public; Owner: postgres
+--
+
+CREATE OR REPLACE FUNCTION "public"."reorder_items"("target_table" "text", "item_ids" "uuid"[], "new_positions" integer[])
+RETURNS void
+LANGUAGE "plpgsql" SECURITY DEFINER
+SET "search_path" TO ''
+AS $$
+DECLARE
+ current_user_id uuid := auth.uid();
+ i integer;
+BEGIN
+ IF current_user_id IS NULL THEN
+ RAISE EXCEPTION 'Not authenticated';
+ END IF;
+
+ IF array_length(item_ids, 1) IS DISTINCT FROM array_length(new_positions, 1) THEN
+ RAISE EXCEPTION 'item_ids and new_positions must have the same length';
+ END IF;
+
+ IF target_table NOT IN ('subscriptions', 'folders', 'custom_feeds') THEN
+ RAISE EXCEPTION 'Invalid table: %', target_table;
+ END IF;
+
+ FOR i IN 1..array_length(item_ids, 1) LOOP
+ IF target_table = 'subscriptions' THEN
+ UPDATE public.subscriptions
+ SET position = new_positions[i]
+ WHERE id = item_ids[i] AND user_id = current_user_id;
+ ELSIF target_table = 'folders' THEN
+ UPDATE public.folders
+ SET position = new_positions[i]
+ WHERE id = item_ids[i] AND user_id = current_user_id;
+ ELSIF target_table = 'custom_feeds' THEN
+ UPDATE public.custom_feeds
+ SET position = new_positions[i]
+ WHERE id = item_ids[i] AND user_id = current_user_id;
+ END IF;
+ END LOOP;
+END;
+$$;
+
+ALTER FUNCTION "public"."reorder_items"("target_table" "text", "item_ids" "uuid"[], "new_positions" integer[]) OWNER TO "postgres";
+
+--
-- Name: subscribe_to_feed("text", "uuid", "text", "text", "text"); Type: FUNCTION; Schema: public; Owner: postgres
--
@@ -3402,6 +3447,14 @@ GRANT ALL ON FUNCTION "public"."search_entries"("p_query" "text", "p_result_limi
--
+-- Name: FUNCTION "reorder_items"("target_table" "text", "item_ids" "uuid"[], "new_positions" integer[]); Type: ACL; Schema: public; Owner: postgres
+--
+
+GRANT ALL ON FUNCTION "public"."reorder_items"("target_table" "text", "item_ids" "uuid"[], "new_positions" integer[]) TO "authenticated";
+GRANT ALL ON FUNCTION "public"."reorder_items"("target_table" "text", "item_ids" "uuid"[], "new_positions" integer[]) TO "service_role";
+
+
+--
-- Name: FUNCTION "subscribe_to_feed"("feed_url" "text", "target_folder_id" "uuid", "feed_custom_title" "text", "feed_credential" "text", "feed_auth_type" "text"); Type: ACL; Schema: public; Owner: postgres
--