What is Spring Boot Flyway/Liquibase database migration?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
Database migration tools manage schema changes version-controlled, similar to VCS for database structure. Never use spring.jpa.hibernate.ddl-auto=update in production — use Flyway or Liquibase instead. Flyway (simpler — SQL migrations): add spring-boot-starter-flyway or flyway-core. Place migration files in src/main/resources/db/migration/. File naming: V{version}__{description}.sql: V1__Create_users_table.sql V2__Add_email_index.sql V3__Add_user_roles.sql. Spring Boot auto-runs Flyway on startup. Flyway tracks applied migrations in flyway_schema_history table. flyway.baseline-on-migrate=true for existing databases. Commands: mvn flyway:migrate, flyway:validate, flyway:repair. Configuration: spring.flyway.locations=classpath:db/migration spring.flyway.baseline-on-migrate=true spring.flyway.out-of-order=false. Liquibase (more flexible — XML/YAML/JSON/SQL changesets): add liquibase-core. Place db/changelog/db.changelog-master.yaml: databaseChangeLog: - include: file: db/changelog/001-create-users.yaml - include: file: db/changelog/002-add-email-index.yaml. Each changeset has an ID and author. Liquibase tracks in databasechangelog table. Best practices: never modify applied migrations; create new migration for every change; run in CI/CD; test migrations against production-like data; rollback scripts for Flyway Pro/Liquibase.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Spring Boot project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is Spring WebFlux and reactive programming?
Next
What is Spring Boot @Async and thread management?
More Spring Boot Questions
View all →- Intermediate What is Spring AOP (Aspect-Oriented Programming)?
- Intermediate What is Spring Boot caching with @Cacheable?
- Intermediate What is Spring Data JPA query methods and JPQL?
- Intermediate What is Spring Boot REST API best practices?
- Intermediate What is Spring Boot JWT authentication implementation?