From 95f8e9a70bd1f2a4dc6f55eb703f30ec5898c315 Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Thu, 26 Feb 2026 07:40:13 -0500 Subject: [PATCH] Fix column/card ordering: set COLLATE C on position columns Postgres en_US.utf8 collation sorts case-insensitively, breaking the lexicographic fractional indexing. Setting COLLATE "C" ensures pure byte-order sorting. Applied via setup-collation.sql in entrypoint after prisma db push. Co-Authored-By: Claude Opus 4.6 --- docker-entrypoint.sh | 7 +++++++ scripts/setup-collation.sql | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 scripts/setup-collation.sql diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d21e437..758386a 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -20,6 +20,13 @@ if [ $RETRY -ge $MAX_RETRIES ]; then exit 1 fi +echo "Applying position column collation fix..." +if psql "$DATABASE_URL" -f ./scripts/setup-collation.sql; then + echo "Collation fix applied successfully." +else + echo "WARNING: Failed to apply collation fix. Continuing anyway..." +fi + echo "Applying RLS policies..." if psql "$DATABASE_URL" -f ./scripts/setup-rls.sql; then echo "RLS policies applied successfully." diff --git a/scripts/setup-collation.sql b/scripts/setup-collation.sql new file mode 100644 index 0000000..32762df --- /dev/null +++ b/scripts/setup-collation.sql @@ -0,0 +1,6 @@ +-- Set COLLATE "C" on position columns so fractional indexing sorts correctly. +-- en_US.utf8 collation is case-insensitive and breaks lexicographic ordering. +-- This must run after prisma db push since push may reset column types. + +ALTER TABLE columns ALTER COLUMN position SET DATA TYPE text COLLATE "C"; +ALTER TABLE cards ALTER COLUMN position SET DATA TYPE text COLLATE "C";