Sobes.tech
Middle

What happened to the database? Migrations have been applied. The database is in a modified state — how to understand what happened and how to recover?

sobes.tech AI

Answer from AI

If after applying migrations the database is in a changed state, and you need to understand what happened and how to restore:

  1. Understand what exactly changed:

    • Check migration logs (e.g., Flyway or Liquibase) — which scripts were applied.
    • Compare the current schema with the expected one (using schema comparison tools).
    • Look at tables responsible for migration versions (e.g., flyway_schema_history) to see which migrations were applied.
  2. Analyze the consequences:

    • If migrations changed data structure (deleted columns, tables), data may be lost.
    • If migrations added new constraints or indexes, check if this caused errors.
  3. Recovery:

    • If backups are available, restore the database from backup.
    • If migrations were erroneous, try to rollback (if supported).
    • Manually restore data if possible.
    • Fix migration scripts and reapply them in a test environment.
  4. Prevention:

    • Implement migration testing processes on a test database before production.
    • Use transactions in migrations if the DBMS supports it.

Thus, first gather information about applied migrations and their effects, then decide whether to restore from backup or fix the migrations.

What happened to the database? Migrations have been… - sobes.tech