See also: https://flywaydb.org/documentation/configuration/configfile
Prepare basic Flyway configuration (no sensitive data inside), say at config/flyway.conf
:
# vim: set syntax=jproperties:
# See https://flywaydb.org/documentation/configuration/configfile
flyway.schemas = foo
flyway.defaultSchema = foo
flyway.url = jdbc:postgresql://postgres-1:5432/helloworld?
flyway.table = _schema_version
flyway.baselineVersion = 0
flyway.baselineOnMigrate = true
Prepare another configuration file with sensitive data (connection credentials), say at config/secret.conf
:
flyway.user = tester
flyway.password = tester
Prepare your migration scripts under sql/
(so this directory will contain all V<version>__<description>.sql
files).
Prepare a docker-compose
recipe for running migration-related operations:
# vim: syntax=yaml:
version: '3.6'
services:
# This is not a service, but an one-off command. Run like:
# docker-compose run --rm flyway migrate
'flyway':
image: 'flyway/flyway:7.7'
#command: ['info']
volumes:
- type: 'bind'
source: ./config/flyway.conf
target: /flyway/conf/flyway.conf
read_only: true
- type: 'bind'
source: ./config/secret.conf
target: /flyway/conf/secret.conf
read_only: true
- type: 'bind'
source: ./sql
target: /flyway/sql
read_only: true
environment:
FLYWAY_CONFIG_FILES: /flyway/conf/flyway.conf,/flyway/conf/secret.conf
# note: this is just a quick'n'dirty way to access the database!
network_mode: "bridge"
extra_hosts:
- 'postgres-1:172.17.0.2'
Print info:
docker-compose run --rm flyway info
Migrate schema:
docker-compose run --rm flyway migrate