Pcornel
Databases · Schema, Keys & Data Types

Schema Migrations

Cheat sheet · https://pcornel.dk/topic.php?topic=6169

Back to the Topic

Answer

Schema migrations apply versioned, repeatable changes to database structure (Flyway, Liquibase, Alembic, framework migrations).

Remember

Keep migrations in version control, test on production-size data, and make them backward-compatible for rolling deploys (expand → migrate → contract). Know which DDL locks tables.

First checks

  • flyway info — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

migration script → applied in order → recorded in history table

Where it usually breaks

Editing an already-applied migration makes environments differ.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6169

Confirmation

Confirm action

Continue?