Spring Boot handles database migrations through version-controlled migration tools like Flyway or Liquibase, which apply incremental schema changes automatically as the application starts.
Key Points: • Flyway migrations are plain SQL scripts named with a version prefix (e.g. V1__create_users_table.sql) placed in src/main/resources/db/migration. • Liquibase uses XML, YAML, JSON, or SQL changelogs and offers rollback support built into its changelog format. • Both tools track applied migrations in a metadata table, so each script runs exactly once, in order, even across multiple environments. • Adding the Flyway or Liquibase starter dependency is enough to trigger migrations automatically on application startup. • This approach keeps schema changes reviewable in version control and consistent across dev, test, and production databases.
Example: Adding a new column requires creating V5__add_phone_to_users.sql with an ALTER TABLE statement; on the next deployment, Flyway detects it hasn't run yet and applies it automatically before the application context finishes starting.
Code Example:
-- V5__add_phone_to_users.sql
ALTER TABLE users ADD COLUMN phone VARCHAR(20);Interview Tip: A concise interview answer is:
"I use Flyway or Liquibase to manage schema changes as version-controlled scripts. Each one runs automatically and exactly once at startup, tracked in a metadata table, which keeps the schema consistent and reproducible across every environment without any manual DBA intervention for routine changes."