task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
3 changed files with 138 additions and 10 deletions
Showing only changes of commit ed50cae208 - Show all commits

View File

@ -1,13 +1,35 @@
package se.su.dsv.scipro.checklist;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.system.DomainObject;
import se.su.dsv.scipro.system.User;
import jakarta.persistence.*;
import java.util.*;
@Entity
@Table(name = "checklist")
@Cacheable(true)
@ -17,6 +39,7 @@ public class Checklist extends DomainObject {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Basic
@Column(nullable = false)
private String name;
@ -28,15 +51,25 @@ public class Checklist extends DomainObject {
*/
@Deprecated
@ManyToOne(optional = false)
@JoinColumn(name = "project_id")
private Project project;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinTable(name = "checklist_checklist_question",
joinColumns = @JoinColumn(name = "checklist_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "checklist_question_id", referencedColumnName = "id"))
private List<ChecklistQuestion> questions = new ArrayList<>();
@ManyToMany
@JoinTable(name = "checklist_checklist_category",
joinColumns = @JoinColumn(name = "checklist_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "checklist_category_id", referencedColumnName = "id"))
private List<se.su.dsv.scipro.checklist.ChecklistCategory> categories = new ArrayList<>();
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "checklist_user_last_open_date", joinColumns = @JoinColumn(name = "checklist_id"))
@Column(name = "last_open_date")
@MapKeyColumn(name = "user_id")
private Map<User, Date> userLastOpenDate = new HashMap<>();
protected Checklist() {

View File

@ -1,13 +1,17 @@
/**
*
*/
package se.su.dsv.scipro.checklist;
import se.su.dsv.scipro.system.DomainObject;
import jakarta.persistence.*;
import java.util.Objects;
import jakarta.persistence.Cacheable;
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 se.su.dsv.scipro.system.DomainObject;
@Entity
@Table(name="checklist_category")
@Cacheable(true)
@ -16,7 +20,7 @@ public class ChecklistCategory extends DomainObject {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique=true)
@Column(name = "category_name", unique = true)
private String categoryName;
protected ChecklistCategory() {

View File

@ -1224,6 +1224,97 @@ alter table `user_profile_project_type`
* Step 7: checklist related tables
*/
-- table: checklist_checklist_question
alter table `checklist_checklist_question` drop foreign key `FKC77ED98C64F9D54`;
alter table `checklist_checklist_question` drop foreign key `FKC77ED981F327355`;
alter table `checklist_checklist_question` drop key `FKC77ED981F327355`;
alter table `checklist_checklist_question` drop key `FKC77ED98C64F9D54`;
alter table `checklist_checklist_question` drop key `UK_o5ndj9lydqv17attv7uf8wlr`;
alter table `checklist_checklist_question` drop key `questions_id`;
alter table `checklist_checklist_question` drop primary key;
alter table `checklist_checklist_question` rename column `questions_id` to `checklist_question_id`;
alter table `checklist_checklist_question` add primary key (checklist_id, checklist_question_id);
alter table `checklist_checklist_question` add constraint uk_ccq_checklist_question_id unique(checklist_question_id);
alter table `checklist_checklist_question`
add constraint fk_ccq_checklist_question_id
foreign key (checklist_question_id) references checklist_question (id)
on delete cascade on update cascade;
alter table `checklist_checklist_question`
add constraint fk_ccq_checklist_id
foreign key (checklist_id) references checklist (id)
on delete cascade on update cascade;
-- table: Checklist_userLastOpenDate
alter table `Checklist_userLastOpenDate` drop foreign key `FKF7E07AB26D025A9`;
alter table `Checklist_userLastOpenDate` drop foreign key `FKF7E07AB21F327355`;
alter table `Checklist_userLastOpenDate` drop key `FKF7E07AB26D025A9`;
alter table `Checklist_userLastOpenDate` drop key `FKF7E07AB21F327355`;
alter table `Checklist_userLastOpenDate` drop primary key;
rename table `Checklist_userLastOpenDate` to `checklist_user_last_open_date`;
alter table `checklist_user_last_open_date` rename column `CheckList_id` to `checklist_id`;
alter table `checklist_user_last_open_date` rename column `userLastOpenDate` to `last_open_date`;
alter table `checklist_user_last_open_date` rename column `userLastOpenDate_KEY` to `user_id`;
alter table `checklist_user_last_open_date` add primary key (checklist_id, user_id);
alter table `checklist_user_last_open_date`
add constraint fk_cu_lod_checklist_id
foreign key (checklist_id) references checklist(id)
on delete cascade on update cascade;
alter table `checklist_user_last_open_date`
add constraint fk_cu_lod_user_id
foreign key (user_id) references user(id)
on delete cascade on update cascade;
-- table: checklist_checklist_category
alter table `checklist_checklist_category` drop foreign key `FK54F86EB08725F1D`;
alter table `checklist_checklist_category` drop foreign key `FK54F86EB01F327355`;
alter table `checklist_checklist_category` drop key `FK54F86EB08725F1D`;
alter table `checklist_checklist_category` drop key `FK54F86EB01F327355`;
alter table `checklist_checklist_category` rename column `categories_id` to `checklist_category_id`;
alter table `checklist_checklist_category`
add constraint fk_cca_checklist_id
foreign key (checklist_id) references checklist (id)
on delete cascade on update cascade;
alter table `checklist_checklist_category`
add constraint fk_cca_checklist_category_id
foreign key (checklist_category_id) references checklist_category (id)
on delete cascade on update cascade;
-- table: checklist_category
alter table `checklist_category` drop key `categoryName`;
alter table `checklist_category` rename column `categoryName` to `category_name`;
alter table `checklist_category` add constraint uk_checklist_category_category_name unique(category_name);
-- table: checklist
alter table `checklist` drop foreign key `FK_checklist_project`;
alter table `checklist` drop key `I_checkList_activity`;
alter table `checklist`
add constraint fk_checklist_project_id
foreign key (project_id) references project (id)
on delete cascade on update cascade;