Help › Change a database's structure
Compare two schemas
Find what differs between two schemas of the same kind of database, choose what to carry over, and get the SQL that changes the target to match the source.
Querlyn 0.1.0 is not released yet. This help describes it ahead of release.
Schema compare reads two schemas, lists what differs, and writes the SQL that would make one of them, the target, look like the other, the source. It compares structure only: tables, views and other objects, never the rows in the tables.
A typical use: your development database has the changes of the last weeks, and you want to know exactly what to run on staging.
Start a comparison
| To | Do this |
|---|---|
| Compare a schema with another | Right-click a schema, database or connection in the sidebar and choose Compare With… (). It becomes the source. |
| Open an empty comparison | Compare… at the top of the sidebar, or |
In the tab, pick the two sides:
- Source (what the target should become)
- Target (what the script changes)
Each list holds the schemas of your connections. A connection that is not connected is listed so that you can connect it. Then choose Compare.
A side can also be a schema as it was: a snapshot kept by schema history. A snapshot is never changed, so the script is applied only when the target is a schema as it is now. What a comparison reads of a schema is kept in that schema's history.
Both sides must be the same kind of database. PostgreSQL cannot be compared with MySQL, and MySQL and MariaDB count as two kinds. Two schemas of one connection can be compared.
Both schemas are read fresh from their databases, with a progress count. Stop () ends the reading. Compare Again (⌘R on macOS or Ctrl+R on Windows and Linux) reads both again. Swap exchanges source and target ().
Read the differences
The list groups the objects:
| Group | Meaning | What the script does |
|---|---|---|
| Only in Source | The target does not have it. | Creates it. |
| Only in Target | The source does not have it. | Drops it. |
| Different | Both have it, defined differently. | Changes it. |
| Identical | The same on both sides. Hidden until you choose Show Identical (). | Nothing. |
Select an object to see its definition on both sides, side by side, with the differing lines marked. The source's definition is shown as it would read in the target's schema, so that only real differences stand out.
For more room for the definitions, hide the list with the chevron on its edge or ⌘7 on macOS or Ctrl+7 on Windows and Linux (); the strip it leaves brings it back. Drag its edge to make it wider.
Options
Above the list, under Ignore, you choose what does not count as a difference:
| Option | At the start |
|---|---|
| Whitespace and comments in definitions | On |
| Column order | On |
| Collation | Off |
| Comments | Off |
| Constraint names | Off |
| Match names ignoring case | Off; offered only where the database itself ignores the case of names |
Under Compare you choose the kinds of object: Tables, Views, Functions and Procedures, Sequences, Triggers, and on Oracle Packages and Types.
Changing an option compares again at once, without reading the databases again. The options are not kept when the tab closes.
Choose what goes into the script
Every difference is included at the start. Each object in the list has a check box; clear it to leave that difference out (Space in the list). Include All () and Include None () set them all.
What you leave out stays out while the tab is open, also when you compare again.
Renamed tables and columns
Querlyn matches tables and columns by name. A column renamed in the source therefore looks like a column to drop and a column to add.
Warning: Applied as it stands, such a script drops the old column with its data and adds an empty new one.
To have the script rename instead, select the table. Above its definition, Querlyn lists likely pairs as hints, each with a Treat as Rename button (), and two lists (Only in target, Only in source) to pair any two yourself. Undo Rename Pairing () takes a pairing back.
Tables can be paired the same way. Hints are only offered; Querlyn never pairs anything by itself. Views, functions, indexes and constraints cannot be paired.
Use the script
Show Script () shows the migration script in place of the object's definition; Show Object goes back. The script's statements carry the same warnings as the table designer's, for example Drops table or Rewrites table; see Read the preview. Dropping a view, function, sequence or trigger is marked Drops object.
| Button | What it does |
|---|---|
| Open in Editor | Opens the script in a new query tab on the target's connection and database, without running it (). |
| Copy Script | Copies it (). |
| Save Script… | Saves it as a .sql file (⌘S on macOS or Ctrl+S on Windows and Linux). |
| Apply to Target | Runs it on the target (⌘↩ on macOS or Ctrl+Enter on Windows and Linux). |
Warning: Apply to Target changes the target database and can drop tables and columns. Read the script first. For anything that matters, open it in the editor and review it there, or hand it to whoever reviews your migrations.
Applying works as in the table designer. Querlyn first checks that the target's tables are still as it read them, and asks if they are not (Apply Anyway or Compare Again). On a Production connection it asks before statements that delete something or that it cannot classify. The script runs in one transaction where the database can; see Apply the changes for which databases those are. A read-only target refuses it.
After a successful apply the target is read again, and the list shows what still differs.
What is compared
Tables with their columns, keys, indexes, foreign keys and checks, and then, depending on the database:
| Database | Besides tables |
|---|---|
| PostgreSQL | Views, materialized views, functions, procedures, sequences, triggers |
| MySQL, MariaDB | Views, functions, procedures, triggers |
| SQL Server | Views, procedures, functions, triggers, sequences |
| SQLite | Views, triggers |
| DuckDB | Views, sequences. Macros are not compared. |
| Amazon Redshift | Views, materialized views, functions, procedures |
| ClickHouse | Views, materialized views, dictionaries. A table whose engine or keys differ is reported, not changed by the script. |
| Oracle Database | Views, materialized views, functions, procedures, packages, types, sequences, triggers |
| Snowflake | Views, materialized views, functions, procedures, sequences |
Not compared on any database: the rows (see Compare the data of two tables), privileges, and partitions. Partitioned tables are compared, but the script does not create them.
Things to know about the script:
- Where a database refuses to change a table while a view uses it (PostgreSQL, and SQL Server for some views), the script drops those views and creates them again. The summary lists them.
- A changed view, function or trigger is replaced in place where the database can. Where it must be dropped and created, privileges granted on it must be granted again; the warning says so.
Help for Querlyn 0.1.0. All help topics