Canonical TSAPI series DB schema v1.0.0
Single source of truth for the timeseries PostgreSQL schema shared by the Python (TSAPI_SERIESDB_PG_PY) and C++ (TSAPI_POSTGRES_CPP) libraries. SQL seeded byte-for-byte from TSAPI_SERIESDB_PG_PY/tsapi_pgdb/sql on 2026-09-02. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
eed06559c0
17 changed files with 2080 additions and 0 deletions
44
sql/08_script_log.sql
Normal file
44
sql/08_script_log.sql
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
-- ============================================================================
|
||||
-- Script Logging Table
|
||||
-- ============================================================================
|
||||
-- Persistent log for import scripts and library operations.
|
||||
-- Provides queryable event log without cluttering CLI output.
|
||||
--
|
||||
-- Usage:
|
||||
-- session = db.log_session("import_ohlc.py")
|
||||
-- session.info("Starting import for AAPL")
|
||||
-- session.warning("Missing data for 2024-01-15")
|
||||
-- session.error("Failed to parse file", details={"file": "bad.csv"})
|
||||
-- ============================================================================
|
||||
|
||||
-- Create script_log table in log schema
|
||||
CREATE TABLE IF NOT EXISTS log.script_log (
|
||||
id SERIAL PRIMARY KEY,
|
||||
timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
level VARCHAR(10) NOT NULL DEFAULT 'INFO' CHECK (level IN ('DEBUG', 'INFO', 'WARNING', 'ERROR')),
|
||||
message TEXT NOT NULL,
|
||||
script_name VARCHAR(100),
|
||||
series_name VARCHAR(255),
|
||||
session_id UUID,
|
||||
details JSONB
|
||||
);
|
||||
|
||||
-- Indexes for common query patterns
|
||||
CREATE INDEX IF NOT EXISTS idx_script_log_timestamp ON log.script_log(timestamp DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_script_log_session ON log.script_log(session_id) WHERE session_id IS NOT NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_script_log_series ON log.script_log(series_name) WHERE series_name IS NOT NULL;
|
||||
CREATE INDEX IF NOT EXISTS idx_script_log_level ON log.script_log(level);
|
||||
|
||||
-- View for recent logs (last 1000)
|
||||
CREATE OR REPLACE VIEW log.script_log_recent AS
|
||||
SELECT * FROM log.script_log
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 1000;
|
||||
|
||||
-- Table and column comments
|
||||
COMMENT ON TABLE log.script_log IS 'Persistent log for import scripts and library operations';
|
||||
COMMENT ON COLUMN log.script_log.level IS 'Log level: DEBUG, INFO, WARNING, ERROR';
|
||||
COMMENT ON COLUMN log.script_log.session_id IS 'Groups logs from a single script run (UUID)';
|
||||
COMMENT ON COLUMN log.script_log.script_name IS 'Name of the script or operation (e.g., import_ohlc.py)';
|
||||
COMMENT ON COLUMN log.script_log.series_name IS 'Optional: link to specific series';
|
||||
COMMENT ON COLUMN log.script_log.details IS 'Optional structured data stored as JSONB';
|
||||
Loading…
Add table
Add a link
Reference in a new issue