This project uses Flyway for migrations. The decision has been made to keep the PostgreSQL sequence generation instead of the global one sequence to rule them all of Hibernate.
The ability for Hibernate to automagically update the database for you has been disabled. Any changes to the database schema has to be done manually, and a migration made.
To make a new migration create a new entity. The convention for tables and columns matches those of Ruby on Rails, not the default Hibernate/JPA of just naming it exactly after the class.
An example entity with a custom set table name and a PostgreSQL table sequence.
@Entity
@Table(name = "commands")
public class Command {
@Id
// This line creates a sequence `commands_id_seq` that is for the field `id` in the table `commands`.
@SequenceGenerator(name = "pk_sequence", sequenceName = "commands_id_seq")
// Wire the sequence up to the id.
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pk_sequence")
private long id;
@Column(unique = true)
private String name;
private String endpoint;
private RequestMethod method;
}
In development mode any new entity will automatically generate a new table with the correct fields on it. You can then copy the table definition to a new migration.
Note: Tests are run in their own profile and they rely on all database changes to happen through a migration.
The migration file for the above entity is named V1__Add_commands_table.sql
and contained at the time of writing:
CREATE TABLE commands
(
id BIGSERIAL, -- This is PostgreSQL syntax for a bigint primary key with its own serial sequence.
endpoint VARCHAR(255),
method INTEGER,
name VARCHAR(255)
);
CREATE UNIQUE INDEX uk_py1b1n9yenhsrtlh4gj3p7b4g ON commands (name);
Flyway will automatically migrate the database to the latest version on boot.
It's probably because IntelliJ hasn't been configured to support annotation processors.
Do so by:
- Opening the settings window for "Annotation processors"
- Click "Enable annotation processors"
- Recompile the entire project