-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Creating database models with reverse database engineering provided by jpa buddy #72
Conversation
Task linked: CU-8696y76jy EPIC - API v3 |
2c61db9
to
dc72213
Compare
.postsPrivacy(publicSettings) | ||
.friendsPrivacy(publicSettings) | ||
.birthdate(request.getBirthdate()) | ||
.salt("salt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should create a salt implementation to generate actual things. :-(
@JoinColumn(name = "USER_ID", nullable = false) | ||
private User user; | ||
|
||
@Size(max = 40) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if jwt token is that short. Please double check it
@NotNull | ||
@Column(name = "ANSWER_DATE", nullable = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation @NotNull and nullable attribute is redundant. Maybe let's choose how we are going to set if something is not nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not redundant, as they serve different purpose. @NotNull is bean validation and is used to validate that a property is not null at runtime during validation.
Nullable = false is a databae constraint.
…rovided by jpa buddy Task: 8696y76r9
dc72213
to
0364984
Compare
Quality Gate passedIssues Measures |
@@ -32,4 +32,4 @@ jobs: | |||
distribution: 'temurin' | |||
cache: maven | |||
- name: Build with Maven | |||
run: mvn -B package -Dspring.profiles.active=dev --file pom.xml | |||
run: mvn -B package -Dspring.profiles.active=test --file pom.xml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i created a dedicated for tests test profile, and deleted the dev profile as it was no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof User)) return false; | ||
return id != null && id.equals(((User) o).getId()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return getClass().hashCode(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use @EqualsAndHashCode annotation? If they're not custom then please replace them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, i thought u might look into it. As you can see, the equals function is overrided -> the object is only compared by its id. So i can't use @EqualsAndHashCode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so it's fine ✨
@Column(name = "MSG_DATE", nullable = false) | ||
private LocalDate msgDate; | ||
|
||
@Column(name = "CREATED_AT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may have noticed, but i deleted @NotNull and nullable=false annotation for createdBy and createdAt.
These fields are populated by an audit trigger that is not visible from hibernate's perspective.
@NotNull was throwing an error, because it checks on application level before save, if the field is not null.
nullable = false was deleted, because when running tests for h2, (h2 database for tests is populated by hibernate with models) was throwing an exception, because the triggers are not created there. For production environment is still works correctly, as we are using database-first approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough 😊
@Size(max = 512) | ||
@Column(name = "TOKEN", length = 512) | ||
private String token; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i modified the size of the column that will store tokens in the future. Currently, our token only stores user basic data and roles, and it will be more than enough. Token size monitoring is recommended in the future
user1.setName("Jan"); | ||
user1.setSurname("Kos"); | ||
user1.setSalt("salt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am aware that this approach to hardcode salt is disgusting, but currently we don't have a working mechanism for it yet. Also, this task was meant only to create models with reverse database engineering and adjust the project so it can run with then smoothly.
The salt implementation will be provided in the future, it might be after delivering certain API's like posts API or profiles API though, as they have higher priority now.
@@ -0,0 +1,2 @@ | |||
springdoc.api-docs.enabled=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i created a separate profile, just for swagger for clarity
CREATE SCHEMA IF NOT EXISTS MH_USERS; | ||
CREATE SCHEMA IF NOT EXISTS MH_CHATS; | ||
CREATE SCHEMA IF NOT EXISTS MH_MATCHING; | ||
CREATE SCHEMA IF NOT EXISTS MH_POSTS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed init schema file, as the h2 db ran in create-drop mode does not have any recollection of used schema's for the tables and throws exceptions
spring.datasource.password= | ||
|
||
spring.sql.init.mode=always | ||
spring.sql.init.schema-locations=classpath:create_schemas_h2.sql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialization of create schemas
Green light! |
It's a part of bigger changes, in the upcoming PR's and with promotor's insight there will a restructurization of the project, in the direction of DDD architeture.
In this PR:
Dev test: https://pejot.sharepoint.com/:w:/s/MeowHub/EZLwRwAB3gBBh4uXNHbpFr0B5XDrxO66kkOToV9K0jDD-A?e=3f4V7X
Task: 8696y76r9