fix: initialize training answer schema at startup

main
chenyuan 4 weeks ago
parent 57267bb9d6
commit b30e78ef7d

@ -18,6 +18,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@ -44,6 +45,11 @@ public class StudentTrainingAnswerServiceImpl implements StudentTrainingAnswerSe
private boolean studentTrainingAnswerTableChecked = false; private boolean studentTrainingAnswerTableChecked = false;
@PostConstruct
public void initializeSchema() {
ensureStudentTrainingAnswerTable();
}
@Override @Override
public StudentTrainingAnswer get(String taskKey, String teachingClassId, JwtUser user) { public StudentTrainingAnswer get(String taskKey, String teachingClassId, JwtUser user) {
ensureStudentTrainingAnswerTable(); ensureStudentTrainingAnswerTable();

@ -152,6 +152,17 @@ class StudentTrainingAnswerServiceImplTest {
verify(service.jdbcTemplate).execute(startsWith("CREATE TABLE IF NOT EXISTS student_training_step_answer")); verify(service.jdbcTemplate).execute(startsWith("CREATE TABLE IF NOT EXISTS student_training_step_answer"));
} }
@Test
void startupInitializesDynamicStepAnswerColumnBeforeHomepageQueries() {
StudentTrainingAnswerServiceImpl service = buildService();
service.jdbcTemplate = mock(JdbcTemplate.class);
service.initializeSchema();
verify(service.jdbcTemplate).execute(startsWith(
"ALTER TABLE student_training_answer ADD COLUMN dynamic_step_answers"));
}
private StudentTrainingAnswerServiceImpl buildService() { private StudentTrainingAnswerServiceImpl buildService() {
StudentTrainingAnswerServiceImpl service = new StudentTrainingAnswerServiceImpl(); StudentTrainingAnswerServiceImpl service = new StudentTrainingAnswerServiceImpl();
service.studentTrainingAnswerMapper = mock(StudentTrainingAnswerMapper.class); service.studentTrainingAnswerMapper = mock(StudentTrainingAnswerMapper.class);

Loading…
Cancel
Save