fix: initialize teaching class score weight schema
parent
5c9170887f
commit
57267bb9d6
@ -0,0 +1,33 @@
|
||||
package com.sztzjy.linkCommerce.config;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* Keeps deployments compatible with databases created before class score
|
||||
* weights were introduced.
|
||||
*/
|
||||
@Component
|
||||
public class TeachingClassScoreWeightSchemaInitializer {
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public TeachingClassScoreWeightSchemaInitializer(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS teaching_class_score_weight (" +
|
||||
"teaching_class_id varchar(64) NOT NULL," +
|
||||
"foundation_weight decimal(6,4) NOT NULL DEFAULT 0.1000," +
|
||||
"market_insight_weight decimal(6,4) NOT NULL DEFAULT 0.3000," +
|
||||
"planning_design_weight decimal(6,4) NOT NULL DEFAULT 0.1000," +
|
||||
"development_validation_weight decimal(6,4) NOT NULL DEFAULT 0.1000," +
|
||||
"launch_operation_weight decimal(6,4) NOT NULL DEFAULT 0.2000," +
|
||||
"comprehensive_training_weight decimal(6,4) NOT NULL DEFAULT 0.2000," +
|
||||
"PRIMARY KEY (teaching_class_id)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.sztzjy.linkCommerce.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
class TeachingClassScoreWeightSchemaInitializerTest {
|
||||
|
||||
@Test
|
||||
void createsMissingScoreWeightTableWithEveryWeightColumn() {
|
||||
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
TeachingClassScoreWeightSchemaInitializer initializer =
|
||||
new TeachingClassScoreWeightSchemaInitializer(jdbcTemplate);
|
||||
|
||||
initializer.initialize();
|
||||
|
||||
ArgumentCaptor<String> statement = ArgumentCaptor.forClass(String.class);
|
||||
verify(jdbcTemplate).execute(statement.capture());
|
||||
String ddl = statement.getValue();
|
||||
assertTrue(ddl.startsWith("CREATE TABLE IF NOT EXISTS teaching_class_score_weight"));
|
||||
assertTrue(ddl.contains("teaching_class_id varchar(64) NOT NULL"));
|
||||
assertTrue(ddl.contains("foundation_weight decimal(6,4) NOT NULL DEFAULT 0.1000"));
|
||||
assertTrue(ddl.contains("market_insight_weight decimal(6,4) NOT NULL DEFAULT 0.3000"));
|
||||
assertTrue(ddl.contains("planning_design_weight decimal(6,4) NOT NULL DEFAULT 0.1000"));
|
||||
assertTrue(ddl.contains("development_validation_weight decimal(6,4) NOT NULL DEFAULT 0.1000"));
|
||||
assertTrue(ddl.contains("launch_operation_weight decimal(6,4) NOT NULL DEFAULT 0.2000"));
|
||||
assertTrue(ddl.contains("comprehensive_training_weight decimal(6,4) NOT NULL DEFAULT 0.2000"));
|
||||
assertTrue(ddl.contains("PRIMARY KEY (teaching_class_id)"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue