claude-memory/graph/solutions/postgresql-migration-add-default-order-by-id-to-basemodelsel-478cd8.md
Cal Corum b140d4d82a migrate: 313 memories from MemoryGraph
- 313 new markdown files created
- 30 relationships embedded
- 313 entries indexed
- State initialized with usage data
2026-02-13 11:11:48 -06:00

13 lines
712 B
Markdown

---
id: 478cd8a2-efb4-47c2-a215-dcb95f486cf7
type: solution
title: "PostgreSQL migration: Add default ORDER BY id to BaseModel.select()"
tags: [paper-dynasty, postgresql, migration, solution, peewee, ordering]
importance: 0.9
confidence: 0.8
created: "2026-01-31T22:06:36.571809+00:00"
updated: "2026-01-31T22:06:36.571809+00:00"
---
PostgreSQL does not guarantee row order without ORDER BY, unlike SQLite which implicitly returned rows by rowid. This caused bugs like get_team_by_owner returning the wrong team. Solution: Override select() in BaseModel to add default .order_by(cls.id). Explicit .order_by() calls will override this default. Tested with joins, where, limit, aggregations - all work correctly.