Skip to content

Import fails when multiple applications share the same mongockChangeLog collection #907

@Celmas

Description

@Celmas

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

  1. Set up two Spring Boot applications (app1 and app2) sharing the same MongoDB database and using the same mongockChangeLog collection.
  2. Run both applications with Mongock so that both write audit entries to the shared collection.
  3. Migrate app1 to Flamingock with @MongockSupport.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions