A tool for migrating the Postgres database of the old IMI-Map to a MongoDB for the imimap21
First you'll have to decide how you want to use the resulting MongoDB. There are three options:
- Mount a local directory as volume for the MongoDB to write the database files to
- Export the database from the service when the conversion is done
- Reuse the volume used in the migration for the actual IMI-Map
Edit the docker-compose.yml and change the mapping for the volume mongo-data
to your preferred directory.
After migrating the database you can use the directory as a mounted volume for the database container of the new IMI-Map.
- Run the migration (see next section)
- Connect to the Docker container using
docker exec -it <container-name> bash
- Run
mongodump --archive=db-dump.gz --gzip --db=imimap
inside the container to dump the database to/db-dump.gz
- Exit the Docker container using
exit
- Fetch the archive from the Docker container using
docker cp <container-name>:/db-dump.gz <local destination path>
If you want to reuse the volume created by the migration for the new MongoDB,
you can simply mount the volume mongo-data
in the new IMI-Map's docker-compose.yml.
- Put an SQL dump file of the old database into the
init/
directory and start the Docker-Compose-Project usingdocker-compose up -d
- Run the migration using
npm run migrate
- The Docker service
db-mongo
now contains the migrated database.
The project consists of 5 different parts:
- The old Postgres-Models (
src/pgModels
) - The new Mongoose-Models (
src/mongooseModels
), the new IMI-Map uses the same models - Loaders for loading the Postgres entities from the old database (
src/loaders
) - Converters for converting the Postgres entities to the new MongoDB entities (
src/converters
) - Some helper functions and utility classes (
src/helpers
)
The index.ts
executes the migration by loading the old models using the provided loaders and converting them
to the new models using the converters.