mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 03:14:11 +00:00
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.
This commit is contained in:
+8
-7
@@ -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);
|
||||
CREATE INDEX "assets_name_idx" ON "assets" ("name" COLLATE natural_sort);
|
||||
Reference in New Issue
Block a user