Skip to content
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
5 changes: 5 additions & 0 deletions db/migration/V0081__Drop_createdAt_not_null_constraints.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE "User"
DROP CONSTRAINT "ck_user_createdAt_not_null";

ALTER TABLE "Session"
DROP CONSTRAINT "ck_session_createdAt_not_null";
18 changes: 18 additions & 0 deletions db/migration/V0082__Correct_renamed_question_596.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
DO $$
BEGIN
CASE current_database()
WHEN 'codebloom-prod' THEN
UPDATE
"Question"
SET
"questionTitle" = 'Classes With at Least 5 Students',
"questionSlug" = 'classes-with-at-least-5-students',
"questionLink" = 'https://leetcode.com/problems/classes-with-at-least-5-students'
WHERE
id = '7ea283ec-2e03-4753-b8f8-406b3a68cbe1'
AND "questionNumber" = 596
AND "questionSlug" = 'classes-more-than-5-students';
ELSE
RAISE NOTICE 'Skipping prod only migration: Current database is %', current_database();
END CASE;
END $$;
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ void attachTagsToExistingQuestions() {
}

for (var question : questions) {
log.info("Updating question with id of {}", question.getId());
log.info("Updating question with id of {} and slug {}", question.getId(), question.getQuestionSlug());
LeetcodeQuestion leetcodeQuestion;
try {
leetcodeQuestion = leetcodeClient.findQuestionBySlug(question.getQuestionSlug());
} catch (Exception e) {
log.error("LeetcodeClient threw an exception", e);
log.error(
"LeetcodeClient threw an exception for question id {} and slug {}",
question.getId(),
question.getQuestionSlug(),
e);
continue;
}

Expand All @@ -64,6 +68,11 @@ void attachTagsToExistingQuestions() {

questionTopicRepository.createQuestionTopic(newQuestionTopic);
}
log.info(
"Attached {} topics to question id {} and slug {}",
leetcodeQuestion.getTopics().size(),
question.getId(),
question.getQuestionSlug());
}

log.info("This task is complete.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,38 @@ function hello() {
.thenThrow(new RuntimeException("Expected!"));

attachTagsToExistingQuestion.attachTagsToExistingQuestions();
verifyNoInteractions(questionTopicRepository);
assertTrue(logWatcher.list.stream()
.anyMatch(log -> log.getLevel().equals(Level.ERROR)
&& log.getFormattedMessage().contains("LeetcodeClient threw an exception")));
&& log.getFormattedMessage().contains("LeetcodeClient threw an exception")
&& log.getFormattedMessage().contains(mockQuestion.getId())
&& log.getFormattedMessage().contains(mockQuestion.getQuestionSlug())));
}

@Test
void correctedSlugAttachesTopicsAndContinuesPastFailedQuestion() {
var failed = Question.builder().id("failed").questionSlug("old-slug").build();
var corrected = Question.builder()
.id("corrected")
.questionSlug("classes-with-at-least-5-students")
.build();
when(questionRepository.getAllQuestionsWithNoTopics()).thenReturn(List.of(failed, corrected));
when(leetcodeClient.findQuestionBySlug("old-slug")).thenThrow(new RuntimeException("Missing"));
when(leetcodeClient.findQuestionBySlug(corrected.getQuestionSlug()))
.thenReturn(org.patinanetwork.codebloom.common.leetcode.models.LeetcodeQuestion.builder()
.topics(List.of(org.patinanetwork.codebloom.common.leetcode.models.LeetcodeTopicTag.builder()
.name("Database")
.slug("database")
.build()))
.build());

attachTagsToExistingQuestion.attachTagsToExistingQuestions();

verify(questionTopicRepository)
.createQuestionTopic(
argThat(topic -> topic.getQuestionId().orElseThrow().equals("corrected")
&& topic.getTopicSlug().equals("database")));
assertTrue(logWatcher.list.stream().anyMatch(log -> log.getFormattedMessage()
.contains("Attached 1 topics to question id corrected and slug classes-with-at-least-5-students")));
}
}
Loading