From 9aa49c83d78d8d641c79ef28c7471fd3d8ab1865 Mon Sep 17 00:00:00 2001 From: yoseplee Date: Wed, 5 Feb 2025 20:09:35 +0900 Subject: [PATCH] fix index-creating ddl Signed-off-by: yoseplee --- .../springframework/batch/core/schema-mongodb.js | 12 ++++++------ .../MongoDBJobRepositoryIntegrationTests.java | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mongodb.js b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mongodb.js index e3a971ad8a..eb10033e8c 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mongodb.js +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mongodb.js @@ -10,9 +10,9 @@ db.getCollection("BATCH_SEQUENCES").insertOne({_id: "BATCH_JOB_EXECUTION_SEQ", c db.getCollection("BATCH_SEQUENCES").insertOne({_id: "BATCH_STEP_EXECUTION_SEQ", count: Long(0)}); // INDICES -db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_name_idx", {"jobName": 1}, {}); -db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_name_key_idx", {"jobName": 1, "jobKey": 1}, {}); -db.getCollection("BATCH_JOB_INSTANCE").createIndex("job_instance_idx", {"jobInstanceId": -1}, {}); -db.getCollection("BATCH_JOB_EXECUTION").createIndex("job_instance_idx", {"jobInstanceId": 1}, {}); -db.getCollection("BATCH_JOB_EXECUTION").createIndex("job_instance_idx", {"jobInstanceId": 1, "status": 1}, {}); -db.getCollection("BATCH_STEP_EXECUTION").createIndex("step_execution_idx", {"stepExecutionId": 1}, {}); +db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobName": 1}, {"name": "job_name_idx"}); +db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobName": 1, "jobKey": 1}, {"name": "job_name_key_idx"}); +db.getCollection("BATCH_JOB_INSTANCE").createIndex( {"jobInstanceId": -1}, {"name": "job_instance_idx"}); +db.getCollection("BATCH_JOB_EXECUTION").createIndex( {"jobInstanceId": 1}, {"name": "job_instance_idx"}); +db.getCollection("BATCH_JOB_EXECUTION").createIndex( {"jobInstanceId": 1, "status": 1}, {"name": "job_instance_status_idx"}); +db.getCollection("BATCH_STEP_EXECUTION").createIndex( {"stepExecutionId": 1}, {"name": "step_execution_idx"}); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java index 6b70f0b3c7..7975019595 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MongoDBJobRepositoryIntegrationTests.java @@ -24,6 +24,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; +import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.index.Index; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -68,6 +70,18 @@ public void setUp() { mongoTemplate.createCollection("BATCH_JOB_EXECUTION"); mongoTemplate.createCollection("BATCH_STEP_EXECUTION"); mongoTemplate.createCollection("BATCH_SEQUENCES"); + mongoTemplate.indexOps("BATCH_JOB_INSTANCE") + .ensureIndex(new Index().on("jobName", Sort.Direction.ASC).named("job_name_idx")); + mongoTemplate.indexOps("BATCH_JOB_INSTANCE") + .ensureIndex(new Index().on("jobName", Sort.Direction.ASC).on("jobKey", Sort.Direction.ASC).named("job_name_key_idx")); + mongoTemplate.indexOps("BATCH_JOB_INSTANCE") + .ensureIndex(new Index().on("jobInstanceId", Sort.Direction.DESC).named("job_instance_idx")); + mongoTemplate.indexOps("BATCH_JOB_EXECUTION") + .ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).named("job_instance_idx")); + mongoTemplate.indexOps("BATCH_JOB_EXECUTION") + .ensureIndex(new Index().on("jobInstanceId", Sort.Direction.ASC).on("status", Sort.Direction.ASC).named("job_instance_status_idx")); + mongoTemplate.indexOps("BATCH_STEP_EXECUTION") + .ensureIndex(new Index().on("stepExecutionId", Sort.Direction.ASC).named("step_execution_idx")); mongoTemplate.getCollection("BATCH_SEQUENCES") .insertOne(new Document(Map.of("_id", "BATCH_JOB_INSTANCE_SEQ", "count", 0L))); mongoTemplate.getCollection("BATCH_SEQUENCES")