-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/create models #6
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
Open
matheusgondra
wants to merge
5
commits into
develop
Choose a base branch
from
feature/create-models
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c76dbbc
feat: create addresses migration
matheusgondra 3b1964d
feat: create users migration
matheusgondra 88ae199
feat: create Address model
matheusgondra bd97d59
feat: create User model
matheusgondra 777324f
fix: rename entity and database table
matheusgondra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.laporeon.library_api.model; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import org.hibernate.annotations.CreationTimestamp; | ||
| import org.hibernate.annotations.UpdateTimestamp; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Data | ||
| @Entity | ||
| @Table(name = "addresses") | ||
| public class Address { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private String street; | ||
|
|
||
| @Column(nullable = false) | ||
| private Integer number; | ||
|
|
||
| @Column(nullable = false, length = 50) | ||
| private String city; | ||
|
|
||
| @CreationTimestamp | ||
| @Column(name = "created_at") | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @UpdateTimestamp | ||
| @Column(name = "updated_at") | ||
| private LocalDateTime updatedAt; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.laporeon.library_api.model; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| import org.hibernate.annotations.CreationTimestamp; | ||
| import org.hibernate.annotations.UpdateTimestamp; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.OneToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.ToString; | ||
|
|
||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Entity | ||
| @Table(name = "people") | ||
| public class Person { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| private UUID id; | ||
|
|
||
| @Column(nullable = false, length = 50) | ||
| private String name; | ||
|
|
||
| @Column(nullable = false, unique = true, length = 11) | ||
| private String cpf; | ||
|
|
||
| @Column(name = "birth_date", nullable = false) | ||
| private LocalDate birthDate; | ||
|
|
||
| @Column(nullable = false) | ||
| private String password; | ||
|
|
||
| @ToString.Exclude | ||
| @OneToOne | ||
| @JoinColumn(name = "address_id") | ||
| private Address address; | ||
|
|
||
| @CreationTimestamp | ||
| @Column(name = "created_at") | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @UpdateTimestamp | ||
| @Column(name = "updated_at") | ||
| private LocalDateTime updatedAt; | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/resources/db/migration/V1__create-table-addresses.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| CREATE TABLE addresses ( | ||
| id SERIAL PRIMARY KEY, | ||
| street VARCHAR NOT NULL, | ||
| number INTEGER NOT NULL, | ||
| city VARCHAR(50) NOT NULL, | ||
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
| ); |
10 changes: 10 additions & 0 deletions
10
src/main/resources/db/migration/V2__create-table-users.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| CREATE TABLE users ( | ||
| id UUID PRIMARY KEY, | ||
| name VARCHAR(50) NOT NULL, | ||
| cpf VARCHAR(11) NOT NULL UNIQUE, | ||
| birth_date DATE NOT NULL, | ||
| password VARCHAR NOT NULL, | ||
| address_id INTEGER REFERENCES addresses(id), | ||
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
| ); |
5 changes: 5 additions & 0 deletions
5
src/main/resources/db/migration/V3__rename-users-to-people.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ALTER TABLE users RENAME TO people; | ||
|
|
||
| ALTER TABLE people RENAME CONSTRAINT users_pkey TO people_pkey; | ||
| ALTER TABLE people RENAME CONSTRAINT users_address_id_fkey TO people_address_id_fkey; | ||
| ALTER TABLE people RENAME CONSTRAINT users_cpf_key TO people_cpf_key; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Não sei se tu vai querer usar builder pattern, mas se for, apenas a sugestão mesmo se quiser aproveitar a PR pra já tacar o
@Buildernessas duas entidadesThere 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.
Não cheguei a usar o padrão builder no java. O que acha melhor?