# Schema

Exported from bundle v1 (schema v2, built 2026-07-29).

All nutrient columns are per 100 g of the food as sold or as described, whatever the serving. Empty cells mean the source published no value; nothing is defaulted to zero.

## data.csv

One row per food.

| Column | Type | Meaning |
|---|---|---|
| `id` | integer | The food's id in the app's shared id space. USDA rows are below off_id_base, Open Food Facts rows at or above it. |
| `source` | text | Where the row came from: usda_foundation, usda_sr_legacy, usda_fndds or off. |
| `source_id` | text | The row's id at its source: the FoodData Central fdc_id, or the Open Food Facts barcode. |
| `gtin` | text | Normalised barcode (leading zeros stripped). Open Food Facts rows only. |
| `code` | text | The barcode exactly as Open Food Facts stores it. Open Food Facts rows only. |
| `name` | text | Food or product name. |
| `brand` | text | Brand, when the source has one. |
| `kcal_per_100g` | real | Energy, kcal per 100 g. Empty when the source has none (Open Food Facts rows only; every USDA row has one). |
| `protein_g` | real | Protein, g per 100 g. |
| `carb_g` | real | Carbohydrate, g per 100 g. |
| `fat_g` | real | Total fat, g per 100 g. |
| `fiber_g` | real | Dietary fibre, g per 100 g. Empty means the source published no figure; it is never zero by default. |
| `sugar_g` | real | Sugars, g per 100 g. |
| `sodium_mg` | real | Sodium, mg per 100 g. |
| `sat_fat_g` | real | Saturated fat, g per 100 g. |
| `serving_label` | text | The source's serving description, e.g. "1 serving (30 g)". Open Food Facts rows only. |
| `serving_grams` | real | Weight of that serving in grams, when known. |
| `gram_only` | integer | 1 when the food is logged by weight only (no household measures). USDA rows only; 0 otherwise. |
| `category` | text | The app's own shelf for the food (a curated grouping, not the source's taxonomy). Empty when unmapped. |
| `last_modified_t` | integer | Open Food Facts' last-modified Unix timestamp for the product. Open Food Facts rows only. |

## portions.csv

One row per household measure of a food in data.csv. Open Food Facts rows carry their serving in data.csv itself and have no rows here.

| Column | Type | Meaning |
|---|---|---|
| `id` | integer | Portion id. |
| `food_id` | integer | The id column of data.csv the portion belongs to. |
| `label` | text | Household measure, e.g. "1 cup". |
| `grams` | real | Weight of that measure in grams. |
| `source` | text | Where the measure came from (same vocabulary as data.csv). |

## Notes

- `off_id_base` is 10000000: ids below it are USDA rows, ids at or above it are Open Food Facts rows.
- Both files are UTF-8, comma-separated, RFC 4180 quoting, LF line endings, with a header row.
- Rows are sorted by `id`, so two exports of the same data are byte-identical and two releases diff cleanly.
