feat: add Firearm and Modification entities with database schema
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.onixbyte.deltaforceguide.domain.entity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "firearm")
|
||||
public class Firearm {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name", nullable = false, length = 64)
|
||||
private String name;
|
||||
|
||||
@Column(name = "type", nullable = false)
|
||||
private Integer type;
|
||||
|
||||
@Column(name = "level", nullable = false)
|
||||
private Integer level;
|
||||
|
||||
@Column(name = "review", columnDefinition = "TEXT")
|
||||
private String review;
|
||||
|
||||
@OneToMany(mappedBy = "firearm", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Modification> modifications = new ArrayList<>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getReview() {
|
||||
return review;
|
||||
}
|
||||
|
||||
public void setReview(String review) {
|
||||
this.review = review;
|
||||
}
|
||||
|
||||
public List<Modification> getModifications() {
|
||||
return modifications;
|
||||
}
|
||||
|
||||
public void setModifications(List<Modification> modifications) {
|
||||
this.modifications = modifications;
|
||||
}
|
||||
|
||||
public void addModification(Modification modification) {
|
||||
this.modifications.add(modification);
|
||||
modification.setFirearm(this);
|
||||
}
|
||||
|
||||
public void removeModification(Modification modification) {
|
||||
this.modifications.remove(modification);
|
||||
modification.setFirearm(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package com.onixbyte.deltaforceguide.domain.entity;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(
|
||||
name = "modification",
|
||||
indexes = {
|
||||
@Index(name = "idx_modification_firearm_id", columnList = "firearm_id")
|
||||
}
|
||||
)
|
||||
public class Modification {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
||||
@JoinColumn(name = "firearm_id", nullable = false, foreignKey = @ForeignKey(name = "fk_modification_firearm"))
|
||||
private Firearm firearm;
|
||||
|
||||
@Column(name = "name", nullable = false, length = 64)
|
||||
private String name;
|
||||
|
||||
@Column(name = "code", nullable = false, length = 64)
|
||||
private String code;
|
||||
|
||||
@Type(JsonType.class)
|
||||
@Column(name = "tags", columnDefinition = "json")
|
||||
private List<String> tags = new ArrayList<>();
|
||||
|
||||
@Column(name = "note", columnDefinition = "TEXT")
|
||||
private String note;
|
||||
|
||||
@Column(name = "author", length = 64)
|
||||
private String author;
|
||||
|
||||
@Column(name = "video_url", length = 512)
|
||||
private String videoUrl;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Firearm getFirearm() {
|
||||
return firearm;
|
||||
}
|
||||
|
||||
public void setFirearm(Firearm firearm) {
|
||||
this.firearm = firearm;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public List<String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getVideoUrl() {
|
||||
return videoUrl;
|
||||
}
|
||||
|
||||
public void setVideoUrl(String videoUrl) {
|
||||
this.videoUrl = videoUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,46 @@
|
||||
spring:
|
||||
application:
|
||||
name: delta-force-guide-server
|
||||
name: delta-force-guide
|
||||
cache:
|
||||
type: redis
|
||||
redis:
|
||||
time-to-live: PT2H
|
||||
data:
|
||||
redis:
|
||||
repositories:
|
||||
# Disable redis repositories
|
||||
enabled: false
|
||||
jta:
|
||||
# Disable JTA support
|
||||
enabled: false
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
transaction:
|
||||
jta:
|
||||
# No need to use distributed transaction manager for 1 datasource.
|
||||
platform: org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
open-in-view: false
|
||||
datasource:
|
||||
hikari:
|
||||
minimum-idle: 1
|
||||
maximum-pool-size: 10
|
||||
flyway:
|
||||
enabled: true
|
||||
baseline-on-migrate: true
|
||||
|
||||
mybatis:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
map-underscore-to-camel-case: true
|
||||
type-aliases-package: com.onixbyte.deltaforceguide.domain.entity
|
||||
type-handlers-package: com.onixbyte.deltaforceguide.mapper.handler
|
||||
mapper-locations: classpath:/mapper/*.xml
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.hibernate:
|
||||
orm.connections.pooling: off
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
DROP TABLE IF EXISTS firearm CASCADE;
|
||||
DROP TABLE IF EXISTS modification CASCADE;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS firearm
|
||||
(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(64) NOT NULL,
|
||||
type INT NOT NULL,
|
||||
level INT NOT NULL,
|
||||
review TEXT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS modification
|
||||
(
|
||||
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
firearm_id BIGINT NOT NULL,
|
||||
name VARCHAR(64) NOT NULL,
|
||||
code VARCHAR(64) NOT NULL,
|
||||
tags JSON NULL,
|
||||
note TEXT NULL,
|
||||
author VARCHAR(64) NULL,
|
||||
video_url VARCHAR(512) NULL,
|
||||
CONSTRAINT fk_modification_firearm
|
||||
FOREIGN KEY (firearm_id)
|
||||
REFERENCES firearm (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE RESTRICT
|
||||
);
|
||||
|
||||
CREATE INDEX idx_modification_firearm_id ON modification (firearm_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user