From b9e35512e56187f4109220d16fee8c2d72c723c5 Mon Sep 17 00:00:00 2001 From: yiling Date: Fri, 29 May 2026 15:30:35 +0800 Subject: [PATCH] fix(db): rename collation from 'numeric' to 'natural_sort' 'numeric' is a reserved keyword and built-in type in PostgreSQL, which can cause syntax parsing issues and ORM compatibility problems when used as a collation name. Renamed to 'natural_sort' to be unambiguous and self-documenting. --- .../migration.sql | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/prisma/migrations/20260529071410_add_natural_sort_collation_to_assets_name/migration.sql b/prisma/migrations/20260529071410_add_natural_sort_collation_to_assets_name/migration.sql index 1ea8bdb9..b864e728 100644 --- a/prisma/migrations/20260529071410_add_natural_sort_collation_to_assets_name/migration.sql +++ b/prisma/migrations/20260529071410_add_natural_sort_collation_to_assets_name/migration.sql @@ -1,16 +1,17 @@ --- Create ICU numeric collation for natural sort (numbers sort by value, not lexicographically) +-- Create ICU collation for natural sort (numbers sort by value, not lexicographically) +-- Named 'natural_sort' to avoid conflict with the 'numeric' reserved keyword / built-in type in PostgreSQL DO $$ BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_collation WHERE collname = 'numeric') THEN - CREATE COLLATION numeric (provider = icu, locale = 'en@colNumeric=yes'); + IF NOT EXISTS (SELECT 1 FROM pg_collation WHERE collname = 'natural_sort') THEN + CREATE COLLATION natural_sort (provider = icu, locale = 'en@colNumeric=yes'); END IF; END; $$; --- Alter assets.name to use the numeric collation +-- Alter assets.name to use the natural_sort collation -- This makes all ORDER BY name queries (ORM and raw SQL) use natural sort automatically -ALTER TABLE "assets" ALTER COLUMN "name" TYPE TEXT COLLATE numeric; +ALTER TABLE "assets" ALTER COLUMN "name" TYPE TEXT COLLATE natural_sort; --- CreateIndex: B-tree index on name using the numeric collation +-- CreateIndex: B-tree index on name using the natural_sort collation -- Supports efficient ORDER BY name ASC/DESC without seq scans -CREATE INDEX "assets_name_idx" ON "assets" ("name" COLLATE numeric); \ No newline at end of file +CREATE INDEX "assets_name_idx" ON "assets" ("name" COLLATE natural_sort); \ No newline at end of file