recipe-manager/migrations/2026-03-25-schema-migration.md

2.0 KiB

Recipe Manager DB Schema Migration — 2026-03-25

Schema Diff (current → MVP target)

The current schema (src/backend/db/schema.sql) differs from the Step 2 MVP spec in docs/recipe-manager-mvp-plan.md as follows:

recipes table

Current:

  • Has columns: id, title, description, ingredients (JSON), instructions (JSON), source_url, notes, servings, prep_time_minutes, cook_time_minutes, created_at (INTEGER), updated_at (INTEGER), last_cooked_at

Target:

  • Should be normalized: No JSON columns for ingredients/instructions. Should instead link to separate ingredients and steps tables via recipe_id FK.
  • Remove: ingredients, instructions, notes, last_cooked_at columns.
  • created_at and updated_at should be DATETIME.

ingredients table

  • Does NOT exist in current schema. Add ingredients table:
    • id (PK)
    • recipe_id (FK)
    • position (INTEGER)
    • quantity (TEXT)
    • unit (TEXT)
    • item (TEXT, required)
    • notes (TEXT)

steps table

  • Does NOT exist. Add steps table:
    • id (PK)
    • recipe_id (FK)
    • position (INTEGER)
    • instruction (TEXT, required)

tags/recipe_tags

  • Already present (mostly matches spec)
  • Remove color column from tags (not in MVP spec)
  • "name" should be unique and required (already declared)

Indexes

  • Add idx_ingredients_item on ingredients(item)
  • Add idx_recipe_tags_tag_id on recipe_tags(tag_id) (already present)

Migration Steps

  1. Create new ingredients and steps tables
  2. Populate ingredients & steps tables from JSON columns of recipes
  3. Migrate tags: drop color column from tags (if exists)
  4. Drop ingredients, instructions, notes, last_cooked_at columns from recipes
  5. Change created_at, updated_at columns to DATETIME
  6. Add new indexes (ingredients(item))
  7. Update test data and migration documentation

Notes

  • This migration normalizes the schema: recipes → ingredients & steps as separate tables
  • Data in existing recipes.ingredients and instructions must be extracted and split into new tables

Status: DRAFT — pending implementation