This project demonstrates how to set up automatic PostgreSQL database migrations using the Liquibase tool in a containerized environment with Docker Compose.
PostgreSQLcontainer for the database.Liquibasecontainer for performing migrations.changelog.ymlfile describing changes to the database.SQLfiles for migrations and rollbacks.
containerized-database-migrator-with-liquibase/
├── compose.yml # docker-compose file
└── liquibase/
└── changelog/
├── migrations/ # SQL files for migrations
│ └── ...
├── rollbacks/ # SQL files for migrations
│ └── ...
└── changelog.yml
git clone https://github.com/ваш-репозиторий.git
cd containerized-database-migrator-with-liquibasedocker-compose up -ddocker-compose logs liquibase- Create a new SQL migration file in the
liquibase/changelog/migrations/directory (for example,3-new-migration.sql) - Create a new SQL rollback file in the
liquibase/changelog/rollbacks/directory (for example,3-new-migration.sql) - Add a new
changeSetto thechangelog.ymlfile:
- changeSet:
id: 2-new-migration
author: your-email@example.com
changes:
- tagDatabase:
tag: "your tag"
- sqlFile:
path: changelog/migrations/2-new-migration.sql
rollback:
- sqlFile:
path: changelog/rollbacks/2-new-migration.sql- Restart the containers:
docker-compose down
docker-compose up -dTo increase the level of logging, add to compose.yml:
environment:
LIQUIBASE_LOG_LEVEL: FINEAnatoly Dudko