- type
- concept
- created
- Mon Apr 06 2026 02:00:00 GMT+0200 (Central European Summer Time)
- updated
- Mon Apr 06 2026 02:00:00 GMT+0200 (Central European Summer Time)
- sources
- raw/notes/systemPatterns, raw/notes/techContext
- tags
- pattern django database architecture
Companion Table Pattern
abstract
A Django pattern for extending Yardi-synced `managed=False` tables without altering them. Creates a new `managed=True` table with a OneToOne FK pointing to the Yardi model.How It Works
- Yardi tables are read-only (
managed=Falsein Django Meta) — Django NEVER creates, alters, or drops them - To add custom fields (e.g., AI scores, lifecycle states), create a new table with
managed=True - New table has a
OneToOneFieldFK pointing to the Yardi model - Migrations for new tables require superuser:
sudo -u postgres ... migrate - The
propinteluser can only do DML (SELECT/INSERT/UPDATE/DELETE), not DDL
Example
tenant_lease_lifecycle is a companion table that extends Yardi's TenantLease with lifecycle state data.
Why This Matters
- Preserves Yardi data integrity — no risk of breaking the sync
- Allows AI features to store predictions, scores, and states alongside real data
- Clean separation between source-of-truth (Yardi) and intelligence layer (UnitCycle)
Sources
- raw/notes/systemPatterns — architecture patterns
- raw/notes/techContext — database constraints
Related
- wiki/entities/yardi — the system whose tables are protected
- wiki/concepts/lifecycle-state-engine — uses this pattern
- wiki/concepts/tech-stack — overall architecture