Atlas vs Classic Schema Migration Tools
Introduction
What are schema migrations?
Most server-side applications are backed by a database. This database usually has a schema that reflects the application's data model. Over time, the application's data model evolves and the database schema must follow suit.
Schema migrations are a common approach in our industry to automate database schema changes. Following this approach, the user creates a versioned migration script, which is the set of commands that should be executed on the database to upgrade the schema from one version to the next, thereby migrating the database to the next version.
What are schema migration tools?
Over the years, hundreds of tools have been created to facilitate the process of database schema migrations. Migration tools typically provide a structured way of defining migration scripts, versioning them, and a program to execute them on a target database.
Because most database schema changes are not idempotent (they cannot be re-run successfully once applied), migration tools commonly maintain a "Changelog Table" on the target database to keep track of which migrations have already been applied.
Which schema migration tool should you use?
Choosing the right migration tool for your project can be daunting due to the sheer number of options available. In this document, we compare Atlas, a modern, database schema-as-code tool to more "classic" options that have been developed over the years.
We will take a high-level look at multiple candidates:
- Liquibase and Flyway - established JVM-based migration tools
- ORM-based solutions - that ship with the most popular ORM and backend frameworks
- Atlas - a modern, database schema-as-code tool
The candidates
Atlas vs Liquibase vs Flyway vs ORMs
Atlas | Liquibase | Flyway | ORMs | |
---|---|---|---|---|
Tagline | Database schema as code (Terraform for databases) | Database DevOps | Database migrations made easy | Varies |
Open-sourced | 2021 | 2006 | 2010 | Varies |
Written in | Go | Java | Java | Varies |
Docker Image Size | 63 MB | 435 MB | 287 MB | Varies |
Migration Format | SQL | XML/JSON/SQL/Java | SQL | Native Code * |
Commercial Support Available | ✅ | ✅ | ✅ | ☒ * |
Liquibase and Flyway - are well-established projects that have been around since 2006 and 2010 respectively. Both are written in Java and require a JVM to execute. Both tools have an open-source distribution and are backed by commercial companies.
Liquibase and Flyway alike operate by letting the user define migration scripts (Flyway in plain SQL, Liquibase in XML, SQL, or Java) and execute them on behalf of the user.
ORM-based Solutions - many backend developers use application development frameworks or ORM libraries to interact with their underlying database. Virtually all of them provide some support for schema management which is crucial for supporting developers in any realistic production environment.
ORM-based migration tools vary greatly in quality and sophistication which makes it a bit difficult to treat them as a single group. In relevant categories where certain tools especially stand out, we will try to mention them specifically. ORM tend to provide native programming language based DSLs for defining migrations (such as Sequelize Migrations, with a few exceptions which use plain SQL.
ORMs tend to be community-based projects without a commercial entity backing them (with the exception of Prisma. This means that the level of support and maintenance can vary greatly between different options.
Atlas - is a database schema-as-code tool that applies modern DevOps principles to the ancient art of database schema management. Many of its users call it a "Terraform for Databases" because of its schema-first, declarative approach.
Atlas is an open-core project developed by Ariga and is available under both a commercial and an open-source license.
In case you missed it, this document is written and maintained by the team behind Atlas 😊
The Comparison
Summary (tl;dr)
To assist you in deciding which database migration tool is right for you, we will compare the different possibilities along these categories:
Description | Atlas | Liquibase | Flyway | ORMs | |
---|---|---|---|---|---|
Schema-as-code | Schema-first approach? | ✅ | Revisions | Revisions | Mix |
Auto migration planning | Are changes planned by the tool? | ✅ | Manual | Manual | Manual* |
Auto code review | Are automated quality checks available? | ✅ | Some | Some | Some |
Testing framework | Unit and integration tests for database and migrations logic? | ✅ | ☒ | ☒ | ☒ |
CLI Support | Is CLI support available? | ✅ | ✅ | ✅ | ✅ |
Kubernetes Operator | Can users natively deploy from k8s? | ✅ | ☒ | ☒ | ☒ |
Terraform Provider | Does the tool integrate with IaC? | ✅ | ☒ | ☒ | ☒ |
Database per tenant migrations | Built-in support for managing migrations across tenants? | ✅ | ☒ | ☒ | ☒ |
Webhook Notifications | Real-time alerts on schema changes via Slack or custom endpoints | ✅ | ☒ | ☒ | ☒ |
Schema Drift Detection | Detect and report unintended schema changes | ✅ | ☒ | ☒ | ☒ |
Approval Flows | Human-in-the-loop approvals for critical migrations | ✅ | ☒ | ☒ | ☒ |
Database Support | Database driver count | 13 | 60 | 31 | Varies |
* Exceptions exist
Schema-as-code
What is the source-of-truth for your database schema?
Atlas | Liquibase | Flyway | ORMs | |
---|---|---|---|---|
Migrations | ✅ | ✅ | ✅ | Mix |
SQL Schema | ✅ | ☒ | ☒ | ☒ |
ORM Models | ✅ | ☒ | ☒ | Mix |
HCL | ✅ | ☒ | ☒ | ☒ |
One of the most important principles that came from the DevOps movement is the idea that to achieve effective automation, you need to be able to build everything, deterministically, from a single source of truth.
This is especially important when it comes to databases! The database schema is a critical part of our application and we better have a way to ensure it is compatible with the code we are deploying.
Let's compare the approach to defining the source of truth schema between different migration tools:
Flyway and Liquibase are "version-based", which means that to obtain the current source of truth schema, one needs to replay all migrations on an empty database and inspect the result.
ORMs and frameworks are more difficult to classify. On one hand, ORMs and frameworks revolve around a code-first definition of the different entities in the application data model.
On the other hand, migrations are defined as revisions, in a version-based approach. Aside from Prisma and Django, most frameworks do not supply a mechanism to ensure that the planned migrations are consistent with the application data model as it is defined in the ORM.
Atlas is a database schema-as-code tool that takes the "schema-based" approach. Developers provide Atlas with the source-of-truth schema in various ways (SQL, HCL, and many other programming languages), and Atlas uses that to automatically plan changes. This way, the source of truth schema is always readily available and legible to users.
Atlas provides a set of plugins called "schema loaders" for integrating with ORMs such as SQLAlchemy, GORM and Hibernate.
By using schema loaders, developers can keep defining the application data model using their favorite ORM and programming language while offloading database schema management to Atlas.