a tool for shared writing and social publishing

make timestamp cast immutable

+3 -1
+3 -1
supabase/migrations/20260125000000_add_sort_date_column.sql
··· 2 2 -- This column stores the older of publishedAt (from JSON data) or indexed_at 3 3 -- Used for sorting feeds chronologically by when content was actually published 4 4 5 + -- Note: We use ::timestamp AT TIME ZONE 'UTC' to make the expression immutable 6 + -- (direct ::timestamptz cast is not immutable as it depends on session timezone) 5 7 ALTER TABLE documents 6 8 ADD COLUMN sort_date timestamptz GENERATED ALWAYS AS ( 7 9 LEAST( 8 - COALESCE((data->>'publishedAt')::timestamptz, indexed_at), 10 + COALESCE((data->>'publishedAt')::timestamp AT TIME ZONE 'UTC', indexed_at), 9 11 indexed_at 10 12 ) 11 13 ) STORED;