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 all 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
4 changes: 2 additions & 2 deletions docs/schema-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Here is a brief description of the activities defined for Liquibase
3. diffMain: Specify the reference and the target database to generate changelog that contains operations to update reference database to the state of the target database. i.e the reference is the JSON file generated by the snapshot command, this can be replaced with a live database which is used as reference.

## Generating/ Updating liquibase change logs
1. Ensure `diff-main` activity in `build.gradle` is pointing to the latest release changelog `src/main/resources/db/changelog/db.changelog-<release_number>.xml`
1. Ensure `diffMain` activity in `build.gradle` is pointing to the latest release changelog `src/main/resources/db/changelog/db.changelog-<release_number>.xml`
2. Delete the `postgres-data` folder to clear any old database schemas
3. Run `git checkout <reference_branch>` and
3. Run `git checkout <reference_branch>`
4. Run the server using `./gradlew serverRun` to generate tables found on branch
5. Generate snapshot of database by running `./gradlew liquibaseSnapshot -PrunList=snapshot`, the snapshot will be output to `liquibase-snapshot.json`
6. Checkout your branch and repeat steps 2 and 4 to generate the tables found on your branch
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
Expand All @@ -23,7 +24,9 @@
* Represents a deadline extension entity.
*/
@Entity
@Table(name = "DeadlineExtensions")
@Table(name = "DeadlineExtensions", uniqueConstraints = {
@UniqueConstraint(name = "Unique deadline per session and user", columnNames = { "userId", "sessionId" }),
})
public class DeadlineExtension extends BaseEntity {
@Id
private UUID id;
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, columnDefinition = "TEXT")
private String description;

@Column(nullable = false)
Expand Down
8 changes: 7 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 All @@ -35,6 +38,9 @@ public class Section extends BaseEntity {
@JoinColumn(name = "courseId")
private Course course;

@Column(nullable = false, insertable = false, updatable = false)
private String courseId;

@Column(nullable = false)
private String name;

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, columnDefinition = "TEXT")
private String comments;

protected Student() {
Expand Down
Loading