Master seamless database migrations with Flyway and Spring Boot native integration. This repository demonstrates how to build a complete multi-environment migration system that manages database schema changes across development, staging, and production environments using Spring Boot's built-in Flyway auto-configuration.
📖 Complete Guide: For detailed explanations, Spring Boot configuration mastery, and production-ready migration strategies, read our comprehensive tutorial.
👉 Flyway Migration Using Spring Boot: Complete Tutorial Guide
This application showcases a complete Spring Boot Flyway integration system with:
- Spring Boot native Flyway integration with automatic migration execution on startup
- Multi-environment profiles with separate dev, staging, and production configurations
- Environment-specific migrations using Spring profiles and classpath locations
- Spring Boot REST API demonstrating the migrated database with real data
- Actuator endpoints for migration monitoring and health checks
- Production-ready configurations with security and monitoring best practices
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)
# Run with development profile (default)
./mvnw spring-boot:run
# Or explicitly specify dev profile
./mvnw spring-boot:run -Dspring.profiles.active=dev
# Check migration status via Actuator
curl http://localhost:8080/actuator/flyway# Run with staging profile
./mvnw spring-boot:run -Dspring.profiles.active=stage
# Verify staging-specific data
curl http://localhost:8080/api/users# Run with production profile
./mvnw spring-boot:run -Dspring.profiles.active=prod
# Check health including Flyway status
curl http://localhost:8080/actuator/healthCreate the required PostgreSQL databases: flyway_demo_dev, flyway_demo_stage and flyway_demo_prod.
./mvnw spring-boot:run -Dspring.profiles.active=dev# Get all users (shows environment-specific data)
curl http://localhost:8080/api/users
# Get user by ID
curl http://localhost:8080/api/users/1
# Health check
curl http://localhost:8080/api/users/health# Check Flyway migration details
curl http://localhost:8080/actuator/flyway | jq '.'
# Check overall application health
curl http://localhost:8080/actuator/health | jq '.components.flyway'- Clone the repository
- Setup PostgreSQL databases (dev, stage, prod)
- Configure environment variables for database connections
- Run the application with desired profile
- Test the REST API to verify migration success
- Monitor via Actuator endpoints for ongoing health checks
For comprehensive tutorials on database migration strategies:
Built with ❤️ by BootcampToProd