Add db_push_uprova branch contents
This commit is contained in:
parent
33c2b95125
commit
4c3aa40a58
@ -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"]
|
||||
CMD ["python", "/app/block_wrapper.py"]
|
||||
|
||||
|
||||
43
README.md
43
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);
|
||||
```
|
||||
|
||||
18
config.json
18
config.json
@ -1,6 +1,14 @@
|
||||
[
|
||||
{
|
||||
"namespace": "",
|
||||
"connectionId": ""
|
||||
}
|
||||
]
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
41
main.sql
41
main.sql
@ -1 +1,40 @@
|
||||
Select * from dummy_table limit 10;
|
||||
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;
|
||||
|
||||
|
||||
@ -1 +1,45 @@
|
||||
{}
|
||||
{
|
||||
"$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"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1,14 @@
|
||||
{}
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
"error": {
|
||||
"type": ["string", "null"]
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user