Skip to content

Commit b67f3d6

Browse files
committed
feat: create custom entrypoint to perform rollback
1 parent aee3b9c commit b67f3d6

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ RUN set -ex && \
3838
# Install source
3939
COPY pact_broker $HOME/
4040

41+
RUN ln -s /pact_broker/script/db-migrate.sh /usr/local/bin/db-migrate
42+
RUN ln -s /pact_broker/script/db-version.sh /usr/local/bin/db-version
43+
4144
# Start Puma
4245
ENV RACK_ENV=production
4346
ENV PACT_BROKER_PORT_ENVIRONMENT_VARIABLE_NAME=PACT_BROKER_PORT

README.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,29 @@ DATABASE_URL=...
185185

186186
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).
187187

188-
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.
188+
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.
189+
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.
189190

190191
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".
191192

192-
To rollback run:
193+
```
194+
# You can use the PACT_BROKER_DATABASE_URL or the separate environment variables as listed in the Getting Started section.
195+
196+
docker run --rm \
197+
-e PACT_BROKER_DATABASE_URL=<url> \
198+
-e PACT_BROKER_MIGRATION_TARGET=<target> \
199+
--entrypoint db-migrate \
200+
pactfoundation/pact-broker
201+
```
193202

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

196-
You can confirm the new version by running `bundle exec rake pact_broker:db:version`
205+
```
206+
docker run --rm \
207+
-e PACT_BROKER_DATABASE_URL=<url> \
208+
--entrypoint db-version \
209+
pactfoundation/pact-broker
210+
```
197211

198212
# Troubleshooting
199213

pact_broker/script/db-migrate.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
bundle exec rake pact_broker:db:migrate[$PACT_BROKER_MIGRATION_TARGET]

pact_broker/script/db-version.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
bundle exec rake pact_broker:db:version

0 commit comments

Comments
 (0)