Skip to content

Commit a79b6f7

Browse files
yosepleefmbenhassine
authored andcommitted
Fix index creation statements in MongoDB DDL script
Signed-off-by: yoseplee <yoseplee@linecorp.com>
1 parent 9fbdf1e commit a79b6f7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

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

+6-6
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

+21
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;
@@ -64,16 +66,35 @@ static void setMongoDbConnectionString(DynamicPropertyRegistry registry) {
6466

6567
@BeforeEach
6668
public void setUp() {
69+
// collections
6770
mongoTemplate.createCollection("BATCH_JOB_INSTANCE");
6871
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
6972
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
73+
// sequences
7074
mongoTemplate.createCollection("BATCH_SEQUENCES");
7175
mongoTemplate.getCollection("BATCH_SEQUENCES")
7276
.insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L)));
7377
mongoTemplate.getCollection("BATCH_SEQUENCES")
7478
.insertOne(new Document(Map.of("_id", "BATCH_JOB_EXECUTION_SEQ", "count", 0L)));
7579
mongoTemplate.getCollection("BATCH_SEQUENCES")
7680
.insertOne(new Document(Map.of("_id", "BATCH_STEP_EXECUTION_SEQ", "count", 0L)));
81+
// indices
82+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
83+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC).named("job_name_idx"));
84+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
85+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC)
86+
.on("jobKey", Sort.Direction.ASC)
87+
.named("job_name_key_idx"));
88+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
89+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.DESC).named("job_instance_idx"));
90+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
91+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).named("job_instance_idx"));
92+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
93+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC)
94+
.on("status", Sort.Direction.ASC)
95+
.named("job_instance_status_idx"));
96+
mongoTemplate.indexOps("BATCH_STEP_EXECUTION")
97+
.ensureIndex(new Index().on("stepExecutionId", Sort.Direction.ASC).named("step_execution_idx"));
7798
}
7899

79100
@Test

0 commit comments

Comments
 (0)