Database Schema Diff and Migration Script Generator
Compare two CREATE TABLE schemas, list added, removed and altered tables, columns, keys and indexes, and write up and down migrations.
Працює у вашому браузері. Ваші файли ніколи не залишають пристрій. Дізнатися, як це перевірити
…
Як користуватися
- 1Paste the current schema
Put the DDL running today in Current schema (from), or press Open .sql.
- 2Paste the target schema
Put the schema your code needs in Target schema (to).
- 3Pick the dialect
Choose PostgreSQL or MySQL 8 and decide on the transaction and safe mode options.
- 4Review the changes
Open Changes, read each item and press Treat as rename for any suggested rename that is correct.
- 5Copy the up script
Open Up migration, read the warnings box and copy or download the SQL file.
- 6Keep the rollback
Download the Down (rollback) script and store it next to the up script in your migrations folder.
Про цей інструмент
Writing a migration by hand is where production outages begin: a column dropped instead of renamed, a NOT NULL added to a table that already has rows, a foreign key created before the table it points to. This tool reads two versions of your schema as plain SQL DDL, the one running today and the one your branch needs, and lists every difference: new and removed tables, new, removed and changed columns, primary keys, unique and plain indexes, foreign keys and check constraints. It then writes an ordered migration script and the matching rollback for PostgreSQL or MySQL 8. Suspected renames are offered as one-click hints so data is kept, and safe mode comments out every drop until you have reviewed it.
Who this is for
Backend developers preparing a release, database administrators reviewing a pull request, and teams that keep schema files in Git but do not use an ORM that generates migrations.
Where the two schemas come from
Use the output of `pg_dump --schema-only`, `mysqldump --no-data`, a schema.sql file from your repository or the CREATE statements from a design tool. The parser understands CREATE TABLE with inline and table-level constraints, CREATE INDEX and ALTER TABLE … ADD. Views, functions, triggers and enum types are skipped and listed under the change list, so nothing is ignored silently.
How differences are found
Type aliases are normalised before comparing, so int and integer, varchar and character varying, bool and boolean count as the same. Indexes and foreign keys are compared by what they do (columns, target table, actions) rather than by their generated names, which avoids noise from tools that name constraints differently.
Renames instead of drop and add
A dropped column and a new column of the same type in one table look like a rename. The tool shows these pairs as Possible renames; press Treat as rename and the script uses RENAME COLUMN, keeping the data. Tables whose columns mostly match are offered the same way.
Order of the generated script
Changed foreign keys and indexes are dropped first, then renames, new tables, new and changed columns, dropped columns and tables, and finally primary keys, indexes and foreign keys. With this order a reference never points at an object that does not exist yet. PostgreSQL output is wrapped in BEGIN and COMMIT because its DDL is transactional; MySQL commits every DDL statement, so its script disables foreign key checks while running instead.
Worked example
The current users table has email varchar(120) and a name column; the target has email varchar(255), full_name and a new created_at timestamptz NOT NULL DEFAULT now(). After marking name → full_name as a rename, the PostgreSQL up script contains `ALTER TABLE users RENAME COLUMN name TO full_name;`, `ALTER TABLE users ALTER COLUMN email TYPE varchar(255) USING email::varchar(255);` and `ALTER TABLE users ADD COLUMN created_at timestamptz NOT NULL DEFAULT now();`. The down script renames the column back and drops created_at.
Limits
This is not a database connection: it does not read your live database, so differences that exist only on the server are not seen. Data migrations (back-filling values, splitting columns) still have to be written by you. Partitioning, generated columns, collations and storage parameters are not compared. Always run the script on a copy of the database first.
Приклад із розв'язанням
users.name → full_name marked as a rename, email widened to varchar(255), created_at added NOT NULL with DEFAULT now(): 3 up statements and 3 matching down statements.
Коротко
- Категорія: Розробка та дані
- Працює в браузері, без реєстрації й завантаження.
- Введені вами дані залишаються на пристрої.
- Доступно англійською.
- Вміст востаннє перевірено:
- Офіційне джерело: PostgreSQL ALTER TABLE reference and MySQL 8.0 ALTER TABLE statement documentation
Поширені запитання
Which databases are supported?
The migration scripts are written for PostgreSQL and MySQL 8. The parser also reads SQLite style CREATE TABLE statements as input.
Will it drop my data?
Only if you run a drop. Every DROP TABLE and DROP COLUMN is listed as a data loss risk, and safe mode writes them as comments so you must uncomment them on purpose.
Why does it suggest a rename?
A removed column and an added column with the same type in the same table usually mean a rename. Accepting the hint turns drop plus add into RENAME COLUMN, which keeps the values.
What is the down migration for?
It reverses the up script so you can roll back a release. It is generated by comparing the schemas in the other direction, with your rename hints reversed.
Why is there a warning about NOT NULL?
Adding a NOT NULL column without a default fails on a table that already has rows. Give it a default or add it as nullable, back-fill, then set NOT NULL.
Is my schema uploaded?
No. Parsing and comparison happen in your browser and the schemas are saved only in this browser's storage.
