fix: Migration 003 - dynamic column restore to handle missing updated_at #42

Merged
jason merged 1 commits from fix/migration-003-dynamic-columns into master 2026-03-10 14:32:37 -05:00
Owner

Problem

Migration 003 hardcoded updated_at in the INSERT ... SELECT restore statement. The old health_records table never had an updated_at column (it was only added in newer schema versions via ALTER TABLE), so the migration crashed with:

no such column: updated_at

Fix

Instead of hardcoding the column list, Migration 003 now:

  1. Runs PRAGMA table_info(health_records_migration_backup) after creating the backup
  2. Builds the restore column list dynamically — only including columns that actually exist in the backup
  3. Logs both the detected columns and restored columns for transparency

New columns added in the fresh table (updated_at) will receive their DEFAULT (datetime('now')) value automatically for any restored rows.

Result

Migration 003 is now resilient to any column additions that happened via ALTER TABLE on old installs.

## Problem Migration 003 hardcoded `updated_at` in the `INSERT ... SELECT` restore statement. The old `health_records` table never had an `updated_at` column (it was only added in newer schema versions via `ALTER TABLE`), so the migration crashed with: ``` no such column: updated_at ``` ## Fix Instead of hardcoding the column list, Migration 003 now: 1. Runs `PRAGMA table_info(health_records_migration_backup)` after creating the backup 2. Builds the restore column list dynamically — only including columns that **actually exist** in the backup 3. Logs both the detected columns and restored columns for transparency New columns added in the fresh table (`updated_at`) will receive their `DEFAULT (datetime('now'))` value automatically for any restored rows. ## Result Migration 003 is now resilient to any column additions that happened via `ALTER TABLE` on old installs.
jason added 1 commit 2026-03-10 14:32:12 -05:00
jason merged commit d5bce0522b into master 2026-03-10 14:32:37 -05:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jason/breedr#42