Skip to content

Mongock Change Units/Logs allows duplicate and empty order strings #680

@TheSteinn

Description

@TheSteinn

Description

Something that is perhaps a bug, but definitely isn't documented, is that Mongock does not throw an exception if two of more change units/logs share the same order string value. I would have expected it to throw an exception similar to Flyway, given the similar use of version/order numbers.

Looking at the code in ChangeLogComparator.java, it looks like if the order string is equal, it uses the change unit/log class's canonical name.

I can't think of a use case for allowing duplicate order strings, but recognise it would be a breaking change to start throwing an exception in such cases. It's something to at least think about for a new version.

An alternative short-term approach could also be to log a (warning) message when change logs/units share duplicate order strings in order to warn a developer.

If this is an intended feature, it should be properly documented

In addition, an empty string for the order value appears to be allowed. This seems contradictory to the documentation, which states it is a mandatory parameter. The change unit ID is also a mandatory parameter, and has checks to ensure it is not null or empty in ChangeLogItem.java. However this is not done for the order parameter.

PRIORITY

Normal

Version and environment

Mongock

  • Mongock version: 5.4.0
  • Modules involved: mongock-springboot-v3, mongodb-springdata-v4-driver
  • How Mongock is used: annotation approach (via @EnableMongock and application.yml)

Environment

  • Framework and libraries versions. Especially those that affect directly to Mongock(Spring, Spring data, MongoDB driver, etc.): Spring Boot 3.2.3, spring-boot-starter-data-mongodb 3.2.3 (Spring Data MongoDB 4.2.3, MongoDB driver 4.11.1), spring-boot-starter-jdbc 3.2.3 (Spring JDBC 6.1.4)
  • Infrastructure: Kubernetes, Docker, SO, etc.: N/A

Steps to Reproduce

Duplicate order values:

  1. Create two migrations with duplicate order string value
  2. When the application starts up and migrations are run, both migrations are run, with order dependent on class name

Empty order values:

  1. Create a migration with an empty string order ""
  2. Start the application

Behaviour

Duplicate order values:
Expected behavior: An exception is throw (if this was not an intended feature)

Actual behavior: Mongock allows the duplicate order values

Empty order values:
Expected behavior: An exception is throw (if this was not an intended feature)

Actual behavior: Mongock allows the empty string order value

How often the bug happens: Always

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions