Status: Accepted Date: 2025-11-01 Context: Issue #280 CORE-ALPHA-DATA-LEAK Deciders: Christian Crumlish (PM), Code Agent, Chief Architect (Claude Sonnet)
During implementation of Issue #280 (data leak remediation), we discovered the need to make an explicit architectural decision about database management across development, alpha testing, and production environments.
main branch have different database than production branch?The root confusion stemmed from treating databases like git branches - assuming they would merge or be shared. This is a category error: code lives in git, data lives in PostgreSQL, and they follow different rules.
We will use separate local databases for each environment, with no automatic synchronization between environments.
┌─────────────────────────────────────────────────────┐
│ GIT REPOSITORY (Code - Shared via git) │
├─────────────────────────────────────────────────────┤
│ main branch → Active development (PM) │
│ production branch → Stable releases (alpha testers) │
└─────────────────────────────────────────────────────┘
↓ git pull/clone
↓ (code only)
┌─────────────────────────────────────────────────────┐
│ LOCAL ENVIRONMENTS (Code + Data - Never Merge) │
├─────────────────────────────────────────────────────┤
│ │
│ Dev Laptop: │
│ Branch: main │
│ PostgreSQL DB #1: {xian: Christian's data} │
│ │
│ Alpha Laptop: │
│ Branch: production │
│ PostgreSQL DB #2: {alfy: generic/test data} │
│ │
│ External Tester: │
│ Branch: production │
│ PostgreSQL DB #3: {tester123: their data} │
│ │
└─────────────────────────────────────────────────────┘
DB #1 ≠ DB #2 ≠ DB #3 (Never merge)
alpha_users.preferences JSONB fieldconfig/PIPER.md (in git, shared)Security and Isolation:
Simplicity:
Development Velocity:
main without breaking alpha testersproduction branchWe considered and rejected a shared development database because:
main changes could break production usersWe explicitly chose manual migration because:
In Git (Shared):
config/
PIPER.md # Generic system config
PIPER.md.backup-YYYYMMDD # Historical backups
scripts/
migrate_personal_data.py # Flexible migration tool
create_test_alpha_user.py # User creation utility
test_user_data_isolation.py # Isolation verification
docs/
ALPHA_DATABASE_ARCHITECTURE.md # Operational guide
adrs/adr-040-local-database.md # This decision record
services/database/
models.py # Table schemas
connection.py # Database connection
Not in Git (.gitignore):
postgres_data/ # PostgreSQL data directory
*.db # SQLite files
.env # Environment variables
uploads/ # User-uploaded files
__pycache__/ # Python cache
# Migrate PM's data to xian account (dev laptop)
python scripts/migrate_personal_data.py --username xian
# Verify alfy user exists, no migration (alpha laptop)
python scripts/migrate_personal_data.py --username alfy --skip-migration
# Migrate custom data from JSON file (future testers)
python scripts/migrate_personal_data.py \
--username tester123 \
--data-file tester_data.json
main Branch:
production Branch:
Merge Flow:
PM develops on main
↓
Test locally with xian account
↓
Merge main → production when stable
↓
Alpha testers pull production branch
↓
Each tester runs on their local database
✅ Security: Strong data isolation, no cross-contamination risk ✅ Privacy: PM’s personal data never exposed to testers ✅ Simplicity: No complex multi-tenant database infrastructure ✅ Control: Each user controls their own data ✅ Rollback: Easy to restore (just local database backup) ✅ Cost: No hosting costs for alpha phase ✅ Development Speed: PM can experiment without breaking testers
⚠️ Manual Migration: Requires explicit work to move alpha → production ⚠️ Documentation: Needs clear explanation (non-obvious to new developers) ⚠️ Setup Complexity: Each tester must set up local PostgreSQL ⚠️ Backup Responsibility: Users responsible for backing up local data ⚠️ No Real-Time Sync: Can’t automatically propagate improvements
📋 Requires Clear Documentation: ALPHA_DATABASE_ARCHITECTURE.md created 📋 Migration Scripts Must Be Flexible: Added –username parameter 📋 Setup Wizard Needed: For alpha tester onboarding 📋 Production Migration Plan: Documented in architecture guide
Architecture:
Rejected Because:
main and production share database?When It Makes Sense:
Architecture:
main branch has one databaseproduction branch has different databaseRejected Because:
Why This Doesn’t Work:
Architecture:
Deferred to MVP Because:
When We’ll Implement This:
Architecture:
data/xian.json)Rejected Because:
Why We Need PostgreSQL:
Security Model:
Acceptable for Alpha Because:
Required Security:
Email Backend Security (from email-service-research-mvp.md):
-- Hosted on Render/Railway/Supabase
CREATE TABLE users (
id UUID PRIMARY KEY,
username TEXT UNIQUE,
email TEXT UNIQUE,
password_hash TEXT,
preferences JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
# On alpha tester's local machine
python scripts/export_user_data.py --username alfy > alfy_data.json
# On production server
python scripts/import_user_data.py \
--username alfy \
--email alfy@example.com \
--data alfy_data.json
✅ User Preferences (from alpha_users.preferences)
✅ User Profile (username, email)
✅ Configuration Overrides (personalization)
❌ NOT Migrated:
Why Manual:
Estimated Time:
Alpha Phase:
Production Phase:
For Alpha Testers:
For Developers:
# Data isolation tests
python -m pytest tests/config/test_data_isolation.py
# UserContextService tests
python -m pytest tests/services/test_user_context_service.py
# Migration script tests
python -m pytest tests/scripts/test_migration.py
# Verify PIPER.md has no personal data
grep -i "christian\|xian\|VA\|DRAGONS" config/PIPER.md
# Expected: No matches
# Test migration script flexibility
python scripts/migrate_personal_data.py --username test-user
# Verify data isolation
python scripts/test_user_data_isolation.py
# Expected: Each user sees only their data
Triggers to Reconsider:
Expected Timeline:
┌─────────────────────────────────────────────┐
│ Production Environment (Hosted) │
├─────────────────────────────────────────────┤
│ │
│ Web Application (Render/Railway) │
│ ├── FastAPI backend │
│ └── React frontend │
│ │
│ PostgreSQL Database (Hosted) │
│ ├── users table (all production users) │
│ ├── Row-level security enabled │
│ └── Encrypted connections (SSL/TLS) │
│ │
│ Email Service (SendGrid) │
│ ├── Verification emails │
│ ├── Password reset │
│ └── Rate limited │
│ │
└─────────────────────────────────────────────┘
This production architecture will be documented in a separate ADR when we reach that phase.
| Date | Event | Decision |
|---|---|---|
| 2025-11-01 08:10 | Discovered confusion about database location | Clarified code vs data separation |
| 2025-11-01 08:12 | Discussed branch strategy with PM | Confirmed separate local databases |
| 2025-11-01 08:21 | Migration script made flexible | Added –username parameter |
| 2025-11-01 08:26 | ADR drafted and accepted | Local database per environment |
Approved by: Christian Crumlish (PM) Date: 2025-11-01 Status: Accepted and Implemented
Implementation Evidence:
Last Updated: 2025-11-01 08:26 AM PT Next Review: Before MVP deployment (when hosting production database)