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
|
|
@ -38,6 +38,28 @@ ALTER TABLE meta.series ADD CONSTRAINT series_db_schema_fkey
|
|||
ALTER TABLE meta.series ADD CONSTRAINT series_table_name_check
|
||||
CHECK (table_name ~ '^[a-z_][a-z0-9_]*$' AND octet_length(table_name) <= 63);
|
||||
|
||||
-- Holiday calendar registry (1.5.0). citext keys: unique and referenced
|
||||
-- case-insensitively, stored as given.
|
||||
ALTER TABLE meta.holiday_calendars ADD CONSTRAINT holiday_calendars_pkey PRIMARY KEY (name);
|
||||
ALTER TABLE meta.holiday_calendars ADD CONSTRAINT holiday_calendars_name_check
|
||||
CHECK (name <> '' AND name::text = btrim(name::text) AND char_length(name::text) <= 50);
|
||||
ALTER TABLE meta.holiday_calendars ADD CONSTRAINT holiday_calendars_coverage_check
|
||||
CHECK ((covered_from IS NULL) = (covered_to IS NULL)
|
||||
AND (covered_from IS NULL OR covered_from <= covered_to));
|
||||
|
||||
-- Holidays belong to their calendar: dropping the calendar drops them.
|
||||
ALTER TABLE meta.holidays ADD CONSTRAINT holidays_calendar_fkey
|
||||
FOREIGN KEY (calendar_name) REFERENCES meta.holiday_calendars (name)
|
||||
ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
-- A calendar still named by an exchange or instrument cannot be dropped.
|
||||
ALTER TABLE meta.exchanges ADD CONSTRAINT exchanges_holiday_calendar_fkey
|
||||
FOREIGN KEY (default_holiday_calendar) REFERENCES meta.holiday_calendars (name)
|
||||
ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
ALTER TABLE meta.instruments ADD CONSTRAINT instruments_holiday_calendar_fkey
|
||||
FOREIGN KEY (holiday_calendar) REFERENCES meta.holiday_calendars (name)
|
||||
ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
CREATE INDEX idx_event_log_series_timestamp ON log.event_log USING btree (series_name, "timestamp" DESC);
|
||||
|
||||
CREATE INDEX idx_event_log_timestamp ON log.event_log USING btree ("timestamp" DESC);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue