From 1626669b17a97b115facd15c36d347201fc78dc2 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Sun, 25 Jan 2026 19:04:51 -0500 Subject: [PATCH] add sort_data column and use it --- .../dashboard/PublishedPostsLists.tsx | 1 + supabase/database.types.ts | 1 + .../20260125000000_add_sort_date_column.sql | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 supabase/migrations/20260125000000_add_sort_date_column.sql diff --git a/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx b/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx index 69f9735f..b8a24406 100644 --- a/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx +++ b/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx @@ -111,6 +111,7 @@ function PublishedPostItem(props: { documents: { uri: doc.uri, indexed_at: doc.indexed_at, + sort_date: doc.sort_date, data: doc.data, }, }, diff --git a/supabase/database.types.ts b/supabase/database.types.ts index a385b699..ed234f44 100644 --- a/supabase/database.types.ts +++ b/supabase/database.types.ts @@ -337,6 +337,7 @@ export type Database = { Row: { data: Json indexed_at: string + sort_date: string uri: string } Insert: { diff --git a/supabase/migrations/20260125000000_add_sort_date_column.sql b/supabase/migrations/20260125000000_add_sort_date_column.sql new file mode 100644 index 00000000..483fcf2a --- /dev/null +++ b/supabase/migrations/20260125000000_add_sort_date_column.sql @@ -0,0 +1,14 @@ +-- Add sort_date computed column to documents table +-- This column stores the older of publishedAt (from JSON data) or indexed_at +-- Used for sorting feeds chronologically by when content was actually published + +ALTER TABLE documents +ADD COLUMN sort_date timestamptz GENERATED ALWAYS AS ( + LEAST( + COALESCE((data->>'publishedAt')::timestamptz, indexed_at), + indexed_at + ) +) STORED; + +-- Create index on sort_date for efficient ordering +CREATE INDEX documents_sort_date_idx ON documents (sort_date DESC, uri DESC); -- 2.51.2