[AB-103] adding triggers to update created and updating attributes on tables

fixing error handling in installer
merging change sets to larger operations
adding check constraints
fixing suggestion id handling
applying naming conventions to various columns
adding indices to tables
adding user in server and user locking
This commit is contained in:
Sheldan
2021-02-07 03:06:48 +01:00
parent dac3b0887f
commit 038d5c3832
126 changed files with 1416 additions and 986 deletions

View File

@@ -6,6 +6,7 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
/**
* A role for which the experience gain in a particular server has been disabled.
@@ -14,21 +15,28 @@ import java.io.Serializable;
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "disabled_experience_roles")
@Table(name = "disabled_experience_role")
@Getter
@Setter
@EqualsAndHashCode
@Cacheable
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ADisabledExpRole implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@PrimaryKeyJoinColumn
private ARole role;
/**
* Reference to the actual {@link ARole} being marked as disabled for experience gain.
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id", nullable = false)
private ARole role;
@Column(name = "created")
private Instant created;
@Column(name = "updated")
private Instant updated;
}

View File

@@ -25,26 +25,18 @@ public class AExperienceLevel implements Serializable {
* The unique level from 0 to as defined in the configuration. Will be created on startup.
*/
@Id
@Column(name = "level")
private Integer level;
/**
* The total amount of experience needed for this level.
*/
@Column(name = "experience_needed")
private Long experienceNeeded;
@Column(name = "created")
private Instant created;
@PrePersist
private void onInsert() {
this.created = Instant.now();
}
@Column(name = "updated")
private Instant updated;
@PreUpdate
private void onUpdate() {
this.updated = Instant.now();
}
}

View File

@@ -31,9 +31,13 @@ public class AExperienceRole implements Serializable {
* The abstracto unique id of this experience role.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@PrimaryKeyJoinColumn
private ARole role;
/**
* Reference to the {@link AExperienceLevel} at which this role is awarded.
*/
@@ -50,29 +54,12 @@ public class AExperienceRole implements Serializable {
@JoinColumn(name = "server_id", nullable = false)
private AServer roleServer;
/**
* Reference to the actual {@link ARole} being awarded.
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id", nullable = false)
private ARole role;
@Column(name = "created")
private Instant created;
@PrePersist
private void onInsert() {
this.created = Instant.now();
}
@Column(name = "updated")
private Instant updated;
@PreUpdate
private void onUpdate() {
this.updated = Instant.now();
}
/**
* Current list of {@link dev.sheldan.abstracto.core.models.database.AUserInAServer} which were given this role.
*/

View File

@@ -29,6 +29,7 @@ public class AUserExperience implements Serializable {
* The {@link AUserInAServer} id which is unique for each user in a server.
*/
@Id
@Column(name = "id")
private Long id;
@OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@@ -38,16 +39,19 @@ public class AUserExperience implements Serializable {
/**
* The total amount of experience the user has in the guild
*/
@Column(name = "experience")
private Long experience;
/**
* The total amount of messages the user has written in the guild resulting in the experience.
*/
@Column(name = "message_count")
private Long messageCount;
/**
* Whether or not the experience gain has been disabled for this user
*/
@Column(name = "experience_gain_disabled")
private Boolean experienceGainDisabled;
/**
@@ -61,25 +65,15 @@ public class AUserExperience implements Serializable {
* The {@link AExperienceRole} the user currently has. Can be null.
*/
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "experience_role_id")
@JoinColumn(name = "role_id")
private AExperienceRole currentExperienceRole;
@Column(name = "created")
private Instant created;
@PrePersist
private void onInsert() {
this.created = Instant.now();
}
@Column(name = "updated")
private Instant updated;
@PreUpdate
private void onUpdate() {
this.updated = Instant.now();
}
public Integer getLevelOrDefault() {
return currentLevel != null ? currentLevel.getLevel() : 0;
}