diff --git a/Dockerfile b/Dockerfile index 8d4c3a3..2efdaae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,11 @@ FROM ${CONTAINER_REGISTRY}/db-activity-wrapper:latest # Set up working directory WORKDIR /app -# Copy user-specific files (block.py, schemas, requirements) +# Copy user-specific files (schemas, SQL, config) 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..792658c 100644 --- a/README.md +++ b/README.md @@ -1 +1,29 @@ -**Hello world!!!** +# Block for inserting/upserting THX attributes into the thx table + +This block is responsible for inserting or updating THX-related records in the `thx` table using the same database configuration as `db_push_v1`. + +## Table DDL + +The following DDL illustrates the `thx` table structure (Postgres style, conceptually compatible with DuckDB for tests): + +```sql +-- creating thx table +CREATE TABLE IF NOT EXISTS thx ( + application_key TEXT PRIMARY KEY, + application_timestamp TIMESTAMP NULL, + digital_id_first_seen TEXT NULL, + summary_risk_score TEXT NULL, + cpu_clock TEXT NULL, + true_ip_first_seen TEXT NULL, + ssn_hash_first_seen TEXT NULL, + account_email_attributes TEXT NULL, + tps_ip_latitude TEXT NULL, + tps_ip_longitude TEXT NULL, + account_telephone_first_seen TEXT NULL, + account_login_first_seen TEXT NULL +); + +CREATE INDEX IF NOT EXISTS idx_thx_application_key ON thx(application_key); +CREATE INDEX IF NOT EXISTS idx_thx_application_timestamp ON thx(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..d3a5965 100644 --- a/main.sql +++ b/main.sql @@ -1 +1,42 @@ -Select * from dummy_table limit 10; \ No newline at end of file +INSERT INTO public.thx ( + application_key, + application_timestamp, + digital_id_first_seen, + summary_risk_score, + cpu_clock, + true_ip_first_seen, + ssn_hash_first_seen, + account_email_attributes, + tps_ip_latitude, + tps_ip_longitude, + account_telephone_first_seen, + account_login_first_seen +) +VALUES ( + $application_key, + $application_timestamp, + $digital_id_first_seen, + $summary_risk_score, + $cpu_clock, + $true_ip_first_seen, + $ssn_hash_first_seen, + $account_email_attributes, + $tps_ip_latitude, + $tps_ip_longitude, + $account_telephone_first_seen, + $account_login_first_seen +) +ON CONFLICT (application_key) +DO UPDATE + SET application_timestamp = EXCLUDED.application_timestamp, + digital_id_first_seen = EXCLUDED.digital_id_first_seen, + summary_risk_score = EXCLUDED.summary_risk_score, + cpu_clock = EXCLUDED.cpu_clock, + true_ip_first_seen = EXCLUDED.true_ip_first_seen, + ssn_hash_first_seen = EXCLUDED.ssn_hash_first_seen, + account_email_attributes = EXCLUDED.account_email_attributes, + tps_ip_latitude = EXCLUDED.tps_ip_latitude, + tps_ip_longitude = EXCLUDED.tps_ip_longitude, + account_telephone_first_seen = EXCLUDED.account_telephone_first_seen, + account_login_first_seen = EXCLUDED.account_login_first_seen; + diff --git a/request_schema.json b/request_schema.json index 9e26dfe..bd368e2 100644 --- a/request_schema.json +++ b/request_schema.json @@ -1 +1,48 @@ -{} \ 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" + }, + "digital_id_first_seen": { + "type": ["string", "null"] + }, + "summary_risk_score": { + "type": ["string", "null"] + }, + "cpu_clock": { + "type": ["string", "null"] + }, + "true_ip_first_seen": { + "type": ["string", "null"] + }, + "ssn_hash_first_seen": { + "type": ["string", "null"] + }, + "account_email_attributes": { + "type": ["string", "null"] + }, + "tps_ip_latitude": { + "type": ["string", "null"] + }, + "tps_ip_longitude": { + "type": ["string", "null"] + }, + "account_telephone_first_seen": { + "type": ["string", "null"] + }, + "account_login_first_seen": { + "type": ["string", "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": [] +} +