Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12048] Add database unique constraints and length changes #13079

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testCreateFeedbackQuestion() throws InvalidParametersException, Enti
FeedbackTextQuestionDetails newQuestionDetails = new FeedbackTextQuestionDetails("New question text.");
List<FeedbackParticipantType> showTos = new ArrayList<>();
showTos.add(FeedbackParticipantType.INSTRUCTORS);
FeedbackQuestion newQuestion = FeedbackQuestion.makeQuestion(fs, 6, "This is a new text question",
FeedbackQuestion newQuestion = FeedbackQuestion.makeQuestion(fs, 12, "This is a new text question",
FeedbackParticipantType.STUDENTS, FeedbackParticipantType.OWN_TEAM_MEMBERS, -100,
showTos, showTos, showTos, newQuestionDetails);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ protected void testExecute() throws Exception {

______TS("null question type");

FeedbackQuestionCreateRequest createRequest = getTypicalTextQuestionCreateRequest();
FeedbackQuestionCreateRequest createRequest = getTypicalTextQuestionCreateRequest(10);
createRequest.setQuestionType(null);
verifyHttpRequestBodyFailure(createRequest, params);

______TS("Invalid questionNumber");

createRequest = getTypicalTextQuestionCreateRequest();
createRequest = getTypicalTextQuestionCreateRequest(10);
createRequest.setQuestionNumber(0);
verifyHttpRequestBodyFailure(createRequest, params);

______TS("Failure: Invalid giverType");

createRequest = getTypicalTextQuestionCreateRequest();
createRequest = getTypicalTextQuestionCreateRequest(10);
createRequest.setGiverType(FeedbackParticipantType.NONE);
verifyHttpRequestBodyFailure(createRequest, params);

______TS("Failure: empty question brief");

createRequest = getTypicalTextQuestionCreateRequest();
createRequest = getTypicalTextQuestionCreateRequest(10);
createRequest.setQuestionBrief("");
verifyHttpRequestBodyFailure(createRequest, params);

______TS("Typical case");

createRequest = getTypicalTextQuestionCreateRequest();
createRequest = getTypicalTextQuestionCreateRequest(10);
CreateFeedbackQuestionAction a = getAction(createRequest, params);
JsonResult r = getJsonResult(a);

Expand All @@ -103,7 +103,7 @@ protected void testExecute() throws Exception {

______TS("Custom number of entity to give feedback to");

createRequest = getTypicalTextQuestionCreateRequest();
createRequest = getTypicalTextQuestionCreateRequest(11);
createRequest.setNumberOfEntitiesToGiveFeedbackToSetting(NumberOfEntitiesToGiveFeedbackToSetting.CUSTOM);
createRequest.setCustomNumberOfEntitiesToGiveFeedbackTo(100);
createRequest.setGiverType(FeedbackParticipantType.STUDENTS);
Expand Down Expand Up @@ -152,9 +152,9 @@ protected void testAccessControl() throws Exception {
fs.getCourse(), Const.InstructorPermissions.CAN_MODIFY_SESSION, submissionParams);
}

private FeedbackQuestionCreateRequest getTypicalTextQuestionCreateRequest() {
private FeedbackQuestionCreateRequest getTypicalTextQuestionCreateRequest(int questionNumber) {
FeedbackQuestionCreateRequest createRequest = new FeedbackQuestionCreateRequest();
createRequest.setQuestionNumber(2);
createRequest.setQuestionNumber(questionNumber);
createRequest.setQuestionBrief("this is the brief");
createRequest.setQuestionDescription("this is the description");
FeedbackTextQuestionDetails textQuestionDetails = new FeedbackTextQuestionDetails();
Expand Down
2 changes: 1 addition & 1 deletion src/it/resources/data/FeedbackResponsesITBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@
"questionType": "TEXT"
},
"description": "Feedback question with no responses",
"questionNumber": 5,
"questionNumber": 6,
"giverType": "SELF",
"recipientType": "NONE",
"numOfEntitiesToGiveFeedbackTo": -100,
Expand Down
2 changes: 1 addition & 1 deletion src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@
"questionType": "TEXT"
},
"description": "Feedback question with no responses",
"questionNumber": 5,
"questionNumber": 6,
"giverType": "SELF",
"recipientType": "NONE",
"numOfEntitiesToGiveFeedbackTo": -100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

import org.hibernate.annotations.UpdateTimestamp;

Expand All @@ -39,7 +40,10 @@
* Represents a feedback question.
*/
@Entity
@Table(name = "FeedbackQuestions")
@Table(name = "FeedbackQuestions", uniqueConstraints = {
@UniqueConstraint(name = "Unique question number per session",
columnNames = { "questionNumber", "sessionId" }),
})
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class FeedbackQuestion extends BaseEntity implements Comparable<FeedbackQuestion> {
@Id
Expand All @@ -55,7 +59,7 @@ public abstract class FeedbackQuestion extends BaseEntity implements Comparable<
@Column(nullable = false)
private Integer questionNumber;

@Column(nullable = true)
@Column(nullable = true, length = 2000)
private String description;

@Column(nullable = false)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/teammates/storage/sqlentity/Section.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
Expand All @@ -26,7 +27,9 @@
* Represents a Section.
*/
@Entity
@Table(name = "Sections")
@Table(name = "Sections", uniqueConstraints = {
@UniqueConstraint(name = "Unique section name per course", columnNames = { "name", "courseId" }),
})
public class Section extends BaseEntity {
@Id
private UUID id;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/teammates/storage/sqlentity/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@Entity
@Table(name = "Students")
public class Student extends User {
@Column(nullable = false)
@Column(nullable = false, length = 2000)
private String comments;

protected Student() {
Expand Down
Loading