Skip to content
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

Merged
merged 1 commit into from
Dec 11, 2024

Conversation

KinTrae
Copy link
Collaborator

@KinTrae KinTrae commented Dec 9, 2024

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:

  • successful creation of all database models using jpa buddy (with needed refactoring, cause it wasn't perfect)
  • refactor of existing code, so it now uses the created models
  • creation of enums that will reflect the databases 'dictionary' tables
  • dev test that shows successful creation of a user, sign-in, and post creation with all the changes mentioned above

Dev test: https://pejot.sharepoint.com/:w:/s/MeowHub/EZLwRwAB3gBBh4uXNHbpFr0B5XDrxO66kkOToV9K0jDD-A?e=3f4V7X

Task: 8696y76r9

@JimTheCat
Copy link
Owner

Task linked: CU-8696y76jy EPIC - API v3

@KinTrae KinTrae force-pushed the CU-8696y76jy_EPIC---API-v3_Kinga-Traczyk branch 4 times, most recently from 2c61db9 to dc72213 Compare December 10, 2024 12:22
.postsPrivacy(publicSettings)
.friendsPrivacy(publicSettings)
.birthdate(request.getBirthdate())
.salt("salt")
Copy link
Owner

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)
Copy link
Owner

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

Comment on lines +56 to +57
@NotNull
@Column(name = "ANSWER_DATE", nullable = false)
Copy link
Owner

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

Copy link
Collaborator Author

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.

@KinTrae KinTrae force-pushed the CU-8696y76jy_EPIC---API-v3_Kinga-Traczyk branch from dc72213 to 0364984 Compare December 11, 2024 10:38
@@ -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
Copy link
Collaborator Author

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +178 to +188
@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();
}
Copy link
Owner

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

Copy link
Collaborator Author

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

Copy link
Owner

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")
Copy link
Collaborator Author

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

Copy link
Owner

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;

Copy link
Collaborator Author

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");
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialization of create schemas

@JimTheCat
Copy link
Owner

Green light!

@KinTrae KinTrae merged commit e42fb28 into dev Dec 11, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants