Skip to content

Commit

Permalink
deploy: db migration mySQL -> H2
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO committed Nov 17, 2024
1 parent 2110a7a commit 7135d79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.6.0'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'mysql:mysql-connector-java:8.0.33'
implementation 'com.h2database:h2'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ public class DailyQuestionService {
private final DailyQuestionRepository dailyQuestionRepository;
private final DailyResponseRepository dailyResponseRepository;

// @PostConstruct
// public void loadQuestionsFromFile() {
// try (InputStream inputStream = getClass().getResourceAsStream("/dailyQuestions.txt");
// BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(inputStream)))) {
//
// String line;
// while ((line = reader.readLine()) != null) {
// String finalLine = line;
// if (dailyQuestionRepository.findAll().stream().noneMatch(q -> q.getQuestion().equals(finalLine.trim()))) {
// DailyQuestion question = new DailyQuestion(line.trim());
// dailyQuestionRepository.save(question);
// }
// }
// } catch (IOException e) {
// logger.error("Failed to load questions from file", e);
// }
// }
@PostConstruct
public void loadQuestionsFromFile() {
try (InputStream inputStream = getClass().getResourceAsStream("/dailyQuestions.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull(inputStream)))) {

String line;
while ((line = reader.readLine()) != null) {
String finalLine = line;
if (dailyQuestionRepository.findAll().stream().noneMatch(q -> q.getQuestion().equals(finalLine.trim()))) {
DailyQuestion question = new DailyQuestion(line.trim());
dailyQuestionRepository.save(question);
}
}
} catch (IOException e) {
logger.error("Failed to load questions from file", e);
}
}

@Transactional
public void addDailyQuestion(DailyQuestionRequest dailyQuestionRequest) {
Expand Down

0 comments on commit 7135d79

Please sign in to comment.