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:
+13
-1
@@ -52,6 +52,13 @@ class MigrationRunner {
|
||||
return columns.some(col => col.name === 'sire' || col.name === 'dam');
|
||||
}
|
||||
|
||||
// Check if a table exists (fresh DBs have none — migrations must no-op)
|
||||
tableExists(name) {
|
||||
return !!this.db.prepare(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name = ?"
|
||||
).get(name);
|
||||
}
|
||||
|
||||
// Check if litter_id column exists
|
||||
hasLitterIdColumn() {
|
||||
const columns = this.db.prepare("PRAGMA table_info(dogs)").all();
|
||||
@@ -187,7 +194,12 @@ class MigrationRunner {
|
||||
// Migration 2: Add litter_id column if missing
|
||||
migration002_addLitterIdColumn() {
|
||||
console.log('[Migration 002] Checking for litter_id column...');
|
||||
|
||||
|
||||
if (!this.tableExists('dogs')) {
|
||||
console.log('[Migration 002] Fresh database (no dogs table yet), skipping — init will create it');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.hasLitterIdColumn()) {
|
||||
console.log('[Migration 002] litter_id column already exists, skipping');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user