refactor: update migration files to maintain compatibility and remove redundant column additions

This commit is contained in:
Daniel Volz
2025-12-20 17:49:59 +01:00
parent 70bdc393cc
commit df1ac56948
2 changed files with 6 additions and 16 deletions
@@ -1 +1,3 @@
ALTER TABLE medications ADD COLUMN strips integer NOT NULL DEFAULT 0;
-- Migration 0001: strips column already exists in 0000_init.sql
-- This file is kept for migration history compatibility
SELECT 1;
@@ -1,15 +1,3 @@
ALTER TABLE medications ADD COLUMN pack_count integer NOT NULL DEFAULT 1;
ALTER TABLE medications ADD COLUMN strips_per_pack integer NOT NULL DEFAULT 1;
ALTER TABLE medications ADD COLUMN tabs_per_strip integer NOT NULL DEFAULT 1;
ALTER TABLE medications ADD COLUMN loose_tablets integer NOT NULL DEFAULT 0;
-- Backfill from previous fields where possible
UPDATE medications
SET
pack_count = COALESCE(pack_count, 1),
strips_per_pack = CASE WHEN strips IS NOT NULL THEN strips ELSE 1 END,
tabs_per_strip = CASE WHEN strip_size IS NOT NULL THEN strip_size ELSE 1 END,
loose_tablets = CASE
WHEN strip_size IS NOT NULL AND strips IS NOT NULL THEN MAX(count - (strips * strip_size), 0)
ELSE 0
END;
-- Migration 0002: pack inventory columns already exist in 0000_init.sql
-- This file is kept for migration history compatibility
SELECT 1;