Skip to content

Commit 9aa49c8

Browse files
committed
fix index-creating ddl
Signed-off-by: yoseplee <yoseplee@linecorp.com>
1 parent bbd46fb commit 9aa49c8

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mongodb.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ db.getCollection("BATCH_SEQUENCES").insertOne({_id: "BATCH_JOB_EXECUTION_SEQ", c
1010
db.getCollection("BATCH_SEQUENCES").insertOne({_id: "BATCH_STEP_EXECUTION_SEQ", count: Long(0)});
1111

1212
// INDICES
13-
db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_name_idx", {"jobName": 1}, {});
14-
db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_name_key_idx", {"jobName": 1, "jobKey": 1}, {});
15-
db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_instance_idx", {"jobInstanceId": -1}, {});
16-
db.getCollection("BATCH_JOB_EXECUTION").createIndex("job_instance_idx", {"jobInstanceId": 1}, {});
17-
db.getCollection("BATCH_JOB_EXECUTION").createIndex("job_instance_idx", {"jobInstanceId": 1, "status": 1}, {});
18-
db.getCollection("BATCH_STEP_EXECUTION").createIndex("step_execution_idx", {"stepExecutionId": 1}, {});
13+
db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobName": 1}, {"name": "job_name_idx"});
14+
db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobName": 1, "jobKey": 1}, {"name": "job_name_key_idx"});
15+
db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobInstanceId": -1}, {"name": "job_instance_idx"});
16+
db.getCollection("BATCH_JOB_EXECUTION").createIndex( {"jobInstanceId": 1}, {"name": "job_instance_idx"});
17+
db.getCollection("BATCH_JOB_EXECUTION").createIndex( {"jobInstanceId": 1, "status": 1}, {"name": "job_instance_status_idx"});
18+
db.getCollection("BATCH_STEP_EXECUTION").createIndex( {"stepExecutionId": 1}, {"name": "step_execution_idx"});

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626
import org.springframework.test.annotation.DirtiesContext;
27+
import org.springframework.data.domain.Sort;
28+
import org.springframework.data.mongodb.core.index.Index;
2729
import org.springframework.test.context.DynamicPropertyRegistry;
2830
import org.springframework.test.context.DynamicPropertySource;
2931
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -68,6 +70,18 @@ public void setUp() {
6870
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
6971
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
7072
mongoTemplate.createCollection("BATCH_SEQUENCES");
73+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
74+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC).named("job_name_idx"));
75+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
76+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC).on("jobKey", Sort.Direction.ASC).named("job_name_key_idx"));
77+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
78+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.DESC).named("job_instance_idx"));
79+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
80+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).named("job_instance_idx"));
81+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
82+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).on("status", Sort.Direction.ASC).named("job_instance_status_idx"));
83+
mongoTemplate.indexOps("BATCH_STEP_EXECUTION")
84+
.ensureIndex(new Index().on("stepExecutionId", Sort.Direction.ASC).named("step_execution_idx"));
7185
mongoTemplate.getCollection("BATCH_SEQUENCES")
7286
.insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L)));
7387
mongoTemplate.getCollection("BATCH_SEQUENCES")

0 commit comments

Comments
 (0)