Skip to content

Conversation

@DanielSchiavo
Copy link

@DanielSchiavo DanielSchiavo commented May 29, 2025

Issue reference

https://github.com/mongock/mongock/issues/704

Documentation PR reference

There are 2 commits
flamingock/mongock-docs#44

Description and context

This feature introduces multi-module support to Mongock, enabling modular projects to define and register their own migration packages independently.

Traditionally, Mongock required all migration packages to be configured centrally during builder setup. This approach can be limiting in large modular applications where each module should be able to manage its own database changes.

With this contribution:

Spring Boot modules can now annotate their configuration classes using @MongockScanPackage, and with this annotation, the package will be automatically added to the migration scan package.

For standalone applications, each module can implement a new MongockModuleConfig interface to programmatically register its own migration packages via builder.

This change improves decoupling, scalability, and maintainability in complex systems, especially microservices or monolithic applications split by modules.

Benefits

✅ Decentralized configuration of migration packages.

✅ Enables each module to independently define its migrations.

✅ Improves modularity and separation of concerns.

✅ Enhances flexibility for both Spring and Standalone runners.

✅ Maintains backward compatibility for centralized configuration.

✅ Provides a clean pattern for module-level migrations, both with annotations and builder-style setup.

Possible Drawbacks

I can't think of any

Checklist

@DanielSchiavo DanielSchiavo requested a review from dieppa as a code owner May 29, 2025 05:37
@DanielSchiavo
Copy link
Author

I can't provide a example project in example projects until you guys merge the code

@DanielSchiavo
Copy link
Author

Waiting for your feedback

@DanielSchiavo
Copy link
Author

There is another feature that needs to be released for this to work well

Copy link
Member

@dieppa dieppa left a comment

Choose a reason for hiding this comment

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

Hi @DanielSchiavo,

First of all, apologies for the delay in getting back to you — we’ve been working hard on our upcoming release, which will introduce many new features and mark a significant step forward in Mongock’s evolution.

Regarding your PR, thank you very much for the contribution — we really appreciate your effort. We believe this is a valuable improvement and are happy to move forward with merging it. That said, we have a few suggestions that might simplify the design and increase flexibility moving forward.

Although the current approach works, it might be more complex than necessary. What do you think about merging the concepts of Config and ScanPackage, and generalizing it to support additional properties in the future?

Here’s our proposed approach:

  • Standalone runner
    Introduce a MongockModuleConfig interface with a method that returns a list of packages. The builder could then accept multiple MongockModuleConfig instances, offering a clean and extensible solution.

  • Spring Boot integration
    Instead of using a custom annotation, it may be more user-friendly and consistent with the standalone approach to allow users to register any number of MongockModuleConfig beans. If I’m not mistaken (please confirm), Spring can inject a list of beans of the same type — we could leverage that to collect all registered configs into the builder.

Please let us know what you think. Once we agree on the best approach, I’m happy to assist with the final review and get this merged.

Thanks again!

@DanielSchiavo
Copy link
Author

I'm glad you liked it @dieppa .

We can do it this way, I think it's a wise choice.

Removed files and code previously featured in mongock standalone

Added new role in core runner builder, named ModuleConfigurationProvider

Modified RunnerBuilder to incorporate ModuleConfigurationProvider

Added new attribute in MongockConfiguration named mongockModules, and respective getter and setter
@dieppa
Copy link
Member

dieppa commented Jul 23, 2025

Hello @DanielSchiavo, I am confused this is ready to review or you haven't got the change to update it as we discuss it? Let us know and we review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.