I have a problem. I put the @Check annotation with the appropriate checks over the entity field. Further, I tried to generate the migration file both through the “DDL by Entities” function and through Liquibase. However, neither of these, when generating the migration script, takes into account in any way at all the @Check-constraints I set in the entities over fields. Is there any way or tools to account for the constraints in the migration files from the @Check annotation?
Translated with DeepL (free version)
I have a problem. I put the @Check annotation with the appropriate checks over the entity field. Further, I tried to generate the migration file both through the “DDL by Entities” function and through Liquibase. However, neither of these, when generating the migration script, takes into account in any way at all the @Check-constraints I set in the entities over fields. Is there any way or tools to account for the constraints in the migration files from the @Check annotation?
Translated with DeepL (free version)
Share Improve this question asked 13 hours ago Дмитрий ДмитриевДмитрий Дмитриев 311 silver badge2 bronze badges1 Answer
Reset to default 0It is so easy. Firstly, let me give you a basic sample.
@Entity
@Check(constraints = "COL_AGE > 18")
public class User{
...
@Column(name = "COL_AGE")
private int age;
}
If the user is underage, database doesn't accept it. After that, you can add easily DDL to migration file.
ALTER TABLE user
ADD CONSTRAINT check_age CHECK (COL_AGE > 18);
I hope it helps you well. Take care.