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
|
|
@ -31,12 +31,17 @@
|
|||
-- The schema VERSION string is not compared here: each client compares
|
||||
-- meta.schema_version with the version it was built for. This function only
|
||||
-- reports a missing version row.
|
||||
--
|
||||
-- The function runs with search_path = pg_catalog, so format_type() spells
|
||||
-- extension types schema-qualified ('public.citext') whatever the caller's
|
||||
-- search_path is.
|
||||
-- ============================================================================
|
||||
|
||||
CREATE OR REPLACE FUNCTION meta.find_schema_problems()
|
||||
RETURNS TABLE(object text, problem text)
|
||||
LANGUAGE plpgsql
|
||||
STABLE
|
||||
SET search_path = pg_catalog, pg_temp
|
||||
AS $function$
|
||||
BEGIN
|
||||
-- Schemas and extension -------------------------------------------------
|
||||
|
|
@ -48,7 +53,7 @@ BEGIN
|
|||
|
||||
RETURN QUERY
|
||||
SELECT 'extension ' || e, 'missing'
|
||||
FROM unnest(ARRAY['pg_trgm']) AS e
|
||||
FROM unnest(ARRAY['citext', 'pg_trgm']) AS e
|
||||
WHERE NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = e)
|
||||
ORDER BY 1;
|
||||
|
||||
|
|
@ -92,12 +97,18 @@ BEGIN
|
|||
('meta.exchanges', 'currency', 'character varying(3)', false),
|
||||
('meta.exchanges', 'default_sec_type', 'character varying(18)', false),
|
||||
('meta.exchanges', 'default_session', 'character varying(40)', false),
|
||||
('meta.exchanges', 'default_holiday_calendar', 'character varying(40)', false),
|
||||
('meta.exchanges', 'default_holiday_calendar', 'public.citext', false),
|
||||
('meta.exchanges', 'default_tick_size', 'double precision', false),
|
||||
('meta.exchanges', 'default_tick_value', 'double precision', false),
|
||||
('meta.exchanges', 'default_extended_hours', 'boolean', false),
|
||||
('meta.exchanges', 'country', 'character varying(3)', false),
|
||||
('meta.holidays', 'calendar_name', 'character varying(50)', true),
|
||||
('meta.holiday_calendars', 'name', 'public.citext', true),
|
||||
('meta.holiday_calendars', 'description', 'text', false),
|
||||
('meta.holiday_calendars', 'covered_from', 'date', false),
|
||||
('meta.holiday_calendars', 'covered_to', 'date', false),
|
||||
('meta.holiday_calendars', 'source', 'text', false),
|
||||
('meta.holiday_calendars', 'updated_at', 'timestamp with time zone', true),
|
||||
('meta.holidays', 'calendar_name', 'public.citext', true),
|
||||
('meta.holidays', 'date', 'date', true),
|
||||
('meta.holidays', 'description', 'character varying(255)', false),
|
||||
('meta.holidays', 'early_close', 'boolean', true),
|
||||
|
|
@ -111,7 +122,7 @@ BEGIN
|
|||
('meta.instruments', 'strike', 'double precision', false),
|
||||
('meta.instruments', 'currency', 'character varying(3)', false),
|
||||
('meta.instruments', 'session', 'character varying(40)', false),
|
||||
('meta.instruments', 'holiday_calendar', 'character varying(50)', false),
|
||||
('meta.instruments', 'holiday_calendar', 'public.citext', false),
|
||||
('meta.instruments', 'sec_id', 'character varying(50)', false),
|
||||
('meta.instruments', 'sec_id_type', 'character varying(20)', false),
|
||||
('meta.instruments', 'description', 'character varying(255)', false),
|
||||
|
|
@ -150,7 +161,6 @@ BEGIN
|
|||
('meta.series', 'sec_id', 'character varying(30)', false),
|
||||
('meta.series', 'sec_id_type', 'character varying(30)', false),
|
||||
('meta.series', 'create_timestamp', 'timestamp without time zone', false),
|
||||
('meta.series', 'num_records', 'bigint', false),
|
||||
('meta.series', 'first_timestamp', 'timestamp without time zone', false),
|
||||
('meta.series', 'last_timestamp', 'timestamp without time zone', false),
|
||||
('meta.series', 'bar_type', 'character varying(30)', false),
|
||||
|
|
@ -218,9 +228,15 @@ BEGIN
|
|||
('log.pending_changes', 'pending_changes_pkey'),
|
||||
('log.event_log', 'event_log_pkey'),
|
||||
('meta.holidays', 'holidays_pkey'),
|
||||
('meta.holidays', 'holidays_calendar_fkey'),
|
||||
('meta.holiday_calendars', 'holiday_calendars_pkey'),
|
||||
('meta.holiday_calendars', 'holiday_calendars_name_check'),
|
||||
('meta.holiday_calendars', 'holiday_calendars_coverage_check'),
|
||||
('log.script_log', 'script_log_pkey'),
|
||||
('meta.instruments', 'instruments_pkey'),
|
||||
('meta.instruments', 'instruments_holiday_calendar_fkey'),
|
||||
('meta.exchanges', 'exchanges_pkey'),
|
||||
('meta.exchanges', 'exchanges_holiday_calendar_fkey'),
|
||||
('meta.sessions', 'sessions_pkey'),
|
||||
('meta.series', 'series_pkey'),
|
||||
('meta.series', 'series_schema_table_key'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue