0

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.com (free version)

1 Answer 1

0

It 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.

Sign up to request clarification or add additional context in comments.

2 Comments

But if I need to manually add an annotation, and then manually write a script that executes the logic of that same annotation. Then what is the point of annotation and is it not doing double work? That is, I don't understand the role of the annotation itself. My interest was to generate an automatic DDL-script based on the annotation, but you, as far as I understand, suggest to manually write the logic that should be performed by the annotation. I would be glad to receive clarifications!
You are right. But Flyway's migration automation doesn't work very well on some specific cases.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.