Migration SQL Generator
Describe a schema change and get matching up and down migration SQL for Postgres or MySQL, including the safe ordering for a live table.
🔒 This tool runs entirely in your browser. Your files are never uploaded to a server.
Developer
Migration SQL Generator
Frontend preview — no upload or external service.
Migration SQL
Up: ALTER TABLE orders ADD COLUMN customer_ref text; CREATE INDEX CONCURRENTLY idx_orders_customer_ref ON orders (customer_ref); Down: DROP INDEX and DROP COLUMN in reverse order.
How the Migration SQL Generator works
- Choose the change and the database, since locking behaviour differs sharply between them.
- Name the table and column involved.
- Copy both directions into your migration file and read the notes about which statement takes a lock.
FAQ
Why does the index use CONCURRENTLY?
Because a plain CREATE INDEX on Postgres takes a write lock for the whole build, which stalls a busy table. CONCURRENTLY avoids that at the cost of taking longer and being unable to run inside a transaction.
Is adding a column safe on a large table?
Adding a nullable column with no default is fast on modern Postgres and MySQL. Adding a NOT NULL column with a default used to rewrite the table and still can on older versions — check yours before running it in production.
Why write the down migration at all?
Because you will need it under pressure, at the worst moment, and that is not when you want to be composing DDL. A reversible migration is also a check that the up direction was thought through.
How we compare
| Feature | Online Tool Store | A CLI script | An IDE plugin |
|---|---|---|---|
| Both directions generated | ✓ | Manual | Sometimes |
| Lock behaviour flagged | ✓ | ✗ | ✗ |
| Dialect-specific syntax | ✓ | Manual | ✓ |
| Connects to your database | ✗ | ✗ | ✓ |
| No credentials required | ✓ | ✓ | ✗ |
Migration SQL Generator writes the statements and, more usefully, warns which of them will hold a lock on a table that is still serving traffic.