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
- Open the History sidebar panel
- Select two versions to compare — a source (older) and a target (newer)
- Click Compare Versions to see a side-by-side diff
- Click the Generate Migration SQL button
- Choose your target dialect
- Review the generated SQL
- 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
| Change | SQL generated |
|---|---|
| Table added | CREATE TABLE with all columns, constraints |
| Table removed | DROP TABLE |
Columns
| Change | SQL generated |
|---|---|
| Column added | ALTER TABLE ... ADD COLUMN |
| Column removed | ALTER TABLE ... DROP COLUMN |
| Column type changed | ALTER TABLE ... MODIFY COLUMN / ALTER COLUMN |
| Nullable changed | ALTER TABLE ... MODIFY COLUMN with NULL / NOT NULL |
| Default changed | ALTER TABLE ... ALTER COLUMN SET DEFAULT |
Foreign keys
| Change | SQL generated |
|---|---|
| FK added | ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY |
| FK removed | ALTER TABLE ... DROP CONSTRAINT |
Indexes
| Change | SQL generated |
|---|---|
| Index added | CREATE INDEX / CREATE UNIQUE INDEX |
| Index removed | DROP INDEX |
Dialect support
Select the target database dialect before generating SQL. Each dialect produces syntactically correct DDL for that platform.
| Dialect | Notes |
|---|---|
| MySQL | Uses MODIFY COLUMN, backtick quoting |
| PostgreSQL | Uses ALTER COLUMN, double-quote quoting |
| SQL Server | Uses ALTER COLUMN, bracket quoting |
| Oracle | Uses MODIFY, double-quote quoting |
| Snowflake | Uses 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.