This code accompanies the Automating data migration testing blog post on https://blog.pragmatists.com.
It provides a simple framework for testing data migrations, with both the source and target databases running. Here, we're using PostgreSQL as source, running in Docker, and MongoDB as target, running in memory. The code is written in JavaScript, and Jest is used to run tests.
- Make sure you have Docker Engine, Docker Compose, and Node.js.
- After pulling the code, run
npm install
to install dependencies. - Run
npm test
to launch the test suite. - Run
npm start
to launch the actual migration.
Assuming you're familiar with JavaScript projects in general, the important bits here are:
docker-compose.yml
contains the PostgreSQL container configurationsrc/index.js
runs the full migration, as you would in productionsrc/migrate-users.js
is the code encapsulating migratinguser
entities, andsrc/migrate-users.spec.js
is the test suite for that codesrc/test-init.js
is test initialization code, including starting and stopping databases, sharedby all test suitessrc/mongo-client-builder.js
andsrc/postgres-client-builder.js
are functions building client instances for MongoDB and PostgreSQL accordingly