fix: enforce C collation for page position ordering to ensure consistent behavior in Postgres 17+ (#1446)

- Add explicit C collation to position ordering queries to fix incorrect page placement in PostgreSQL 17+
- Ensures consistent ASCII-based ordering regardless of database locale settings
- Fixes issue where new pages were incorrectly placed at random positions instead of bottom
This commit is contained in:
Philip Okugbe
2025-08-04 09:49:29 +01:00
committed by GitHub
parent cb2a0398c7
commit 3b85f4b616
2 changed files with 3 additions and 3 deletions

View File

@ -110,7 +110,7 @@ export class PageService {
.select(['position']) .select(['position'])
.where('spaceId', '=', spaceId) .where('spaceId', '=', spaceId)
.where('deletedAt', 'is', null) .where('deletedAt', 'is', null)
.orderBy('position', 'desc') .orderBy('position', (ob) => ob.collate('C').desc())
.limit(1); .limit(1);
if (parentPageId) { if (parentPageId) {
@ -191,7 +191,7 @@ export class PageService {
'deletedAt', 'deletedAt',
]) ])
.select((eb) => this.pageRepo.withHasChildren(eb)) .select((eb) => this.pageRepo.withHasChildren(eb))
.orderBy('position', 'asc') .orderBy('position', (ob) => ob.collate('C').asc())
.where('deletedAt', 'is', null) .where('deletedAt', 'is', null)
.where('spaceId', '=', spaceId); .where('spaceId', '=', spaceId);

View File

@ -178,7 +178,7 @@ export class ImportService {
.selectFrom('pages') .selectFrom('pages')
.select(['id', 'position']) .select(['id', 'position'])
.where('spaceId', '=', spaceId) .where('spaceId', '=', spaceId)
.orderBy('position', 'desc') .orderBy('position', (ob) => ob.collate('C').desc())
.limit(1) .limit(1)
.where('parentPageId', 'is', null) .where('parentPageId', 'is', null)
.executeTakeFirst(); .executeTakeFirst();