Database Deployment Instructions
We have seperate Docker containers that run DB migrations for services. The name format is <service_name>-db. You can see examples of how they are configured in the sample docker-compose.yml.
Setup
Database needs to be configured for the migration to run on. Each DB migration container contains environment varaibles that specifies how to connect to the database - see the sample docker-compose.yml for details on how to configure migration containers.
Upgrade
The only thing necessary to upgrade a database is to retrieve new version of a Docker migration container and run it.
Rollback
Node Services
We use db-migrate for Node services to run migrations. Each Node service contains db-migrate:down
that can be run to rollback migrations. Create a Docker container (see the example below) and run it to perform a rollback. Make sure to configure environment variables required by the service.
FROM node:12
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY .npmrc ./
RUN npm install
COPY src/db/. ./src/db/
CMD [ "npm", "run", "db-migrate:down -- -c <num_of_migrations_to_rollback>" ]
Java Services
We use Flyway for Java services to run migrations. You can create a Docker container to run a rollback (see the example below). The example rolls back the latest migration, so the container would need to be run multiple times to roll back more migrations.
FROM flyway/flyway:latest-alpine
COPY src/main/resources/db/migration/ /flyway/sql/
CMD ["undo"]