The objective of this POC is to automate database schema changes using Flyway by codifying database changes and enabling repeatable, version-controlled migrations that can later be integrated into CI/CD pipelines.
This approach eliminates manual database change execution and aligns database management with DevOps and Infrastructure-as-Code practices.
| Component | Technology |
|---|---|
| Database | PostgreSQL 15 |
| Migration Tool | Flyway OSS |
| Container Runtime | Docker |
| Orchestration | Docker Compose |
| Versioning Approach | SQL-based Versioned Migrations |
Developer
↓
Creates SQL Migration
↓
Version Controlled in Git
↓
Flyway Executes Migration
↓
PostgreSQL Schema Updated
↓
Migration History Tracked
Created PostgreSQL container locally using Docker Compose.
services:
postgres:
image: postgres:15
container_name: flyway-postgres
environment:
POSTGRES_USER: flyway
POSTGRES_PASSWORD: flyway123
POSTGRES_DB: appdb
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:docker compose up -dVerified:
- PostgreSQL container running successfully
- DB connectivity working properly
Created migration directory:
mkdir sqlCreated first migration file:
V1__create_users_table.sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(100),
email VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Pulled Flyway Docker image:
docker pull flyway/flywayExecuted migration:
docker run --rm \
--network flyway-poc_default \
-v $(pwd)/sql:/flyway/sql \
flyway/flyway \
-url=jdbc:postgresql://postgres:5432/appdb \
-user=flyway \
-password=flyway123 \
migrateFlyway automatically:
- connected to PostgreSQL
- scanned migration directory
- detected pending migration
- created flyway_schema_history table
- executed migration
- tracked migration metadata
Verified newly created schema objects.
\dtObserved tables:
- users
- flyway_schema_history
\d usersSELECT installed_rank, version, description, script, success
FROM flyway_schema_history;
Re-executed Flyway migration command without adding new migrations.
Flyway correctly detected:
- schema already up to date
- no pending migrations
Output:
Schema "public" is up to date. No migration necessary.
This demonstrates:
- idempotent migration execution
- safe repeated execution
- CI/CD compatibility
Created second migration:
V2__add_phone_column.sql
ALTER TABLE users
ADD COLUMN phone VARCHAR(20);Executed Flyway migrate again.
Flyway:
- detected V1 already executed
- applied only V2 migration
- updated flyway_schema_history table
Verified:
- phone column added successfully
- migration history updated
Created intentionally broken migration:
V3__broken_migration.sql
ALTER TABL users
ADD COLUMN address VARCHAR(255);Flyway failed migration execution due to SQL syntax error.
Observed:
- migration execution failure
- schema rollback
- no partial schema modification
- no failed version entry persisted
PostgreSQL transactional DDL support enabled automatic rollback.
This demonstrated:
- safe migration failure handling
- transactional migration execution
- production-safe rollback behavior
Corrected migration script:
ALTER TABLE users
ADD COLUMN address VARCHAR(255);Re-executed Flyway migration.
Flyway:
- retried pending migration
- successfully applied V3
- updated migration history
Verified:
- address column created
- migration history updated successfully
Modified already executed migration:
V1__create_users_table.sql
Added additional comment to simulate unauthorized modification.
Re-executed Flyway migrate.
Flyway validation failed with checksum mismatch error.
Observed:
- migration immutability enforcement
- checksum validation protection
- tamper detection capability
Flyway prevents modification of already executed migrations, ensuring:
- schema consistency
- environment integrity
- reliable deployment history
| Concept | Status |
|---|---|
| Database-as-Code | Completed |
| Versioned Schema Migrations | Completed |
| Automated Migration Execution | Completed |
| Incremental Schema Evolution | Completed |
| Schema History Tracking | Completed |
| Idempotent Migration Execution | Completed |
| Transactional Rollback Handling | Completed |
| Migration Failure Recovery | Completed |
| Checksum Validation | Completed |
| Migration Immutability | Completed |
- Eliminates manual database change execution
- Enables version-controlled schema management
- Provides repeatable and automated deployments
- Prevents schema drift between environments
- Enables CI/CD integration readiness
- Provides migration audit history
- Detects unauthorized migration modifications
- Supports safe incremental schema evolution
Current POC execution is manual using Docker commands.
Next phase will focus on:
- CI/CD integration
- Jenkins pipeline automation
- Git-triggered migration execution
- Automated deployment workflows
Developer Pushes Migration
↓
Git Repository
↓
Jenkins Pipeline Trigger
↓
Flyway Validate
↓
Flyway Migrate
↓
Database Updated Automatically
This POC successfully demonstrated database migration automation using Flyway with PostgreSQL.
Database schema changes were codified, version-controlled, validated, and executed automatically while maintaining migration history and schema integrity.
The implementation aligns with DevOps principles and provides a strong foundation for future CI/CD-based database deployment automation.