Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.appsmith.server.migrations.db.ce;

import com.appsmith.server.domains.User;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import io.mongock.api.annotations.RollbackExecution;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.index.Index;

import static com.appsmith.server.migrations.DatabaseChangelog1.dropIndexIfExists;
import static com.appsmith.server.migrations.DatabaseChangelog1.ensureIndexes;
import static org.springframework.data.domain.Sort.Direction.ASC;

@Slf4j
@ChangeUnit(order = "067", id = "update-user-email-index")
public class Migration067_UpdateUserEmailIndex {

@RollbackExecution
public void rollbackExecution() {}
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Empty rollback method needs implementation.

The rollback method is currently empty. Implement a proper rollback strategy that would restore the original email index if the migration needs to be reversed.

@RollbackExecution
public void rollbackExecution() {}
+public void rollbackExecution(MongoTemplate mongoTemplate) {
+    log.info("Rolling back migration for user email index");
+    try {
+        // Drop the compound index
+        dropIndexIfExists(mongoTemplate, User.class, "email_organizationId_compound_index");
+        
+        // Recreate the original email index
+        Index emailIndex = new Index()
+                .on("email", ASC)
+                .unique()
+                .named("email");
+                
+        ensureIndexes(mongoTemplate, User.class, emailIndex);
+        
+        log.info("Completed rollback of user email index migration");
+    } catch (Exception e) {
+        log.error("Error rolling back user email index migration", e);
+        throw e;
+    }
+}

Committable suggestion skipped: line range outside the PR's diff.


@Execution
public void execute(MongoTemplate mongoTemplate) {
log.info("Starting migration to update user email index");
try {
// Drop the existing email index
dropIndexIfExists(mongoTemplate, User.class, "email");

// Create new compound index on email and organizationId
Index emailOrgIndex = new Index()
.on("email", ASC)
.on("organizationId", ASC)
.unique()
.named("email_organizationId_compound_index");

ensureIndexes(mongoTemplate, User.class, emailOrgIndex);

log.info("Completed migration to update user email index");
} catch (Exception e) {
log.error("Error updating user email index", e);
throw e;
}
}
}
Loading