Menu

Generate SQL migrations from your JPA entities
📰

Generate SQL migrations from your JPA entities

DEV Community: postgres·Feroz Shah·1 day ago
#B9JqBLwA
#devtopostgresql#devto#dev#migrax#migration
Reading 0:00
15s threshold

Your JPA entities already describe the schema you want. Writing the same change again by hand as SQL is slow and easy to get wrong. Migrax compares your entities with the last state you committed and writes the SQL migration for you, along with a rollback script. You review the SQL, commit it, and apply it.

This article walks through that loop on a small project: create the first tables, add a column, and catch a missing migration in CI.

Tested with: Migrax 0.16.0, Hibernate 6.6.13, PostgreSQL 17. Every output below was copied from a real run.

The project

Two entities, a customer and an order:

@Entity @Table ( name = "customers" ) public class Customer { @Id @GeneratedValue ( strategy = GenerationType . IDENTITY ) Long id ;

@Column ( nullable = false , unique = true , length = 150 ) String email ;

@Column ( nullable = false , length = 100 ) String name ; }

@Entity @Table ( name = "orders" ) public class PurchaseOrder { @Id @GeneratedValue ( strategy = GenerationType .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.