-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from Whats-Cookin/live-fixes
Live fixes
- Loading branch information
Showing
8 changed files
with
3,628 additions
and
3,785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.