This repository has been archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev/db/Добавил миграцию базы данных (#3)
* dev/db/Добавил миграцию базы данных * dev/db/Добавил entity для бд * dev/db/Добавил jpa репозитории
- Loading branch information
1 parent
48f993d
commit 4d49095
Showing
20 changed files
with
397 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Empty file.
34 changes: 34 additions & 0 deletions
34
src/main/java/com/cf/cfteam/models/entities/codeforces/CfUser.java
This file contains 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,34 @@ | ||
package com.cf.cfteam.models.entities.codeforces; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = "group") | ||
@Entity | ||
@Table(name = "cf_users", schema = "codeforces") | ||
public class CfUser { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "c_description", nullable = true) | ||
private String description; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "c_group_id", nullable = false) | ||
private CfUsersGroup group; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/cf/cfteam/models/entities/codeforces/CfUsersGroup.java
This file contains 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,39 @@ | ||
package com.cf.cfteam.models.entities.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.security.User; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = {"user", "cfUsers"}) | ||
@Entity | ||
@Table(name = "t_cf_users_groups", schema = "codeforces") | ||
public class CfUsersGroup { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "c_description", nullable = true) | ||
private String description; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "c_user_id", nullable = false) | ||
private User user; | ||
|
||
@OneToMany(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<CfUser> cfUsers; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/cf/cfteam/models/entities/codeforces/CfUsersTeam.java
This file contains 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,43 @@ | ||
package com.cf.cfteam.models.entities.codeforces; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = "group") | ||
@Entity | ||
@Table(name = "t_cf_teams", schema = "codeforces") | ||
public class CfUsersTeam { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "c_description", nullable = true) | ||
private String description; | ||
|
||
@Column(name = "c_first_user_login", nullable = true) | ||
private String firstUser; | ||
|
||
@Column(name = "c_second_user_login", nullable = true) | ||
private String secondUser; | ||
|
||
@Column(name = "c_third_user_login", nullable = true) | ||
private String thirdUser; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "c_group_id", nullable = false) | ||
private CfUsersTeamsGroup group; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/cf/cfteam/models/entities/codeforces/CfUsersTeamsGroup.java
This file contains 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,39 @@ | ||
package com.cf.cfteam.models.entities.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.security.User; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = {"user", "cfTeams"}) | ||
@Entity | ||
@Table(name = "t_cf_users_teams_groups", schema = "codeforces") | ||
public class CfUsersTeamsGroup { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "c_description", nullable = true) | ||
private String description; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "c_user_id", nullable = false) | ||
private User user; | ||
|
||
@OneToMany(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<CfUsersTeam> cfTeams; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/cf/cfteam/models/entities/security/Role.java
This file contains 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,6 @@ | ||
package com.cf.cfteam.models.entities.security; | ||
|
||
public enum Role { | ||
USER, | ||
ADMIN | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/cf/cfteam/models/entities/security/Token.java
This file contains 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,34 @@ | ||
package com.cf.cfteam.models.entities.security; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = "user") | ||
@Entity | ||
@Table(name = "t_tokens", schema = "security") | ||
public class Token { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_token", nullable = false) | ||
private String token; | ||
|
||
@Column(name = "c_revoked", nullable = false) | ||
private boolean revoked; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "c_user_id", nullable = false) | ||
private User user; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/cf/cfteam/models/entities/security/User.java
This file contains 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,41 @@ | ||
package com.cf.cfteam.models.entities.security; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
@Builder | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(exclude = "tokens") | ||
@Entity | ||
@Table(name = "t_users", schema = "security") | ||
public class User { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "c_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "c_login", unique = true, nullable = false) | ||
private String login; | ||
|
||
@Column(name = "c_hashed_password", nullable = false) | ||
private String hashedPassword; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "c_role", nullable = false) | ||
private Role role; | ||
|
||
@Column(name = "с_time", nullable = false) | ||
private Instant createdTime; | ||
|
||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<Token> tokens; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/cf/cfteam/repositories/jpa/codeforces/CfUserRepository.java
This file contains 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,7 @@ | ||
package com.cf.cfteam.repositories.jpa.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.codeforces.CfUser; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CfUserRepository extends JpaRepository<CfUser,Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/cf/cfteam/repositories/jpa/codeforces/CfUsersGroupRepository.java
This file contains 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,7 @@ | ||
package com.cf.cfteam.repositories.jpa.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.codeforces.CfUsersGroup; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CfUsersGroupRepository extends JpaRepository<CfUsersGroup, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/cf/cfteam/repositories/jpa/codeforces/CfUsersTeamRepository.java
This file contains 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,7 @@ | ||
package com.cf.cfteam.repositories.jpa.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.codeforces.CfUsersTeam; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CfUsersTeamRepository extends JpaRepository<CfUsersTeam, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/cf/cfteam/repositories/jpa/codeforces/CfUsersTeamsGroupRepository.java
This file contains 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,7 @@ | ||
package com.cf.cfteam.repositories.jpa.codeforces; | ||
|
||
import com.cf.cfteam.models.entities.codeforces.CfUsersTeamsGroup; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CfUsersTeamsGroupRepository extends JpaRepository<CfUsersTeamsGroup, Long> { | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/cf/cfteam/repositories/jpa/security/TokenRepository.java
This file contains 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,14 @@ | ||
package com.cf.cfteam.repositories.jpa.security; | ||
|
||
import com.cf.cfteam.models.entities.security.Token; | ||
import com.cf.cfteam.models.entities.security.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface TokenRepository extends JpaRepository<Token, Long> { | ||
Optional<Token> findByToken(String token); | ||
|
||
List<Token> findAllByUserAndRevoked(User user, boolean revoked); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/cf/cfteam/repositories/jpa/security/UserRepository.java
This file contains 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,11 @@ | ||
package com.cf.cfteam.repositories.jpa.security; | ||
|
||
import com.cf.cfteam.models.entities.security.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
Optional<User> findByLogin(String login); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 @@ | ||
spring: | ||
application: | ||
name: T-Bank2024.Fintech-Java-dev-Spring | ||
datasource: | ||
url: jdbc:postgresql://${POSTGRES_CONTAINER_NAME:localhost}:${POSTGRES_PORT:5432}/${POSTGRES_DB:CodeforcesLocalDB} | ||
username: ${POSTGRES_USER:postgres} | ||
password: ${POSTGRES_PASSWORD:123} | ||
driver-class-name: org.postgresql.Driver | ||
profiles: | ||
active: prod |
This file contains 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,52 @@ | ||
--liquibase formatted sql | ||
|
||
--changeset alexandergarifullin:1 | ||
CREATE SCHEMA IF NOT EXISTS codeforces; | ||
|
||
--changeset alexandergarifullin:2 | ||
CREATE TABLE codeforces.t_cf_users_teams_groups | ||
( | ||
id BIGSERIAL PRIMARY KEY, | ||
c_name TEXT NOT NULL, | ||
c_description TEXT, | ||
с_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
c_user_id BIGINT NOT NULL, | ||
CONSTRAINT fk_team_group_user FOREIGN KEY (c_user_id) REFERENCES security.t_users (id) | ||
); | ||
|
||
--changeset alexandergarifullin:3 | ||
CREATE TABLE codeforces.t_cf_teams | ||
( | ||
id BIGSERIAL PRIMARY KEY, | ||
c_name TEXT NOT NULL, | ||
c_description TEXT, | ||
c_first_user_login TEXT, | ||
c_second_user_login TEXT, | ||
c_third_user_login TEXT, | ||
с_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
c_group_id BIGINT NOT NULL, | ||
CONSTRAINT fk_cf_team_team_group FOREIGN KEY (c_group_id ) REFERENCES codeforces.t_cf_users_teams_groups (id) | ||
); | ||
|
||
--changeset alexandergarifullin:4 | ||
CREATE TABLE codeforces.t_cf_users_groups | ||
( | ||
id BIGSERIAL PRIMARY KEY, | ||
c_name TEXT NOT NULL, | ||
c_description TEXT, | ||
с_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
c_user_id BIGINT NOT NULL, | ||
CONSTRAINT fk_group_user FOREIGN KEY (c_user_id) REFERENCES security.t_users (id) | ||
); | ||
|
||
--changeset alexandergarifullin:5 | ||
CREATE TABLE codeforces.cf_users | ||
( | ||
id BIGSERIAL PRIMARY KEY, | ||
c_name TEXT NOT NULL, | ||
c_description TEXT, | ||
с_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
c_group_id BIGINT NOT NULL, | ||
CONSTRAINT fk_cf_user_group FOREIGN KEY (c_group_id) REFERENCES codeforces.t_cf_users_groups (id) | ||
); | ||
|
This file contains 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 @@ | ||
databaseChangeLog: | ||
- include: | ||
file: db/changelog/security-changelog.sql | ||
- include: | ||
file: db/changelog/codeforces-changelog.sql |
Oops, something went wrong.