Import fails when multiple applications share the same mongockChangeLog collection
Description
When migrating from Mongock to Flamingock, the application fails at startup with the following error if multiple applications historically shared the same mongockChangeLog audit collection:
OperationException: importing change with id[<changeId>] from database. It must be imported to a flamingock stage
This happens because Flamingock's MongockImporterMongoDB reads all documents from mongockChangeLog without filtering by the current application's classpath. When it encounters a changeLogClass that belongs to a different application (and therefore does not exist on the current classpath), it fails instead of skipping the unknown entry.
Environment
- Java 21
- Spring Boot 3.5.8
- Flamingock 1.2.1
- MongoDB (shared database across multiple microservices)
Steps to reproduce
- Set up two Spring Boot applications (
app1 and app2) sharing the same MongoDB database and using the same mongockChangeLog collection.
- Run both applications with Mongock so that both write audit entries to the shared collection.
- Migrate
app1 to Flamingock with @MongockSupport.
- Start
app1.
Expected behavior
Flamingock should skip audit entries whose changeLogClass is not found on the current application's classpath, logging a warning rather than throwing an exception. Only entries that belong to the current application should be imported.
Actual behavior
Flamingock throws an OperationException and the application fails to start:
OperationException: importing change with id[APP-5678] from database. It must be imported to a flamingock stage
Suggested fix
In MongockImporterMongoDB, when processing audit entries, catch ClassNotFoundException (or check classpath availability before processing) and skip entries whose class is not found on the current classpath with a WARN-level log message, for example:
WARN: Skipping Mongock audit entry [changeId=APP-5678, class=com.example.app2.changelog.OtherChange] — class not found on classpath. This entry likely belongs to a different application sharing the same audit collection.
This would make Flamingock resilient to the shared-collection pattern without requiring manual data migration.
Import fails when multiple applications share the same
mongockChangeLogcollectionDescription
When migrating from Mongock to Flamingock, the application fails at startup with the following error if multiple applications historically shared the same
mongockChangeLogaudit collection:This happens because Flamingock's
MongockImporterMongoDBreads all documents frommongockChangeLogwithout filtering by the current application's classpath. When it encounters achangeLogClassthat belongs to a different application (and therefore does not exist on the current classpath), it fails instead of skipping the unknown entry.Environment
Steps to reproduce
app1andapp2) sharing the same MongoDB database and using the samemongockChangeLogcollection.app1to Flamingock with@MongockSupport.app1.Expected behavior
Flamingock should skip audit entries whose
changeLogClassis not found on the current application's classpath, logging a warning rather than throwing an exception. Only entries that belong to the current application should be imported.Actual behavior
Flamingock throws an
OperationExceptionand the application fails to start:Suggested fix
In
MongockImporterMongoDB, when processing audit entries, catchClassNotFoundException(or check classpath availability before processing) and skip entries whose class is not found on the current classpath with aWARN-level log message, for example:This would make Flamingock resilient to the shared-collection pattern without requiring manual data migration.