@Target(value=METHOD)
@Retention(value=RUNTIME)
public @interface Rollback
Apply method.
Rollback methods are optional but recommended for production systems to ensure safe change reversibility. They receive the same dependency injection as Apply methods.
Example usage:
@Change(id = "migrate-user-schema", order = "2024-11-16-001", author = "ops-team")
public class MigrateUserSchema {
@Apply
public void migrateSchema(MongoDatabase db) {
// Add new field and migrate data
db.getCollection("users").updateMany(
new Document(),
Updates.set("createdAt", new Date())
);
}
@Rollback
public void revertSchema(MongoDatabase db) {
// Remove the added field
db.getCollection("users").updateMany(
new Document(),
Updates.unset("createdAt")
);
}
}