Skip to main content
Products -> ERDPricingDocsBlogSign in한국어Start with ERD

Migration SQL

Ainecto can automatically generate migration SQL by comparing two versions of your diagram. Instead of writing ALTER TABLE statements by hand, let the tool diff your schema snapshots and produce the DDL for you.


How it works

  1. Open the History sidebar panel
  2. Select two versions to compare — a source (older) and a target (newer)
  3. Click Compare Versions to see a side-by-side diff
  4. Click the Generate Migration SQL button
  5. Choose your target dialect
  6. Review the generated SQL
  7. Click the Copy button to copy to clipboard

The migration SQL represents the minimal set of DDL statements needed to transform the source schema into the target schema.


Supported operations

The generator detects and produces statements for the following changes:

Tables

ChangeSQL generated
Table addedCREATE TABLE with all columns, constraints
Table removedDROP TABLE

Columns

ChangeSQL generated
Column addedALTER TABLE ... ADD COLUMN
Column removedALTER TABLE ... DROP COLUMN
Column type changedALTER TABLE ... MODIFY COLUMN / ALTER COLUMN
Nullable changedALTER TABLE ... MODIFY COLUMN with NULL / NOT NULL
Default changedALTER TABLE ... ALTER COLUMN SET DEFAULT

Foreign keys

ChangeSQL generated
FK addedALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY
FK removedALTER TABLE ... DROP CONSTRAINT

Indexes

ChangeSQL generated
Index addedCREATE INDEX / CREATE UNIQUE INDEX
Index removedDROP INDEX

Dialect support

Select the target database dialect before generating SQL. Each dialect produces syntactically correct DDL for that platform.

DialectNotes
MySQLUses MODIFY COLUMN, backtick quoting
PostgreSQLUses ALTER COLUMN, double-quote quoting
SQL ServerUses ALTER COLUMN, bracket quoting
OracleUses MODIFY, double-quote quoting
SnowflakeUses ALTER COLUMN, double-quote quoting

Example output

-- Migration from v3 to v5

ALTER TABLE "orders" ADD COLUMN "discount_code" VARCHAR(50);

ALTER TABLE "orders" DROP COLUMN "legacy_status";

ALTER TABLE "products"
ADD CONSTRAINT "fk_products_category"
FOREIGN KEY ("category_id") REFERENCES "categories" ("id");

CREATE INDEX "idx_orders_created_at" ON "orders" ("created_at");

Tips

  • Save versions before major changes — the migration tool needs at least two snapshots to compare.
  • Review before running — always inspect the generated SQL and test it against a staging database before applying to production.
  • Use the copy button — click the clipboard icon to copy the full SQL output, ready to paste into your database client or migration file.
  • Combine with version history — use the Version History feature to maintain a clear timeline of schema evolution.