Skip to content

Commit 587d5e1

Browse files
committed
Update importer script for new data model
- Save stop details in the stop_place - quay model - Use requirements.txt to define libraries - Update README - Update docker setup
1 parent 25810d2 commit 587d5e1

File tree

6 files changed

+290
-239
lines changed

6 files changed

+290
-239
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ digiroad_stops*.csv
4545

4646
#possible jore3 backup file
4747
jore3dump/*
48-
!jore3dump/put-bak-file-here.txt
48+
!jore3dump/put-bak-file-here.txt
49+
50+
#stop place import script environment file
51+
.env

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,58 @@ If a test case fails because the `com.microsoft.sqlserver.jdbc.SQLServerExceptio
531531
the error message says that it cannot find a database object, the problem is that the script which
532532
creates the source MSSQL database (_docker/mssql_init/populate.sql_) was changed. You can solve this problem by running the command:
533533
`./development.sh recreate` at command prompt.
534+
535+
---
536+
537+
## Jore3 stop import script
538+
539+
### Requirements
540+
541+
You need to have Python 3 installed on your system to run the script
542+
543+
#### Virtual environment
544+
545+
To run Python scripts with required libraries you should setup a virtual environment which contains the requirements for the script. To setup an environment, run:
546+
547+
`python3 -m venv LOCATION/OF/ENVIRONMENT/HERE`
548+
549+
Where you should replace the location with one you want to use. For example a directory under your home directory.
550+
To use the environment you can either source the virtual environment by running:
551+
552+
`source LOCATION/OF/ENVIRONMENT/HERE/bin/activate`
553+
554+
Which allows you to use the binaries directly as `python importer.py`
555+
556+
Or you can use the virtual environment python directly: `LOCATION/OF/ENVIRONMENT/HERE/bin/python importer.py`
557+
558+
#### Script setup
559+
560+
You need to run the `import.py` script using Python 3 and it requires the following libraries:
561+
562+
- pymssql
563+
- requests
564+
- simplejson
565+
566+
They can be installed by running `pip install -r requirements.txt`
567+
568+
### How to use
569+
570+
To run the stop registry importer script you need to have a Jore3 database, a populated Jore4 routes database, Jore4 Hasura and Jore4 Tiamat running.
571+
572+
By default the script runs from the local jore3 test database and uses the base local Jore4 Hasura instance as the target.
573+
You can change the source database and target Hasura instance by creating a `.env` file in the same directory as the script.
574+
575+
Set the values for variables you want to set:
576+
577+
```
578+
GRAPHQL_URL=
579+
GRAPHQL_SECRET=
580+
JORE3_USERNAME=
581+
JORE3_PASSWORD=
582+
JORE3_DATABASE_URL=
583+
JORE3_DATABASE_NAME=
584+
```
585+
586+
You should have run the base Jore3 importer first which ensures the Jore4 database has the required scheduled stop points. Then run the stop registry import script which will match scheduled stop points in the Jore4 routes database with stops in the Jore3 database and generate GraphQL mutations to Hasura/Tiamat according to the data. The script will also link the generated stop registry stops with the scheduled stop points by their NeTEx ID using Hasura for the mutation.
587+
588+
Running the script will produce multiple errors as there are many stops in the Jore3 database with overlapping validity. These can be ingored as only the most recent one is the one which ends up being imported.

development.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ download_docker_compose_bundle() {
135135
}
136136

137137
start_all() {
138-
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-jore3importer jore4-mapmatchingdb jore4-mapmatching
138+
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-jore3importer jore4-mapmatchingdb jore4-mapmatching jore4-tiamat
139139
}
140140

141141
start_deps() {
@@ -145,7 +145,7 @@ start_deps() {
145145
# jore4-mssqltestdb - The Jore 3 MSSQL database which contains the source data which is read by the importer
146146
# jore4-hasura - Hasura. We have to start Hasura because it ensures that db migrations are run to the Jore 4 database.
147147
# jore4-testdb - Jore 4 database. This is the destination database of the import process.
148-
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-mapmatchingdb jore4-mapmatching
148+
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-mapmatchingdb jore4-mapmatching jore4-tiamat
149149
}
150150

151151
stop() {

docker/docker-compose.custom.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ services:
3838
volumes:
3939
- ../jore3dump:/mnt/jore3dump
4040

41+
jore4-tiamat:
42+
# Pin tiamat to a compatible version.
43+
image: "hsldevcom/jore4-tiamat:main--20250317-1136ff34a5b6030b0e9c85b0373f5ddc02946267"
44+
4145
jore4-hasura:
4246
# pin compatible version of jore4 data model
43-
image: "hsldevcom/jore4-hasura:hsl-main--20231218-8a28ef5f4b22b6351312788be4e674144f2bb0a2"
47+
image: "hsldevcom/jore4-hasura:hsl-main--20250317-60eaf1217447890591ca3bbe262c96f2cc68ba57"
48+
depends_on:
49+
jore4-testdb:
50+
condition: service_healthy
51+
jore4-tiamat:
52+
condition: service_healthy
4453
networks:
45-
jore4:
54+
jore4:

0 commit comments

Comments
 (0)