Fix schema drift: fresh installs were broken

- Create heat_cycles table in init.js (breeding.js used it but nothing created it)
- Add litters columns the routes actually use (breeding_date, whelping_date, puppy_count)
- Add health_records columns used by puppy logs (record_date, description)
- Puppy log insert now also sets NOT NULL test_date
- Migration 002 no-ops on a fresh DB instead of crashing on missing dogs table
- init.js honors DB_PATH and creates the data dir, so migrations and the app
  always target the same file

Verified: full heat-cycle/litter/puppy-log CRUD passes against a virgin database.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jason Stedwell
2026-07-06 14:45:22 -05:00
parent c9d2aa734e
commit ce287f63d1
3 changed files with 54 additions and 6 deletions
+4 -3
View File
@@ -214,10 +214,11 @@ router.post('/:litterId/puppies/:puppyId/logs', (req, res) => {
notes: notes || ''
});
// test_date mirrors record_date: the column is NOT NULL on fresh schemas
const result = db.prepare(`
INSERT INTO health_records (dog_id, record_type, record_date, description, vet_name)
VALUES (?, ?, ?, ?, ?)
`).run(puppyId, record_type || 'weight_log', record_date, description, null);
INSERT INTO health_records (dog_id, record_type, record_date, test_date, description, vet_name)
VALUES (?, ?, ?, ?, ?, ?)
`).run(puppyId, record_type || 'weight_log', record_date, record_date, description, null);
const log = db.prepare('SELECT * FROM health_records WHERE id = ?').get(result.lastInsertRowid);
res.status(201).json(log);