Database

This directory contains database schema and query modules for the meals app.

Files

  • migrations.ts - Schema definitions and table creation
  • queries.ts - CRUD operations for recipes, ingredients, and instructions

Tables

recipes_v1

Stores recipe metadata including title, source URL, servings, and timing.

ingredients_v1

Stores recipe ingredients with quantity, unit, and notes. Linked to recipes via recipe_id.

instructions_v1

Stores recipe steps in order. Linked to recipes via recipe_id.

Usage

Migrations run automatically on backend startup via runMigrations(). The function uses CREATE TABLE IF NOT EXISTS so it's safe to call multiple times.

To modify a schema, create a new table version (e.g., recipes_v2) rather than using ALTER TABLE, which has limited support in Val Town's SQLite.