#05Intermediate5 min

Generating Migrations

Create a checkpoint of your schema, make changes, and generate SQL migration files that capture exactly what changed.

In this guide

  1. 1Open the Checkpoints modal
  2. 2Create a checkpoint (baseline)
  3. 3Make schema changes
  4. 4Generate the migration
  5. 5Choose your framework and export

How migrations work in ER Flow

ER Flow generates migrations by diffing two schema snapshots: the baseline (your checkpoint) and the current state. It detects every change β€” new tables, dropped tables, renamed tables, added columns, modified columns, new indexes, new foreign keys β€” and generates the corresponding SQL migration code.

Two migration generators are currently supported: Laravel (PHP) and Phinx (PHP). Each generates framework-specific migration code with both up() and down() methods.

Step 1: Open the Checkpoints modal

In the toolbar, click the Flag icon (Checkpoints). This opens the Checkpoints modal where you can manage your schema checkpoints and generate migrations.

Step 2: Create a checkpoint (baseline)

Click "Create Checkpoint" and give it a name (e.g., "Initial schema", "v1.0", "Before user refactor"). Optionally add a description.

A checkpoint captures a complete snapshot of your current schema β€” all tables, columns, indexes, foreign keys, triggers, and procedures. This snapshot is stored on the server and serves as the baseline for future diffs.

You should create a checkpoint:

  • Before starting a new feature or refactor
  • After applying a migration to production (to mark the current state)
  • At any point where you want a "save point" you can diff against

Step 3: Make schema changes

With your checkpoint saved, make whatever changes you need:

  • Add new tables and columns
  • Rename tables or columns
  • Change column types, defaults, or constraints
  • Add or remove indexes
  • Create or delete foreign keys
  • Add triggers or procedures

Every change is tracked. When you generate a migration, ER Flow will compare your current schema against the checkpoint and detect all differences.

Step 4: Generate the migration

Go back to the Checkpoints modal and select the checkpoint you want to diff against. Click "Generate Migration". ER Flow runs the diff engine and shows you:

Left panel β€” Detected Changes: - A summary of all operations (tables created, columns added, indexes modified, etc.) - A detailed list of every individual operation - Warnings for potential issues (e.g., dropping a column with data)

Right panel β€” Generated Code: - The up() migration code (what to run going forward) - The down() migration code (how to roll back)

The diff engine detects these operation types: table.create, table.drop, table.rename, column.add, column.drop, column.rename, column.modify, index.add, index.drop, fk.add, fk.drop, pk.set.

Step 5: Choose your framework and export

At the bottom of the migration modal, you can switch between generators:

Laravel: Generates a standard Laravel migration class with Schema::create(), Schema::table(), $table->string(), $table->foreign(), etc. Includes both up() and down() methods.

Phinx: Generates a Phinx migration class with $this->table(), ->addColumn(), ->addIndex(), ->addForeignKey(), etc.

You can:

  • Copy to clipboard β€” paste it directly into your codebase
  • Download β€” saves as a .php file with a generated name
  • Apply β€” marks the current schema as the new baseline (updates the checkpoint), so the next migration will only capture changes from this point forward

After downloading or copying the migration, add it to your project's migration directory and run it with your framework's migration command (e.g., php artisan migrate for Laravel).