fix: make fresh database initialization reproducible

This commit is contained in:
2026-08-13 15:49:02 -05:00
parent e89d003d71
commit 5ee457ae35
4 changed files with 103 additions and 67 deletions
+24 -24
View File
@@ -1,30 +1,30 @@
schema_version: 2
id: beer
name: Alcoholic beverage, beer, regular, all
status: active
id: "beer"
name: "Alcoholic beverage, beer, regular, all"
status: "active"
categories:
- unknown
- "beer"
aliases:
- name: beer
kind: search
- name: "beer"
kind: "common"
nutrition_mapping_ids:
- usda_fdc_beer_168746
- "usda_fdc_beer_168746"
allergen_mapping_ids: []
measure_conversions:
- id: usda_168746_83686
from:
quantity: 1.0
unit_id: fluid_ounce_us
to:
quantity: 29.7
unit_id: gram
source:
source_type: usda_fdc
external_id: '168746'
url: https://fdc.nal.usda.gov/food-details/168746/measures
title: Alcoholic beverage, beer, regular, all
publisher: USDA Agricultural Research Service
retrieved_at: '2026-08-12'
reviewed: true
notes: FoodData Central portion ID 83686.
reviewed_at: '2026-08-12'
- id: "usda_168746_83686"
from:
quantity: 1
unit_id: "fluid_ounce_us"
to:
quantity: 29.7
unit_id: "gram"
source:
source_type: "usda_fdc"
external_id: "168746"
url: "https://fdc.nal.usda.gov/food-details/168746/measures"
title: "Alcoholic beverage, beer, regular, all"
publisher: "USDA Agricultural Research Service"
retrieved_at: "2026-08-12"
reviewed: true
notes: "FoodData Central portion ID 83686."
reviewed_at: "2026-08-12"
+35
View File
@@ -0,0 +1,35 @@
schema_version: 2
id: 0_recipe_test
revision: 4
status: draft
title: 0-recipe-test
categories: []
tags: []
yield:
amount:
quantity: 1000
unit_id: gram
scaling:
mode: amount
components:
- id: component_74d895d5
name: main
items:
- id: line_7ea18d07
reference:
ingredient_id: basil
amount:
quantity: 300
unit_id: gram
percentage: 100
basis_member: true
steps:
- id: step_1
order: 1
instruction: place it into the dog shed
- id: step_3ef49eca
order: 2
instruction: assemble the lego set
- id: step_4cd4eb90
order: 3
instruction: become sad
@@ -1,13 +1,13 @@
schema_version: 2
id: alkaline_soy_meat_marinade
revision: 1
revision: 2
status: draft
title: Alkaline Soy Meat Marinade
categories:
- sauce
- sauce
tags:
- marinade
- chicken
- marinade
- chicken
yield:
amount:
quantity: 107.48
@@ -17,44 +17,45 @@ scaling:
mode: hybrid
basis_id: formula_basis
basis_amount:
quantity: 100.0
quantity: 100
unit_id: gram
components:
- id: main
name: Main
items:
- id: line_01_water
reference:
ingredient_id: water
amount:
quantity: 100
unit_id: gram
percentage: 100
basis_member: true
- id: line_02_soy_sauce_light
reference:
ingredient_id: soy_sauce_light
amount:
quantity: 6.38
unit_id: gram
percentage: 6.38
- id: line_03_baking_soda
reference:
ingredient_id: baking_soda
amount:
quantity: 1.1
unit_id: gram
percentage: 1.1
- id: main
name: Main
items:
- id: line_01_water
reference:
ingredient_id: water
amount:
quantity: 100
unit_id: gram
percentage: 100
basis_member: true
- id: line_02_soy_sauce_light
reference:
ingredient_id: soy_sauce_light
amount:
quantity: 6.38
unit_id: gram
percentage: 6.38
- id: line_03_baking_soda
reference:
ingredient_id: baking_soda
amount:
quantity: 1.1
unit_id: gram
percentage: 1.1
steps:
- id: step_01
order: 1
instruction: Combine.
component_ids:
- main
- id: step_02
order: 2
instruction: Mix until dissolved.
component_ids:
- main
- id: step_01
order: 1
instruction: Combine.
component_ids:
- main
- id: step_02
order: 2
instruction: Mix until dissolved.
component_ids:
- main
notes:
- Formula uses a nominal 100 g basis; review yield and revision before activation.
- Formula uses a nominal 100 g basis; review yield and revision before
activation.
+2 -2
View File
@@ -45,7 +45,7 @@ try {
for (const [componentPosition, component] of recipe.components.entries()) {
run("INSERT INTO recipe_components VALUES (?, ?, ?, ?, ?)", [recipe.id, component.id, componentPosition + 1, component.name, json(component.notes)]);
for (const [itemPosition, item] of component.items.entries()) {
run("INSERT INTO recipe_items VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [recipe.id, component.id, item.id, itemPosition + 1, item.reference.ingredient_id ?? null, item.reference.recipe_id ?? null, item.reference.revision ?? null, item.amount.quantity, item.amount.unit_id, item.percentage ?? null, item.basis_member ? 1 : 0, item.optional ? 1 : 0, item.notes ?? null]);
run("INSERT INTO recipe_items(recipe_id, component_id, id, position, ingredient_id, subrecipe_id, subrecipe_revision, quantity, unit_id, percentage, basis_member, optional, notes, nutrition_retention_factor) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [recipe.id, component.id, item.id, itemPosition + 1, item.reference.ingredient_id ?? null, item.reference.recipe_id ?? null, item.reference.revision ?? null, item.amount.quantity, item.amount.unit_id, item.percentage ?? null, item.basis_member ? 1 : 0, item.optional ? 1 : 0, item.notes ?? null, item.nutrition_retention_factor ?? 1]);
for (const [prepPosition, prep] of (item.prep ?? []).entries()) run("INSERT INTO item_prep_actions VALUES (?, ?, ?, ?, ?, ?)", [recipe.id, item.id, prepPosition + 1, prep.action_id, prep.yield_factor ?? null, prep.notes ?? null]);
}
}
@@ -67,7 +67,7 @@ try {
}
for (const mapping of records("source_mappings")) run("INSERT INTO source_mappings VALUES (?, ?, ?, ?, ?, ?, ?)", [mapping.id, mapping.subject.type, mapping.subject.id, mapping.mapping_type, mapping.status, json(mapping.source), mapping.nutrition_per_100g ? json(mapping.nutrition_per_100g) : null]);
for (const collection of records("collections")) {
run("INSERT INTO collections VALUES (?, ?, ?, ?)", [collection.id, collection.name, collection.description ?? null, json(collection)]);
run("INSERT INTO collections(id, name, description, source_json) VALUES (?, ?, ?, ?)", [collection.id, collection.name, collection.description ?? null, json(collection)]);
for (const [position, entry] of (collection.entries ?? []).entries()) run("INSERT INTO collection_recipes VALUES (?, ?, ?)", [collection.id, entry.recipe_id, position + 1]);
}
db.exec("COMMIT");