Java.DBMigrationTools.What file should you ignore in version control (e.g., .gitignore) when using migration tools?

This is a discipline question. Interviewers want to see that you understand what is source of truth vs runtime state.


Short interview answer (what to say)

“You should never commit migration runtime state or generated artifacts—only migration definitions. That means ignoring local DB files, tool caches, logs, and environment-specific configs, while always committing migration scripts themselves.”


What you should ALWAYS commit

These are source of truth:

  • Migration scripts
    • Flyway: db/migration/V*.sql
    • Liquibase: db/changelog/*.xml|yaml|sql
  • Changelog master files
  • Build configuration (Gradle/Maven setup for migrations)

If someone says “ignore migrations” → ❌ instant fail.


What you should IGNORE ❌ (important)

1) Local database files

If you run DB locally (H2, SQLite, embedded Postgres):

*.db
*.mv.db
*.trace.db
/data/
/db-data/

Why:

  • runtime state
  • machine-specific
  • cannot be reproduced safely

2) Environment-specific configs & secrets

Never commit credentials:

application-local.yml
application-dev.yml
.env
.env.local
*.secrets

Use:

  • env vars
  • secret managers
  • CI/CD injection

3) Migration tool runtime artifacts

For Flyway:

.flyway/

For Liquibase:

liquibase.properties

(when it contains local creds)

Reason:

  • contains execution state
  • local paths
  • credentials
  • not portable

4) Logs & reports

flyway.log
liquibase.log
build/reports/

Logs are outputs, not inputs.


5) Build outputs

/build/
/target/

Standard Java rule, but migrations often live under these dirs during builds.


What you should NEVER ignore (common mistake)

❌ Migration history tables

  • flyway_schema_history
  • DATABASECHANGELOG

Why?

  • They live in the database, not Git
  • Ignoring them in Git is meaningless
  • Editing them manually is dangerous (as we discussed)

Clean example .gitignore (migration-relevant part)

# Local DB
*.db
*.mv.db
/db-data/

# Env-specific configs
.env
.env.local
application-local.yml

# Migration tool runtime state
.flyway/
liquibase.properties

# Logs & build output
*.log
/build/
/target/

Senior rule (memorize)

Commit intent. Ignore state.

  • Intent → migration scripts
  • State → DB data, history tables, local configs

Perfect interview phrasing (polished)

“We commit migration scripts and changelogs, but ignore local database files, credentials, environment-specific configs, logs, and tool runtime state. Migration history tables live in the database and are never tracked in version control.”

This entry was posted in Без рубрики. Bookmark the permalink.