Skip to content

Commit

Permalink
add test fixture data for local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelez17 committed Nov 25, 2024
1 parent e2d0be1 commit d1c6c04
Show file tree
Hide file tree
Showing 5 changed files with 509 additions and 0 deletions.
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')
Loading

0 comments on commit d1c6c04

Please sign in to comment.