"CREATE INDEX IF NOT EXISTS name (expression)" only checks whether an index of that name already exists. It does NOT compare whether the existing index has the same expression. This works as documented: https://www.postgresql.org/docs/current/sql-createindex.html#id-126.96.36.199.6
Module upgrading requires to drop indexes where the expression has changed.
RMB-550 simply drops all indexes on upgrades. Recreating all indexes takes a lot of time.
Be more smart: On each (non-SNAPSHOT) release save all CREATE INDEX statements in the database. We already have the rmb_internal table that currently stores rmb and module version: https://github.com/folio-org/raml-module-builder/blob/v29.2.2/domain-models-runtime/src/main/resources/templates/db_scripts/main.ftl#L15
During upgrade drop the existing index and create the index if no or a different index expression was saved.
Usecase 1: RMB changes how an entry in schema.json is converted into an SQL expression, for example by wrapping the expression into left(..., 600).
Usecase 2: The module changes an entry in schema.json, for example from