Schema 1.5.0: holiday calendar registry, citext names; drop num_records
For the coverage-aware holiday-calendar API in TSAPI core (db_base holiday_calendar__get / __set_coverage / __set_metadata / __upsert). - meta.holiday_calendars (name, description, covered_from, covered_to, source, updated_at): a calendar exists when it has a row here, not when it has holidays (retires the 9999-12-31 sentinel row). covered_from/to: the range over which the closure list is complete; both set or both NULL, from <= to (holiday_calendars_coverage_check). - Calendar names are citext in every table (registry, holidays.calendar_name, exchanges.default_holiday_calendar, instruments.holiday_calendar): stored as given, unique and matched case-insensitively -- also in the foreign keys -- as the native TSAPI backend does with COLLATE NOCASE. New extension citext (00_extensions.sql). Name check: non-empty, trimmed, <= 50 characters. - FKs: holidays -> registry ON DELETE CASCADE; exchanges/instruments -> registry ON DELETE RESTRICT (a calendar in use cannot be dropped); ON UPDATE CASCADE everywhere. - meta.series.num_records dropped. Only some write paths maintained it (never C++), it sometimes held an estimate, and it was NULL for a series never written to. Clients ask the table: count(*), or SELECT EXISTS (SELECT 1 FROM <table>) for "is it empty?". - find_schema_problems() covers the new table, columns, constraints and extension, and runs with search_path = pg_catalog so format_type() reports 'public.citext' whatever the caller's search_path. Verified on a fresh database (PG 17): run_setup.py installs it and find_schema_problems() returns zero rows, also for a caller without public on the search_path; constraint behaviour checked by hand (case-insensitive duplicate refused, FK matches any spelling, RESTRICT and CASCADE, coverage and name checks). Re-provision databases (no migration). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cddaec5730
commit
85679b5e78
7 changed files with 81 additions and 13 deletions
13
README.md
13
README.md
|
|
@ -9,7 +9,7 @@ timeseries database. Both client libraries target the schema defined here:
|
|||
Neither project should keep its own copy of the DDL. When the schema changes,
|
||||
it changes **here**, and both projects re-provision / re-test against it.
|
||||
|
||||
Current schema version: **1.3.0** (see [`VERSION`](VERSION); recorded at runtime
|
||||
Current schema version: **1.5.0** (see [`VERSION`](VERSION); recorded at runtime
|
||||
in the `meta.schema_version` table).
|
||||
|
||||
---
|
||||
|
|
@ -23,7 +23,7 @@ TSAPI_SERIESDB_SCHEMA/
|
|||
├── db_config.json.example # copy to db_config.json and edit (gitignored)
|
||||
├── README.md
|
||||
└── sql/
|
||||
├── 00_extensions.sql # pg_trgm
|
||||
├── 00_extensions.sql # pg_trgm, citext
|
||||
├── 01_schemas.sql # meta / series / log schemas
|
||||
├── 02_sequences.sql # id sequences
|
||||
├── 03_tables.sql # meta.* and log.* tables
|
||||
|
|
@ -78,6 +78,15 @@ database.
|
|||
- **Reference tables:** `meta.currencies`, `meta.timezones`, `meta.exchanges`,
|
||||
`meta.instruments`, `meta.sessions`, `meta.holidays`, `meta.security_types`,
|
||||
`meta.schema_version`.
|
||||
- **Holiday calendars (1.5.0):** `meta.holiday_calendars` is the registry -- a
|
||||
calendar exists when it has a row there. It records the coverage range
|
||||
(`covered_from`/`covered_to`: the closure list is complete over it),
|
||||
`description` and `source`. Calendar names are `citext` in every table:
|
||||
stored as given, unique and matched case-insensitively. Foreign keys from
|
||||
`meta.holidays` (cascade on delete), `meta.exchanges` and `meta.instruments`
|
||||
(a calendar still in use cannot be dropped). Clients pass names as untyped
|
||||
parameters (never `::text`) and keep `public` on the `search_path`, so
|
||||
comparisons use the case-insensitive `citext` operators.
|
||||
- **Procedures:** `meta.drop_series` / `_if_exists` / `drop_all_series`,
|
||||
`meta.update_series_last_timestamp`, `meta.refresh_series_timestamps`,
|
||||
`meta.read_series_batch[_cursor|_ohlc]`, `log.notify_event_log`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue