# `travel@1`: days present in each country

Version **1.1.0** · published 2026-11-29 · MIT · boards: days-abroad · [changelog](../CHANGELOG.md)

One row of `stays` is one contiguous stretch in one country. The importer expands stays into `stay_days` (one row per
calendar day from the first to the last day, gaps included) so metrics count days without date maths. `thresholds`
holds the reference rules a board draws (rolling windows, calendar years, the US substantial presence test, Schengen
90/180); they are configurable examples, not advice.

1.0.0 was the schema Days Abroad shipped with, published unchanged. 1.1.0 (a minor: optional additions only) adds
provenance and an optional city to `stays`, and finance@2's annotation columns.

## Conventions
- **Day rule:** a stay covers `start_date <= day < end_date`. The arrival day counts for the country you arrive in;
  the departure day belongs to the next stay. `nights = end_date - start_date`.
- Countries are ISO 3166-1 alpha-2, or an `X`-prefixed region code when the source names only a region (`XE` = Europe).
- **Source location:** `stays.source_tab` and `source_row` are where the row came from: for a Google Sheet the tab and
  row; for a CSV the file name and line. (They are sheet-shaped names; renaming them waits for travel@2.)
- **Provenance (1.1):** `stays.source` names the connector that wrote the row (`stays-csv`, `google-sheet`;
  later `calendar-ics`, `manual`), `source_ref` says where in the source (`data/stays.csv:12`, `Travel Log!A12`), and
  `imported_at` is the import instant (ISO 8601 UTC). `imported_at` is left out of `meta.data_hash`, so re-importing the
  same file gives the same hash. Connectors written for 1.1 fill all three; the conformance check is at `warn`.
- **City (1.1):** `stays.city` is optional free text as the source wrote it (`Lisbon`). Day counts never use it: rules
  count countries. Boards must render a stay without a city.
- `sheet_summaries` is an optional reconciliation table: the source's own totals, so checks can prove the board
  reproduces them. `plan_slots` is the optional 48-slot year plan grid.
- meta required keys: `schema`, `schema_version`, `as_of`, `data_hash`. 1.1 recommends `source_built_at` (checked at
  `warn`; required from travel@2).
- **Annotations (1.1):** the columns of finance@2's `annotations` (`annotation_id`, `kind`, `author`, `source_ref`,
  `created_at`, `data_hash`, `status`) are here as optional columns. The key stays `(target, body)`: making
  `annotation_id` the key, or any of them NOT NULL, is a major and waits for travel@2.

## Sources that fill it
| Source | Lane | Fills |
|---|---|---|
| A stays CSV (`start_date,end_date,country[,city,note]`, or a known layout: the Travel Log sheet downloaded as CSV, arrive/depart and check-in/check-out logs) | 1 | countries (from inputs), stays (`source = stays-csv`), stay_days, data_issues |
| A Google Sheet travel log read by the assistant's connector, only with the person's consent (rows pass through the assistant's provider) | 3 | the same (`source = google-sheet`), plus sheet_summaries and plan_slots |
| A calendar `.ics` (flights, hotels), Google Maps Timeline | 1 | later mappers |

## Compatibility
- A board that declares `travel@1 >=1.0` keeps working on any later 1.x database: 1.1 only adds optional columns.
- A board that reads `stays.city` or the provenance columns declares `>=1.1` and renders NULL sensibly.
- Remixes that add only metrics, pages and `x_<owner>_` tables survive every minor.

## Fields

<!-- fields:begin (generated from schema.sql by spec/build.py; edit the DDL comments) -->

### `meta` (required table)

Key/value facts about this database. Required: schema, schema_version, as_of, data_hash. 1.1 recommends source_built_at (ISO 8601 UTC instant the importer wrote it), checked at warn.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `key` | TEXT | no |  |
| `value` | TEXT | no |  |

### `countries` (required table)

| Field | Type | Required | Meaning |
|---|---|---|---|
| `country_code` | TEXT (country) | no | ISO 3166-1 alpha-2, or X-prefixed region code (XE = Europe, unspecified) |
| `name` | TEXT | **yes** | display name |
| `source_label` | TEXT | **yes** | label as written in the source sheet |
| `region` | TEXT | **yes** | South America, Central America, North America, Europe, Asia ... |
| `schengen` | INTEGER | **yes** | 1 = Schengen area, 2 = assumed Schengen (region label only) |
| `is_region` | INTEGER | **yes** | 1 = the sheet names a region, not a country |
| `is_home` | INTEGER | **yes** | citizenship country (inputs.yaml) |
| `color_idx` | INTEGER | **yes** | stable index into the chart palette tokens |

### `stays` (required table)

| Field | Type | Required | Meaning |
|---|---|---|---|
| `stay_id` | TEXT | no | S + start date + country |
| `start_date` | TEXT (date) | **yes** | ISO date, first day counted |
| `end_date` | TEXT (date) | **yes** | ISO date, exclusive (the next stay's start) |
| `nights` | INTEGER | **yes** | end_date - start_date |
| `country_code` | TEXT (country) | **yes** |  |
| `sheet_year` | INTEGER | no | the sheet's Year column |
| `sheet_days` | INTEGER | no | the sheet's Days column (DATEDIF) |
| `source_tab` | TEXT | **yes** | source location: the sheet tab, or the file name for a CSV |
| `source_row` | INTEGER | **yes** | 1-based row in the source tab, or the line in the file |
| `adjusted` | TEXT | no | importer adjustment applied (e.g. year_end_fill), else NULL |
| `city` | TEXT | no | 1.1: optional place within the country, as written in the source (e.g. Lisbon) |
| `source` | TEXT | no | 1.1: connector id that wrote the row: stays-csv \| google-sheet \| calendar-ics \| manual |
| `source_ref` | TEXT | no | 1.1: where in the source: file:line (data/stays.csv:12) or tab!row (Travel Log!A12) |
| `imported_at` | TEXT (instant) | no | 1.1: ISO 8601 UTC instant of the import (left out of meta.data_hash) |

### `stay_days` (required table)

| Field | Type | Required | Meaning |
|---|---|---|---|
| `day` | TEXT (date) | no | every calendar day from the first to the last stay, gaps included |
| `country_code` | TEXT | no | NULL = not covered by any stay |
| `stay_id` | TEXT | no |  |
| `year` | INTEGER | **yes** |  |
| `month` | TEXT (month) | **yes** | YYYY-MM |
| `doy` | INTEGER | **yes** | day of year, 1-based |

### `thresholds` (required table)

| Field | Type | Required | Meaning |
|---|---|---|---|
| `rule_id` | TEXT | no |  |
| `label` | TEXT | **yes** |  |
| `kind` | TEXT (vocab `threshold_kinds`) | **yes** |  |
| `country_code` | TEXT | no | NULL for schengen (uses countries.schengen) |
| `window_days` | INTEGER | no | rolling / schengen window length |
| `limit_days` | INTEGER | **yes** | reference line: days allowed before the rule is met |
| `min_days` | INTEGER | no | us_spt: minimum current-year days |
| `source` | TEXT | **yes** | 'sheet' (the workbook itself) or 'reference' (general rule, not in the sheet) |
| `source_note` | TEXT | no |  |
| `ord` | INTEGER | **yes** |  |

### `plan_slots`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `tab` | TEXT | **yes** | 'Travel Plan' or 'Travel Plan - EU' |
| `year` | INTEGER | **yes** |  |
| `slot` | INTEGER | **yes** | 1..48: four slots per month (about a week each) |
| `month` | INTEGER | **yes** |  |
| `location` | TEXT | no | plan-grid label, e.g. City A, City B, Global |
| `country_code` | TEXT | no | mapped through inputs.yaml plan_locations (NULL for Global) |
| `note` | TEXT | no | the note row under the grid (events), on the slot where it is written |

### `sheet_summaries`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `tab` | TEXT | **yes** |  |
| `year` | INTEGER | **yes** |  |
| `measure` | TEXT | **yes** | calendar_year \| prev_365 \| prev_187 \| plan_days |
| `label` | TEXT | **yes** | country or plan location as written |
| `value` | REAL | no |  |
| `source_cell` | TEXT | **yes** |  |

### `data_issues`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `issue_id` | TEXT | no |  |
| `severity` | TEXT (vocab `severities`) | **yes** |  |
| `kind` | TEXT | **yes** |  |
| `title` | TEXT | **yes** |  |
| `detail` | TEXT | **yes** |  |
| `source_tab` | TEXT | no |  |
| `source_cell` | TEXT | no |  |
| `handling` | TEXT | **yes** | what the importer did about it |

### `annotations`

Notes on metrics and pages (platform table). Numbers only through {{metric:...}} placeholders. 1.1 adds finance@2's columns as optional ones; the key stays (target, body) until travel@2.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `target` | TEXT | no | metric id or page id |
| `body` | TEXT | no | the note text |
| `annotation_id` | TEXT | no | 1.1: stable id |
| `kind` | TEXT | no | 1.1: note \| caveat \| flag \| decision \| open_item |
| `author` | TEXT | no | 1.1: person or assistant |
| `source_ref` | TEXT | no | 1.1: where it came from |
| `created_at` | TEXT | no | 1.1: ISO 8601 instant |
| `data_hash` | TEXT | no | 1.1: hash of the cited metric values when written (stale when they change) |
| `status` | TEXT | no | 1.1: active \| stale \| retired |

### `metric_registry`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `metric_id` | TEXT | no |  |
| `version` | INTEGER | no |  |
| `unit` | TEXT | no |  |
| `params` | TEXT | no |  |
| `description` | TEXT | no |  |
| `sql` | TEXT | no |  |
| `test` | TEXT | no |  |

<!-- fields:end -->

## Vocabularies
| File | Controls |
|---|---|
| `vocab/threshold_kinds.csv` | `thresholds.kind` |
| `vocab/severities.csv` | `data_issues.severity` |
| `vocab/countries.csv` (1.1) | Reference list for connectors: ISO 3166-1 alpha-2 code, English name, region, Schengen membership (2025: 29 countries, plus Åland) and common aliases, so a log that says `ES`, `Spain` or `España` maps to one country. Not an enum: `X`-prefixed region codes stay allowed. Compiled from prior knowledge, not yet checked line by line against ISO 3166 or the EU's list: Schengen = the 29 members as of 2025 (Bulgaria and Romania from 1 Jan 2025) plus Åland; Monaco, San Marino and Vatican City have open borders but are not members and are marked 0. A board's `countries:` in inputs overrides any row |

## Conformance checks
See `checks.yaml`: nights consistent, no overlaps, a contiguous day calendar, day rows agree with their stay, known
countries, complete rules (all `fail`); 1.1 adds stays provenance and `meta.source_built_at` at `warn`.
