Skip to content

Commit

Permalink
feat: create custom entrypoint to perform rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 28, 2021
1 parent aee3b9c commit b67f3d6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ RUN set -ex && \
# Install source
COPY pact_broker $HOME/

RUN ln -s /pact_broker/script/db-migrate.sh /usr/local/bin/db-migrate
RUN ln -s /pact_broker/script/db-version.sh /usr/local/bin/db-version

# Start Puma
ENV RACK_ENV=production
ENV PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME=PACT_BROKER_PORT
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,29 @@ DATABASE_URL=...

The Pact Broker auto migrates on startup, and will always do so in a way that is backwards compatible, to support architectures that run multiple instances of the application at a time (eg. AWS auto scaling).

From the `/pact_broker` directory on the docker image, you can run migration and rollback scripts via rake. A rollback would be required if you needed to downgrade your Pact Broker image.
You can use a custom entrypoint to the Pact Broker Docker image to perform a rollback. A rollback would be required if you needed to downgrade your Pact Broker image. The db-migrate entrypoint is support in versions 2.76.1.1 and later.
To perform the rollback, you must use at minimum the version of the Docker image that performed the migrations in the first place. You can always use the latest image to rollback.

To work out which migration to rollback to, select the tag of the Pact Broker gem version you want at https://github.com/pact-foundation/pact_broker and then look in the `db/migrations` directory. Find the very last migration in the directory, and take the numbers at the start of the file name. This is your "target".

To rollback run:
```
# You can use the PACT_BROKER_DATABASE_URL or the separate environment variables as listed in the Getting Started section.
docker run --rm \
-e PACT_BROKER_DATABASE_URL=<url> \
-e PACT_BROKER_MIGRATION_TARGET=<target> \
--entrypoint db-migrate \
pactfoundation/pact-broker
```

`bundle exec rake pact_broker:db:migrate[target]` eg `bundle exec rake pact_broker:db:migrate[20191101]`
To get the current version of the database run:

You can confirm the new version by running `bundle exec rake pact_broker:db:version`
```
docker run --rm \
-e PACT_BROKER_DATABASE_URL=<url> \
--entrypoint db-version \
pactfoundation/pact-broker
```

# Troubleshooting

Expand Down
3 changes: 3 additions & 0 deletions pact_broker/script/db-migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

bundle exec rake pact_broker:db:migrate[$PACT_BROKER_MIGRATION_TARGET]
3 changes: 3 additions & 0 deletions pact_broker/script/db-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

bundle exec rake pact_broker:db:version

0 comments on commit b67f3d6

Please sign in to comment.