Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Containerized DB Migrator with Liquibase

This project demonstrates how to set up automatic PostgreSQL database migrations using the Liquibase tool in a containerized environment with Docker Compose.

Description

  • PostgreSQL container for the database.
  • Liquibase container for performing migrations.
  • changelog.yml file describing changes to the database.
  • SQL files for migrations and rollbacks.

Structure of the project

containerized-database-migrator-with-liquibase/
├── compose.yml             # docker-compose file
└── liquibase/
    └── changelog/
        ├── migrations/     # SQL files for migrations
        │   └── ...
        ├── rollbacks/      # SQL files for migrations
        │   └── ...
        └── changelog.yml

Run containers

1. Clone the repository:

git clone https://github.com/ваш-репозиторий.git
cd containerized-database-migrator-with-liquibase

2. Start the containers using Docker Compose:

docker-compose up -d

3. Check the Liquibase logs to ensure that the migrations are successful:

docker-compose logs liquibase

How to add new migrations

  • 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 changeSet to the changelog.yml file:
- 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 -d

Logging

To increase the level of logging, add to compose.yml:

environment:
  LIQUIBASE_LOG_LEVEL: FINE

Author:

Anatoly Dudko

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors