Hibernate DDL Manager
Controlled schema evolution from Hibernate metadata.
The idea
A Scala 3 framework that compares Hibernate mappings with the database before SessionFactory startup. Stable schema IDs let it recognize renames and make potentially destructive changes explicit.
What it does.
Schema comparison
Derive a change plan from Hibernate metadata and the current database.
Rename detection
Stable IDs distinguish a rename from a drop and an add.
Explicit approval
Changes outside the supported scope are refused instead of guessed.
Installation
libraryDependencies += "com.anjunar.hibernateddl" %% "schema-integration" % "1.0.0"
Package: com.anjunar.hibernateddl:schema-integration
Start building.
Add schema-integration and assign stable @SchemaId values to managed entities and fields.
Stable IDs make renames visible
The column name can change while its schema ID stays the same. The planned migration becomes a rename instead of a drop and add.
@Entity
@SchemaId("7f3a9c21")
@Table(name = "customer")
class Customer:
@Id @SchemaId("0a1b2c3d")
var id: java.lang.Long = uninitialized
@SchemaId("f34e45b6")
@Column(name = "nick_name")
var nickName: String = uninitialized
// Rename nick_name to alias; keep its @SchemaId.
// Planned SQL: ALTER TABLE "public"."customer"
// RENAME COLUMN "nick_name" TO "alias";Preview before startup
Preview the exact plan without changing the database, then run the migration before creating the SessionFactory.
val metadata = MetadataSources(registry) .addAnnotatedClass(classOf[Customer]) .buildMetadata() val report = HibernateSchemaMigration.preview( metadata, dataSource, previewOptions = PreviewOptions(dataChecks = DataChecks.Existence) ) println(PreviewRendering.text(report)) HibernateSchemaMigration.migrate(metadata, dataSource) val sessionFactory = metadata.buildSessionFactory()
By design.
The integration runs before SessionFactory creation. It records schema history and applies only supported PostgreSQL changes.
Make it part of your stack.
Explore further.
Scala.js UI
A Scala 3 and Scala.js UI framework for server-rendered applications.
↗JSON Mapper
JSON mapping for existing object graphs and domain models.
↗Scala Universe
A resolved view of JVM types, generics and annotations.
↗Scala JS Ember
A modular rich-text editor built on one immutable document model.
↗Scala Reflect
Type metadata generated at compile time for the JVM and Scala.js.
↗