task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
4 changed files with 459 additions and 259 deletions
Showing only changes of commit 60732cd0c3 - Show all commits

View File

@ -1,80 +1,115 @@
package se.su.dsv.scipro.peer;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import se.su.dsv.scipro.checklist.ChecklistAnswerEnum;
import se.su.dsv.scipro.system.DomainObject;
import jakarta.persistence.*;
import java.util.Objects;
@Entity
@Table(name="answer")
@Cacheable(true)
public class Answer extends DomainObject {
// ----------------------------------------------------------------------------------
// basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Basic(optional = false)
@Column(name = "question")
private String question;
@Enumerated(EnumType.STRING)
@Column(name = "answer", nullable=false)
private ChecklistAnswerEnum answer = ChecklistAnswerEnum.NO_ANSWER;
@Basic(optional=true)
@Lob
@Column(name = "motivation")
private String motivation;
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (answer) referencing other tables.
// ----------------------------------------------------------------------------------
@ManyToOne(optional=false)
@JoinColumn(name = "peer_review_id", referencedColumnName = "id")
private PeerReview peerReview;
@Basic(optional = false)
private String question;
@Lob
@Basic(optional=true)
private String motivation;
@Enumerated(EnumType.STRING)
@Column(nullable=false)
private ChecklistAnswerEnum answer = ChecklistAnswerEnum.NO_ANSWER;
// ----------------------------------------------------------------------------------
// constructors
// ----------------------------------------------------------------------------------
public Answer() {}
public Answer(PeerReview peerReview, String question){
this.peerReview = peerReview;
this.question = question;
}
// ----------------------------------------------------------------------------------
// getters and setters
// ----------------------------------------------------------------------------------
@Override
public Long getId() {
return this.id;
}
public PeerReview getPeerReview() {
return this.peerReview;
}
public String getQuestion() {
return this.question;
}
public String getMotivation() {
return this.motivation;
}
public ChecklistAnswerEnum getAnswer() {
return this.answer;
}
public void setId(Long id) {
this.id = id;
}
public void setPeerReview(PeerReview peerReview) {
this.peerReview = peerReview;
public String getQuestion() {
return this.question;
}
public void setQuestion(String question) {
this.question = question;
}
public void setMotivation(String motivation) {
this.motivation = motivation;
public ChecklistAnswerEnum getAnswer() {
return this.answer;
}
public void setAnswer(ChecklistAnswerEnum answer) {
this.answer = answer;
}
public String getMotivation() {
return this.motivation;
}
public void setMotivation(String motivation) {
this.motivation = motivation;
}
public PeerReview getPeerReview() {
return this.peerReview;
}
public void setPeerReview(PeerReview peerReview) {
this.peerReview = peerReview;
}
// ----------------------------------------------------------------------------------
// other methods
// ----------------------------------------------------------------------------------
protected boolean canEqual(final Object other) {
return other instanceof Answer;
}
@Override
public boolean equals(final Object o) {
if (o == this) return true;
@ -84,10 +119,6 @@ public class Answer extends DomainObject {
&& Objects.equals(this.getId(), other.getId());
}
protected boolean canEqual(final Object other) {
return other instanceof Answer;
}
@Override
public int hashCode() {
return Objects.hashCode(this.getId());
@ -95,6 +126,7 @@ public class Answer extends DomainObject {
@Override
public String toString() {
return "Answer(id=" + this.getId() + ", question=" + this.getQuestion() + ", motivation=" + this.getMotivation() + ", answer=" + this.getAnswer() + ")";
return "Answer(id=" + this.getId() + ", question=" + this.getQuestion() + ", motivation=" +
this.getMotivation() + ", answer=" + this.getAnswer() + ")";
}
}

View File

@ -1,7 +1,20 @@
package se.su.dsv.scipro.peer;
import com.querydsl.core.annotations.QueryInit;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import se.su.dsv.scipro.checklist.ChecklistTemplate;
import se.su.dsv.scipro.data.dataobjects.Member;
import se.su.dsv.scipro.file.FileReference;
@ -10,57 +23,138 @@ import se.su.dsv.scipro.system.DomainObject;
import se.su.dsv.scipro.system.Language;
import se.su.dsv.scipro.system.User;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "peer_request")
@Cacheable(true)
public class PeerRequest extends DomainObject {
// ----------------------------------------------------------------------------------
// basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Lob
@Basic(optional = true)
@Lob
@Column(name = "comment")
private String comment;
@ManyToOne(optional = false)
@QueryInit({"headSupervisor", "projectType"})
private Project project;
@ManyToOne(optional = false)
private User requester;
@ManyToOne(optional = false)
@JoinColumn(name = "file_reference_id")
private FileReference file;
@ManyToOne(optional = true)
private ChecklistTemplate checklistTemplate;
@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false)
private RequestStatus status = RequestStatus.WAITING;
@Enumerated(EnumType.STRING)
private Language language;
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (peer_request) referencing other tables.
// ----------------------------------------------------------------------------------
@ManyToOne(optional = true)
@JoinColumn(name = "checklist_template_id", referencedColumnName = "id")
private ChecklistTemplate checklistTemplate;
@ManyToOne(optional = false)
@JoinColumn(name = "file_reference_id", referencedColumnName = "id")
private FileReference file;
@ManyToOne(optional = false)
@JoinColumn(name = "project_id", referencedColumnName = "id")
@QueryInit({"headSupervisor", "projectType"})
private Project project;
@ManyToOne(optional = false)
@JoinColumn(name = "requester_user_id", referencedColumnName = "id")
private User requester;
// ----------------------------------------------------------------------------------
// JPA-mappings of other tables referencing to this table "peer_request"
// ----------------------------------------------------------------------------------
@OneToMany(mappedBy = "peerRequest")
private List<PeerReview> peerReviews = new ArrayList<>(1);
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private RequestStatus status = RequestStatus.WAITING;
// ----------------------------------------------------------------------------------
// getters and setters
// ----------------------------------------------------------------------------------
@Override
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public RequestStatus getStatus() {
return this.status;
}
public void setStatus(RequestStatus status) {
this.status = status;
}
public Language getLanguage() {
return this.language;
}
public void setLanguage(Language language) {
this.language = language;
}
public ChecklistTemplate getChecklistTemplate() {
return this.checklistTemplate;
}
public void setChecklistTemplate(ChecklistTemplate checklistTemplate) {
this.checklistTemplate = checklistTemplate;
}
public FileReference getFile() {
return this.file;
}
public void setFile(FileReference file) {
this.file = file;
}
public Project getProject() {
return this.project;
}
public void setProject(Project project) {
this.project = project;
}
public User getRequester() {
return this.requester;
}
public void setRequester(User requester) {
this.requester = requester;
}
public List<PeerReview> getPeerReviews() {
return this.peerReviews;
}
public void setPeerReviews(List<PeerReview> peerReviews) {
this.peerReviews = peerReviews;
}
// ----------------------------------------------------------------------------------
// other methods
// ----------------------------------------------------------------------------------
public List<Member> getMembers() {
List<Member> members = project.getMembers();
@ -80,77 +174,8 @@ public class PeerRequest extends DomainObject {
return null;
}
@Override
public Long getId() {
return this.id;
}
public String getComment() {
return this.comment;
}
public Project getProject() {
return this.project;
}
public User getRequester() {
return this.requester;
}
public FileReference getFile() {
return this.file;
}
public ChecklistTemplate getChecklistTemplate() {
return this.checklistTemplate;
}
public Language getLanguage() {
return this.language;
}
public List<PeerReview> getPeerReviews() {
return this.peerReviews;
}
public RequestStatus getStatus() {
return this.status;
}
public void setId(Long id) {
this.id = id;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setProject(Project project) {
this.project = project;
}
public void setRequester(User requester) {
this.requester = requester;
}
public void setFile(FileReference file) {
this.file = file;
}
public void setChecklistTemplate(ChecklistTemplate checklistTemplate) {
this.checklistTemplate = checklistTemplate;
}
public void setLanguage(Language language) {
this.language = language;
}
public void setPeerReviews(List<PeerReview> peerReviews) {
this.peerReviews = peerReviews;
}
public void setStatus(RequestStatus status) {
this.status = status;
protected boolean canEqual(final Object other) {
return other instanceof PeerRequest;
}
@Override
@ -162,10 +187,6 @@ public class PeerRequest extends DomainObject {
&& Objects.equals(this.getId(), other.getId());
}
protected boolean canEqual(final Object other) {
return other instanceof PeerRequest;
}
@Override
public int hashCode() {
return Objects.hashCode(this.getId());
@ -173,6 +194,9 @@ public class PeerRequest extends DomainObject {
@Override
public String toString() {
return "PeerRequest(id=" + this.getId() + ", comment=" + this.getComment() + ", project=" + this.getProject() + ", requester=" + this.getRequester() + ", file=" + this.getFile() + ", checklistTemplate=" + this.getChecklistTemplate() + ", language=" + this.getLanguage() + ", status=" + this.getStatus() + ")";
return "PeerRequest(id=" + this.getId() + ", comment=" + this.getComment() + ", project=" +
this.getProject() + ", requester=" + this.getRequester() + ", file=" + this.getFile() +
", checklistTemplate=" + this.getChecklistTemplate() + ", language=" + this.getLanguage() +
", status=" + this.getStatus() + ")";
}
}

View File

@ -1,6 +1,24 @@
package se.su.dsv.scipro.peer;
import com.querydsl.core.annotations.QueryInit;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import se.su.dsv.scipro.checklist.ChecklistAnswerEnum;
import se.su.dsv.scipro.data.dataobjects.Member;
import se.su.dsv.scipro.file.FileReference;
@ -8,7 +26,6 @@ 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.ArrayList;
import java.util.Date;
import java.util.List;
@ -23,41 +40,140 @@ public class PeerReview extends DomainObject implements Commentable {
public enum ReviewStatus {
IN_PROGRESS, COMPLETED, EXPIRED
}
// ----------------------------------------------------------------------------------
// basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Basic
@Lob
@Column(name = "comment")
private String comment;
@Enumerated(EnumType.STRING)
@Column(name = "status")
private ReviewStatus status = ReviewStatus.IN_PROGRESS;
@Basic(optional = false)
@Column(name = "deadline")
private Date deadline;
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (peer_review) referencing other tables.
// ----------------------------------------------------------------------------------
@OneToOne(optional=true, orphanRemoval = true, cascade = CascadeType.ALL)
@JoinColumn(name = "file_reference_id", referencedColumnName = "id")
private FileReference file;
@ManyToOne(optional=false)
@JoinColumn(name = "peer_request_id", referencedColumnName = "id")
@QueryInit({"project.headSupervisor", "requester.user", "language", "checklistTemplate"})
private PeerRequest peerRequest;
@ManyToOne(optional=false)
@JoinColumn(name = "project_id", referencedColumnName = "id")
@QueryInit({"headSupervisor", "projectType"})
private Project project;
@ManyToOne(optional=false)
@JoinColumn(name = "reviewer_user_id", referencedColumnName = "id")
@QueryInit("*.*")
private User reviewer;
@ManyToOne(optional=false)
@QueryInit({"headSupervisor", "projectType"})
private Project project;
@ManyToOne(optional=false)
@QueryInit({"project.headSupervisor","requester.user", "language", "checklistTemplate"})
private PeerRequest peerRequest;
// ----------------------------------------------------------------------------------
// JPA-mappings of other tables referencing to this table "peer_review"
// ----------------------------------------------------------------------------------
@OneToMany(mappedBy="peerReview", orphanRemoval=true, cascade=CascadeType.ALL)
@OrderBy("id")
private List<Answer> answers = new ArrayList<>();
@OneToOne(optional=true, orphanRemoval = true, cascade = CascadeType.ALL)
@JoinColumn(name = "file_reference_id")
private FileReference file;
@Lob
private String comment;
// ----------------------------------------------------------------------------------
// getters and setters
// ----------------------------------------------------------------------------------
@Override
public Long getId() {
return this.id;
}
@Enumerated(EnumType.STRING)
private ReviewStatus status = ReviewStatus.IN_PROGRESS;
public void setId(Long id) {
this.id = id;
}
@Basic(optional = false)
private Date deadline;
public String getComment() {
return this.comment;
}
@Override
public void setComment(String comment) {
this.comment = comment;
}
public ReviewStatus getStatus() {
return status;
}
public void setStatus(ReviewStatus status) {
this.status = status;
}
public Date getDeadline() {
return this.deadline;
}
public void setDeadline(Date deadline) {
this.deadline = deadline;
}
public FileReference getFile() {
return this.file;
}
public void setFile(FileReference file) {
this.file = file;
}
public PeerRequest getPeerRequest() {
return this.peerRequest;
}
public void setPeerRequest(PeerRequest peerRequest) {
this.peerRequest = peerRequest;
}
public Project getProject() {
return this.project;
}
public void setProject(Project project) {
this.project = project;
}
public User getReviewer() {
return this.reviewer;
}
public void setReviewer(User reviewer) {
this.reviewer = reviewer;
}
public List<Answer> getAnswers() {
return this.answers;
}
public void setAnswers(List<Answer> answers) {
this.answers = answers;
}
public void addAnswer(String question) {
this.answers.add(new Answer(this, question));
}
// ----------------------------------------------------------------------------------
// other methods
// ----------------------------------------------------------------------------------
@Override
public final String getCommentKey() {
return PeerReview.class.getCanonicalName();
}
@ -73,10 +189,6 @@ public class PeerReview extends DomainObject implements Commentable {
return new Date().after(getDeadline());
}
public ReviewStatus getStatus() {
return status;
}
public boolean isExpired() {
return status == ReviewStatus.EXPIRED;
}
@ -97,90 +209,12 @@ public class PeerReview extends DomainObject implements Commentable {
setStatus(isLate() ? ReviewStatus.EXPIRED : ReviewStatus.COMPLETED);
}
private static boolean isEmpty(String s) {
return s == null || s.isBlank();
}
public void expire() {
status = ReviewStatus.EXPIRED;
}
public void addAnswer(String question) {
this.answers.add(new Answer(this, question));
}
@Override
public Long getId() {
return this.id;
}
public User getReviewer() {
return this.reviewer;
}
public Project getProject() {
return this.project;
}
public PeerRequest getPeerRequest() {
return this.peerRequest;
}
public List<Answer> getAnswers() {
return this.answers;
}
public FileReference getFile() {
return this.file;
}
public String getComment() {
return this.comment;
}
public Date getDeadline() {
return this.deadline;
}
public void setId(Long id) {
this.id = id;
}
public void setReviewer(User reviewer) {
this.reviewer = reviewer;
}
public void setProject(Project project) {
this.project = project;
}
public void setPeerRequest(PeerRequest peerRequest) {
this.peerRequest = peerRequest;
}
public void setAnswers(List<Answer> answers) {
this.answers = answers;
}
public void setFile(FileReference file) {
this.file = file;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setStatus(ReviewStatus status) {
this.status = status;
}
public void setDeadline(Date deadline) {
this.deadline = deadline;
}
@Override
public String toString() {
return "PeerReview(id=" + this.getId() + ", reviewer=" + this.getReviewer() + ", project=" + this.getProject() + ", peerRequest=" + this.getPeerRequest() + ", answers=" + this.getAnswers() + ", file=" + this.getFile() + ", comment=" + this.getComment() + ", status=" + this.getStatus() + ", deadline=" + this.getDeadline() + ")";
protected boolean canEqual(final Object other) {
return other instanceof PeerReview;
}
@Override
@ -192,12 +226,23 @@ public class PeerReview extends DomainObject implements Commentable {
&& Objects.equals(this.getId(), other.getId());
}
protected boolean canEqual(final Object other) {
return other instanceof PeerReview;
@Override
public int hashCode() {
return Objects.hashCode(this.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(this.getId());
public String toString() {
return "PeerReview(id=" + this.getId() + ", reviewer=" + this.getReviewer() + ", project=" +
this.getProject() + ", peerRequest=" + this.getPeerRequest() + ", answers=" + this.getAnswers() +
", file=" + this.getFile() + ", comment=" + this.getComment() + ", status=" + this.getStatus() +
", deadline=" + this.getDeadline() + ")";
}
// ----------------------------------------------------------------------------------
// Static helper methods
// ----------------------------------------------------------------------------------
private static boolean isEmpty(String s) {
return s == null || s.isBlank();
}
}

View File

@ -1885,11 +1885,110 @@ alter table `activity_final_seminar`
on delete cascade on update cascade;
/*
* Step 12: XXX related tables
*
* Step 12: Peer Review related tables
*/
-- table: peer_request
alter table `peer_request` drop foreign key `FK_peer_request_checklist_template`;
alter table `peer_request` drop foreign key `FK_peer_request_file`;
alter table `peer_request` drop foreign key `FK_ppnisfed4ipbg17rts8vbuqt8`;
alter table `peer_request` drop foreign key `peer_request_reviewer_id`;
alter table `peer_request` drop key `FK_peer_request_file`;
alter table `peer_request` drop key `FK_ppnisfed4ipbg17rts8vbuqt8`;
alter table `peer_request` drop key `peer_request_reviewer_id`;
alter table `peer_request` drop key `FK514488B2869F0235`;
alter table `peer_request` drop key `FK514488B2C1813915`;
alter table `peer_request` change `version` `version` int(4) not null default 0 after `last_modified`;
alter table `peer_request` change `language` `language` varchar(255) not null after `status`;
alter table `peer_request` rename column `checkListTemplate_id` to `checklist_template_id`;
alter table `peer_request` rename column `requester_id` to `requester_user_id`;
alter table `peer_request` change `checklist_template_id` `checklist_template_id` bigint(20) default null after `language`;
alter table `peer_request` change `file_reference_id` `file_reference_id` bigint(20) not null after `checklist_template_id`;
alter table `peer_request`
add constraint fk_peer_request_checklist_template_id
foreign key (checklist_template_id) references checklist_template (id)
on delete cascade on update cascade;
alter table `peer_request`
add constraint fk_peer_request_file_reference_id
foreign key (file_reference_id) references file_reference (id)
on delete cascade on update cascade;
alter table `peer_request`
add constraint fk_peer_request_project_id
foreign key (project_id) references project (id)
on delete cascade on update cascade;
alter table `peer_request`
add constraint fk_peer_request_requester_user_id
foreign key (requester_user_id) references user (id)
on delete cascade on update cascade;
-- table: peer_review
alter table `peer_review` drop foreign key `peer_review_reviewer_id`;
alter table `peer_review` drop foreign key `FK_n5wj0qsev5cf8acm0xhfrqlpg`;
alter table `peer_review` drop foreign key `FK_9ke7armwg3tfnghmschgo011f`;
alter table `peer_review` drop foreign key `FK_peer_review_file`;
alter table `peer_review` drop key `peer_review_reviewer_id`;
alter table `peer_review` drop key `FK_n5wj0qsev5cf8acm0xhfrqlpg`;
alter table `peer_review` drop key `FKB00C90D5C1813915`;
alter table `peer_review` drop key `FK_9ke7armwg3tfnghmschgo011f`;
alter table `peer_review` drop key `FKB00C90D5CEE8709B`;
alter table `peer_review` drop key `FK_peer_review_file`;
alter table `peer_review` change `version` `version` int(4) not null default 0 after `last_modified`;
alter table `peer_review` change `status` `status` varchar(255) not null after `comment`;
alter table `peer_review` change `deadline` `deadline` datetime not null after `status`;
alter table `peer_review` change `file_reference_id` `file_reference_id` bigint(20) default null after `deadline`;
alter table `peer_review` change `peerRequest_id` `peer_request_id` bigint(20) not null;
alter table `peer_review` change `reviewer_id` `reviewer_user_id` bigint(20) not null;
alter table `peer_review`
add constraint fk_peer_review_file_reference_id
foreign key (file_reference_id) references file_reference (id)
on delete cascade on update cascade;
alter table `peer_review`
add constraint fk_peer_review_peer_request_id
foreign key (peer_request_id) references peer_request (id)
on delete cascade on update cascade;
alter table `peer_review`
add constraint fk_peer_review_project_id
foreign key (project_id) references project (id)
on delete cascade on update cascade;
alter table `peer_review`
add constraint fk_peer_review_reviewer_user_id
foreign key (reviewer_user_id) references user (id)
on delete cascade on update cascade;
-- table: answer
alter table `answer` drop foreign key `FK_64r70sbiishrkuj1vn87vo53k`;
alter table `answer` drop key `FK_64r70sbiishrkuj1vn87vo53k`;
alter table `answer` drop key `FKABCA3FBE2C41A959`;
alter table `answer` change `version` `version` int(4) not null default 0 after `last_modified`;
alter table `answer` change `question` `question` longtext not null after `version`;
alter table `answer` change `answer` `answer` varchar(255) not null after `question`;
alter table `answer` rename column `peerReview_id` to `peer_review_id`;
alter table `answer`
add constraint fk_answer_peer_review_id
foreign key (peer_review_id) references peer_review (id)
on delete cascade on update cascade;
@ -1939,7 +2038,7 @@ order by table_name;
select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name
from information_schema.key_column_usage
where table_schema = 'tozh4728' and table_name = 'ActivityTemplate' and constraint_name != 'PRIMARY';
where table_schema = 'tozh4728' and table_name = 'peer_request' and constraint_name != 'PRIMARY';
select table_name, column_name, constraint_name, referenced_table_name, referenced_column_name
from information_schema.key_column_usage