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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user