Skip to main content

Declarative schema migrations

It is sometimes useful to be able to calculate the diff between two databases. For instance, as you are developing you may want to calculate how to move from an existing database to some other state that you are interested in. Alternatively, you may be diagnosing some issue and want to verify there is no difference between a local copy of a schema and a remote one.

To accommodate these types of use-cases, Atlas supports the schema diff command. This command connects to two given databases, inspects them, calculates the difference in their schemas, and prints a plan of SQL statements to migrate the "from" database to the schema of the "to" database.

Flags

  • --from (required) - the URL of the database to calculate the diff from.
  • --to (required) - the URL of the database to calculate the diff to.

Examples

Diff to a remote database:

atlas schema diff --from "mysql://user:pass@localhost:3306" --to "mysql://user:pass@remote:3306"

Diff to a remote schema

atlas schema diff --from "mysql://user:pass@localhost:3306/schema" --to "mysql://user:pass@remote:3306/schema"

Diff to another schema in the same database

atlas schema diff --from "mysql://user:pass@localhost:3306/schema" --to "mysql://user:pass@localhost:3306/other"

Reference

CLI Command Reference