Skip to content

Commit

Permalink
Merge pull request #154 from Whats-Cookin/live-fixes
Browse files Browse the repository at this point in the history
Live fixes
  • Loading branch information
gvelez17 authored Nov 25, 2024
2 parents 0f1b05f + 37340ae commit 35b8010
Show file tree
Hide file tree
Showing 8 changed files with 3,628 additions and 3,785 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"key-did-resolver": "^2.0.4",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"s3": "^4.4.0",
"sharp": "^0.33.5",
"uint8arrays": "^3.0.0",
"ulid": "^2.3.0",
"yaml": "^2.6.1",
"zod": "^3.21.4"
},
"engines": {
Expand Down
19 changes: 19 additions & 0 deletions scripts/README_FIXTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## How to create the fixture data


On a server with data:
```
psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d claim -A -f make_fixture.sql > fixture_data.txt
python convert_to_inserts.py # creates fixture_data.sql
```

## Load the fixture data into local db

On your local development machine:

```
psql claim -f insert_fixture.sql
```
46 changes: 46 additions & 0 deletions scripts/convert_to_inserts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
def create_insert_statements(input_file, output_file):
current_table = None
header = None
data = []

with open(input_file, 'r') as f:
lines = f.readlines()

with open(output_file, 'w') as f:
f.write('BEGIN;\n')

for line in lines:
line = line.strip()
if not line:
continue

if line == 'NODES:|':
current_table = 'Node'
header = None
continue
elif line == 'EDGES:|':
current_table = 'Edge'
header = None
continue
elif line == 'CLAIMS:|':
current_table = 'Claim'
header = None
continue

if header is None:
header = line.split('|')
continue

values = line.split('|')
columns = ','.join(f'"{h}"' for h in header)
value_list = ','.join(
'NULL' if v == '\\N' or v == ''
else f"'{v}'" if not v.replace('.','').replace('-','').replace('+','').isdigit()
else v
for v in values
)
f.write(f'INSERT INTO "{current_table}" ({columns}) VALUES ({value_list});\n')

f.write('COMMIT;\n')

create_insert_statements('fixture_data.txt', 'insert_fixture.sql')
175 changes: 175 additions & 0 deletions scripts/fixture_data.txt

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions scripts/insert_fixture.sql

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions scripts/make_fixture.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- Nodes
WITH claim_edge AS (
SELECT * FROM "Edge" WHERE "claimId" IN (118499, 118500, 118501, 33594)
),
first_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN "Edge" e ON n."id" IN (e."startNodeId", e."endNodeId")
WHERE e."claimId" IN (118499, 118500, 118501, 33594)
),
first_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM first_nodes)
OR e."endNodeId" IN (SELECT "id" FROM first_nodes)
),
second_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN first_edges e ON n."id" IN (e."startNodeId", e."endNodeId")
),
second_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM second_nodes)
OR e."endNodeId" IN (SELECT "id" FROM second_nodes)
LIMIT 50
),
all_nodes AS (
SELECT * FROM first_nodes
UNION
SELECT * FROM second_nodes
)
SELECT * FROM all_nodes;

-- Edges
WITH claim_edge AS (
SELECT * FROM "Edge" WHERE "claimId" IN (118499, 118500, 118501, 33594)
),
first_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN "Edge" e ON n."id" IN (e."startNodeId", e."endNodeId")
WHERE e."claimId" IN (118499, 118500, 118501, 33594)
),
first_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM first_nodes)
OR e."endNodeId" IN (SELECT "id" FROM first_nodes)
),
second_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN first_edges e ON n."id" IN (e."startNodeId", e."endNodeId")
),
second_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM second_nodes)
OR e."endNodeId" IN (SELECT "id" FROM second_nodes)
LIMIT 50
),
all_edges AS (
SELECT * FROM first_edges
UNION
SELECT * FROM second_edges
)
SELECT * FROM all_edges;

-- Claims
WITH claim_edge AS (
SELECT * FROM "Edge" WHERE "claimId" IN (118499, 118500, 118501, 33594)
),
first_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN "Edge" e ON n."id" IN (e."startNodeId", e."endNodeId")
WHERE e."claimId" IN (118499, 118500, 118501, 33594)
),
first_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM first_nodes)
OR e."endNodeId" IN (SELECT "id" FROM first_nodes)
),
second_nodes AS (
SELECT DISTINCT n.*
FROM "Node" n
JOIN first_edges e ON n."id" IN (e."startNodeId", e."endNodeId")
),
second_edges AS (
SELECT e.*
FROM "Edge" e
WHERE e."startNodeId" IN (SELECT "id" FROM second_nodes)
OR e."endNodeId" IN (SELECT "id" FROM second_nodes)
LIMIT 50
),
all_edges AS (
SELECT * FROM first_edges
UNION
SELECT * FROM second_edges
)
SELECT DISTINCT c.*
FROM "Claim" c
WHERE c."id" IN (SELECT "claimId" FROM all_edges);
4 changes: 2 additions & 2 deletions src/dao/api.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class NodeDao {
AND c.statement IS NOT NULL
AND n1.name IS NOT NULL
AND n1.name != ''
ORDER BY c.id, c."effectiveDate" DESC
ORDER BY c.id DESC, c."effectiveDate" DESC
LIMIT ${limit}
OFFSET ${offset}
`;
Expand Down Expand Up @@ -392,7 +392,7 @@ export class NodeDao {
n3.name ILIKE '%${search}%' OR
n3."descrip" ILIKE '%${search}%'
)
ORDER BY c.id, c."effectiveDate" DESC
ORDER BY c.id DESC, c."effectiveDate" DESC
LIMIT ${limit}
OFFSET ${offset}
`;
Expand Down
Loading

0 comments on commit 35b8010

Please sign in to comment.