/flyway-with-spring-boot-maven

A Spring Boot project demonstrating how to configure and run database migrations using the Flyway Maven plugin

Primary LanguageJava

🚀 Flyway Spring Boot Maven: Multi-Environment Database Migration Management

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


✨ What This Project Demonstrates

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

🏗️ Project Structure

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

🚦 Environment Variables

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)

🛠️ Maven Commands

Development Environment

# Check migration status
mvn flyway:info -Pdev

# Apply all pending migrations
mvn flyway:migrate -Pdev

# Clean database (development only)
mvn flyway:clean -Pdev

Staging Environment

# Validate migration integrity
mvn flyway:validate -Pstage

# Apply migrations to staging
mvn flyway:migrate -Pstage

# Check staging status
mvn flyway:info -Pstage

Production Environment

# Validate before production deployment
mvn flyway:validate -Pprod

# Apply production migrations
mvn flyway:migrate -Pprod

# Verify production deployment
mvn flyway:info -Pprod

🗄️ Database Setup

Create the required PostgreSQL databases: flyway_demo_dev, flyway_demo_stage and flyway_demo_prod.


🏃‍♂️ Running the Application

# 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