Announcing Automatic Migrations for Hibernate Users
You can now import the desired database schema from your Hibernate project into Atlas, and use it to automatically plan migrations for you.
Introduction
Hibernate-ORM is one of the most popular ORMs for Java, so much so that parts of it have evolved into the JPA standard and the Jakarta APIs.
Today, we are excited to announce that Atlas now supports loading and managing Hibernate schemas.
Atlas is a modern tool for managing your database schema. It allows you to inspect, plan, lint and apply schema changes to your database. It is designed to be used by developers, DBAs and DevOps engineers alike.
By using Atlas, Hibernate users can now enjoy these benefits:
- A declarative migration flow - Atlas can operate like a "Terraform for databases", where
by running
atlas schema applythe application schema is applied on a target database. - Automatic schema migration planning - Alternatively, Atlas can operate using a more traditional versioned migration flow. However, contrary to most tools, Atlas will automatically analyze the diff between the migration directory and the current application data model, and will produce correct and safe SQL migration files.
- CI for schema changes - Atlas can be used during CI to make sure you never merge a pull request that will break your database schema.
- Modern CD integrations - Atlas integrates seamlessly with modern deployment tools such as Kubernetes, Terraform, Helm, Flux, and ArgoCD. This allows you to deploy changes to your database schema as part of your existing deployment pipelines.
- Visualization - Atlas users can create beautiful, shareable ERDs of their application data model with a single command.
- .. and much more (read more about Atlas features).
Integrating Atlas into your Hibernate project
Hibernate ships with an automatic schema management tool called hbm2ddl.
Similarly to Atlas, this tool can inspect a target database and automatically migrate the schema to the desired one. However, the Hibernate team has been advising for years not to use this tool in production:
Although the automatic schema generation is very useful for testing and prototyping purposes, in a production environment, it’s much more flexible to manage the schema using incremental migration scripts.
This is where Atlas comes in. Atlas can read Hibernate schema and plan database schema migrations.
How does it work?
Atlas compares two database schema states and plans a migration to get from ones state to the other. The database schema can be read directly from Hibernate, a migration directory, a database connection, or another ORM.
To read the Hibernate schema, Atlas utilizes the concept of an external_schema datasource.
Demo Time
For this demo, we are going to use Gradle, PostgreSQL and this example project.