Skip to content

Commit de1d271

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

File tree

2 files changed

+21
-6
lines changed

2 files changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import java.util.Map;
2020

2121
import com.mongodb.client.MongoCollection;
22+
import com.mongodb.client.model.IndexOptions;
2223
import org.bson.Document;
2324
import org.junit.jupiter.api.Assertions;
2425
import org.junit.jupiter.api.BeforeEach;
2526
import org.junit.jupiter.api.Test;
27+
import org.springframework.data.domain.Sort;
28+
import org.springframework.data.mongodb.core.index.Index;
2629
import org.springframework.test.context.DynamicPropertyRegistry;
2730
import org.springframework.test.context.DynamicPropertySource;
2831
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -66,6 +69,18 @@ public void setUp() {
6669
mongoTemplate.createCollection("BATCH_JOB_EXECUTION");
6770
mongoTemplate.createCollection("BATCH_STEP_EXECUTION");
6871
mongoTemplate.createCollection("BATCH_SEQUENCES");
72+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
73+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC).named("job_name_idx"));
74+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
75+
.ensureIndex(new Index().on("jobName", Sort.Direction.ASC).on("jobKey", Sort.Direction.ASC).named("job_name_key_idx"));
76+
mongoTemplate.indexOps("BATCH_JOB_INSTANCE")
77+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.DESC).named("job_instance_idx"));
78+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
79+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).named("job_instance_idx"));
80+
mongoTemplate.indexOps("BATCH_JOB_EXECUTION")
81+
.ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).on("status", Sort.Direction.ASC).named("job_instance_status_idx"));
82+
mongoTemplate.indexOps("BATCH_STEP_EXECUTION")
83+
.ensureIndex(new Index().on("stepExecutionId", Sort.Direction.ASC).named("step_execution_idx"));
6984
mongoTemplate.getCollection("BATCH_SEQUENCES")
7085
.insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L)));
7186
mongoTemplate.getCollection("BATCH_SEQUENCES")

0 commit comments

Comments
 (0)