-
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.
add test fixture data for local testing
- Loading branch information
Showing
5 changed files
with
509 additions
and
0 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
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') |
Oops, something went wrong.