Master enterprise-grade database migrations with Flyway, Spring Boot, and Maven commands. This repository demonstrates how to build a complete multi-environment migration system that manages database schema changes across development, staging, and production environments with precision and control.
📖 Complete Guide: For detailed explanations, Maven command mastery, and production-ready migration strategies, read our comprehensive tutorial.
👉 Flyway Spring Boot Maven: Complete Guide for Multi-Environment Database Migration Management
This application showcases a complete database migration management system with:
- Maven-driven migration control using flyway:migrate, flyway:info, flyway:validate commands
- Multi-environment configuration with separate dev, staging, and production setups
- Environment-specific migrations with shared common scripts and targeted deployments
- Spring Boot REST API demonstrating the migrated database in action
flyway-maven-demo/
├── src/main/resources/db/migration/
│ ├── common/ # Shared migrations across all environments
│ ├── dev/ # Development-specific migrations
│ ├── stage/ # Staging-specific migrations
│ └── prod/ # Production-specific migrations
├── config/
│ ├── flyway-dev.conf # Development environment configuration
│ ├── flyway-stage.conf # Staging environment configuration
│ └── flyway-prod.conf # Production environment configuration
└── pom.xml # Maven configuration with Flyway plugin
Configure your database connections using these environment variables:
DB_HOST: Database server hostname (default: localhost)DB_PORT: Database server port (default: 5432)DB_NAME: Database name (default: flyway_demo_dev)DB_USER: Database username (default: postgres)DB_PASSWORD: Database password (required for staging/production)
# Check migration status
mvn flyway:info -Pdev
# Apply all pending migrations
mvn flyway:migrate -Pdev
# Clean database (development only)
mvn flyway:clean -Pdev# Validate migration integrity
mvn flyway:validate -Pstage
# Apply migrations to staging
mvn flyway:migrate -Pstage
# Check staging status
mvn flyway:info -Pstage# Validate before production deployment
mvn flyway:validate -Pprod
# Apply production migrations
mvn flyway:migrate -Pprod
# Verify production deployment
mvn flyway:info -PprodCreate the required PostgreSQL databases: flyway_demo_dev, flyway_demo_stage and flyway_demo_prod.
# Start Spring Boot application in development mode
mvn spring-boot:run -Dspring.profiles.active=dev
# Test the REST API
curl http://localhost:8080/api/users