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

712 B

id type title tags importance confidence created updated
478cd8a2-efb4-47c2-a215-dcb95f486cf7 solution PostgreSQL migration: Add default ORDER BY id to BaseModel.select()
paper-dynasty
postgresql
migration
solution
peewee
ordering
0.9 0.8 2026-01-31T22:06:36.571809+00:00 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.