From f664314b298eabfcb1ef41c5875f9f265e0bb038 Mon Sep 17 00:00:00 2001 From: Ankur Malik Date: Wed, 26 Nov 2025 12:08:33 -0500 Subject: [PATCH] Add db_push_scores branch contents --- Dockerfile | 3 ++- README.md | 22 +++++++++++++++++++++- config.json | 18 +++++++++++++----- main.sql | 22 +++++++++++++++++++++- request_schema.json | 28 +++++++++++++++++++++++++++- response_schema.json | 21 ++++++++++++++++++++- 6 files changed, 104 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8d4c3a3..352a9ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,5 @@ COPY . . RUN ls ./ # Set CMD to execute the symbolic link, making it look like block.py is the entry -CMD ["python", "/app/block_wrapper.py"] \ No newline at end of file +CMD ["python", "/app/block_wrapper.py"] + diff --git a/README.md b/README.md index 59a3efc..fdcb5e2 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ -**Hello world!!!** +# Block for inserting/upserting scores into the scores table + +This block is responsible for inserting or updating score records in the `scores` table using the same database configuration as `db_push_v1`. + +## Table DDL + +The following DDL illustrates the `scores` table structure (Postgres style, conceptually compatible with DuckDB for tests): + +```sql +-- creating scores table +CREATE TABLE IF NOT EXISTS scores ( + application_key TEXT PRIMARY KEY, + application_timestamp TIMESTAMP NOT NULL, + hd_score_m1 DOUBLE PRECISION NULL, + hd_score_m2 DOUBLE PRECISION NULL, + hd_score_iso_m2 DOUBLE PRECISION NULL +); + +CREATE INDEX IF NOT EXISTS idx_scores_application_key ON scores(application_key); +CREATE INDEX IF NOT EXISTS idx_scores_application_timestamp ON scores(application_timestamp); +``` diff --git a/config.json b/config.json index 41f8111..d59008d 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,14 @@ [ - { - "namespace": "", - "connectionId": "" - } - ] \ No newline at end of file + { + "namespace": "staging", + "connectionId": "56be80f8-7139-466f-b883-e4a695812d52" + }, + { + "namespace": "production", + "connectionId": "cf2344a8-28d3-4b38-9456-ba9e5c347bf5" + }, + { + "namespace": "production-beta", + "connectionId": "cf2344a8-28d3-4b38-9456-ba9e5c347bf5" + } +] \ No newline at end of file diff --git a/main.sql b/main.sql index f0129ba..55949b1 100644 --- a/main.sql +++ b/main.sql @@ -1 +1,21 @@ -Select * from dummy_table limit 10; \ No newline at end of file +INSERT INTO public.scores ( + application_key, + application_timestamp, + hd_score_m1, + hd_score_m2, + hd_score_iso_m2 +) +VALUES ( + $application_key, + $application_timestamp, + $hd_score_m1, + $hd_score_m2, + $hd_score_iso_m2 +) +ON CONFLICT (application_key) +DO UPDATE + SET application_timestamp = EXCLUDED.application_timestamp, + hd_score_m1 = EXCLUDED.hd_score_m1, + hd_score_m2 = EXCLUDED.hd_score_m2, + hd_score_iso_m2 = EXCLUDED.hd_score_iso_m2; + diff --git a/request_schema.json b/request_schema.json index 9e26dfe..dc986d7 100644 --- a/request_schema.json +++ b/request_schema.json @@ -1 +1,27 @@ -{} \ No newline at end of file +{ + "$schema": "http://json-schema.org/draft-07/schema", + "type": "object", + "properties": { + "application_key": { + "type": "string" + }, + "application_timestamp": { + "type": "string", + "format": "date-time" + }, + "hd_score_m1": { + "type": ["number", "null"] + }, + "hd_score_m2": { + "type": ["number", "null"] + }, + "hd_score_iso_m2": { + "type": ["number", "null"] + } + }, + "required": [ + "application_key", + "application_timestamp" + ] +} + diff --git a/response_schema.json b/response_schema.json index 9e26dfe..cdcf869 100644 --- a/response_schema.json +++ b/response_schema.json @@ -1 +1,20 @@ -{} \ No newline at end of file +{ + "$schema": "http://json-schema.org/draft-07/schema", + "type": "object", + "properties": { + "result": { + "type": [ + "string", + "null" + ] + }, + "error": { + "type": [ + "string", + "null" + ] + } + }, + "required": [] +} +