From 4c3aa40a58cbf5e516da345ea0f5d7fc61842e6e Mon Sep 17 00:00:00 2001 From: Ankur Malik Date: Wed, 26 Nov 2025 12:04:04 -0500 Subject: [PATCH] Add db_push_uprova branch contents --- Dockerfile | 5 +++-- README.md | 43 ++++++++++++++++++++++++++++++++++++++++- config.json | 18 ++++++++++++----- main.sql | 41 ++++++++++++++++++++++++++++++++++++++- request_schema.json | 46 +++++++++++++++++++++++++++++++++++++++++++- response_schema.json | 15 ++++++++++++++- 6 files changed, 157 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8d4c3a3..bb6ff2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ WORKDIR /app # Copy user-specific files (block.py, schemas, requirements) COPY . . -RUN ls ./ +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..0ab9698 100644 --- a/README.md +++ b/README.md @@ -1 +1,42 @@ -**Hello world!!!** +# db_push_uprova + +Block for upserting uprova application data into the `public.uprova` table in the `staging` database. + +The table stores uprova-specific attributes keyed by `application_key`. The block uses a parameterised +`INSERT ... ON CONFLICT ... DO UPDATE` statement defined in `main.sql` to upsert records. + +## Table DDL + +The `public.uprova` table can be created with the following SQL, following the style of +`k8s/mlgraph-db/init-configmap.yaml`: + +```sql +-- Connect to postgres database as superuser +\c postgres; + +-- Create databases +CREATE DATABASE staging; + +-- Grant privileges +GRANT ALL PRIVILEGES ON DATABASE staging TO cpflowxuser; + +-- Connect to staging database and create uprova table +\connect staging; + +CREATE TABLE IF NOT EXISTS uprova ( + application_key TEXT PRIMARY KEY, + application_timestamp TIMESTAMP NOT NULL, + educationlevel TEXT NULL, + employmentstatus TEXT NULL, + lengthatbank TEXT NULL, + lengthatjob NUMERIC NULL, + ownhome BOOLEAN NULL, + payfrequency TEXT NULL, + monthsatresidence NUMERIC NULL, + state TEXT NULL, + zip TEXT NULL +); + +CREATE INDEX IF NOT EXISTS idx_uprova_application_key ON uprova (application_key); +CREATE INDEX IF NOT EXISTS idx_uprova_application_timestamp ON uprova (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..ab61f89 100644 --- a/main.sql +++ b/main.sql @@ -1 +1,40 @@ -Select * from dummy_table limit 10; \ No newline at end of file +INSERT INTO public.uprova ( + application_key, + application_timestamp, + educationlevel, + employmentstatus, + lengthatbank, + lengthatjob, + ownhome, + payfrequency, + monthsatresidence, + state, + zip +) +VALUES ( + $application_key, + $application_timestamp, + $educationlevel, + $employmentstatus, + $lengthatbank, + $lengthatjob, + $ownhome, + $payfrequency, + $monthsatresidence, + $state, + $zip +) +ON CONFLICT (application_key) +DO UPDATE +SET + application_timestamp = EXCLUDED.application_timestamp, + educationlevel = EXCLUDED.educationlevel, + employmentstatus = EXCLUDED.employmentstatus, + lengthatbank = EXCLUDED.lengthatbank, + lengthatjob = EXCLUDED.lengthatjob, + ownhome = EXCLUDED.ownhome, + payfrequency = EXCLUDED.payfrequency, + monthsatresidence = EXCLUDED.monthsatresidence, + state = EXCLUDED.state, + zip = EXCLUDED.zip; + diff --git a/request_schema.json b/request_schema.json index 9e26dfe..8412425 100644 --- a/request_schema.json +++ b/request_schema.json @@ -1 +1,45 @@ -{} \ 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" + }, + "educationlevel": { + "type": ["string", "null"] + }, + "employmentstatus": { + "type": ["string", "null"] + }, + "lengthatbank": { + "type": ["string", "null"] + }, + "lengthatjob": { + "type": ["number", "null"] + }, + "ownhome": { + "type": ["boolean", "null"] + }, + "payfrequency": { + "type": ["string", "null"] + }, + "monthsatresidence": { + "type": ["number", "null"] + }, + "state": { + "type": ["string", "null"] + }, + "zip": { + "type": ["string", "null"] + } + }, + "required": [ + "application_key", + "application_timestamp" + ] +} + diff --git a/response_schema.json b/response_schema.json index 9e26dfe..65c8193 100644 --- a/response_schema.json +++ b/response_schema.json @@ -1 +1,14 @@ -{} \ 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": [] +} +