Hybris: how to drop db index from inherited itemType

Imagine situation when you have already defined model with predefined db index. Like PriceRowModel:

<itemtype code="PriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field2"/>
      </index>
   </indexes>
</itemtype>

Your system is already on production and you have a lot of values inside this table. Then you need to extend the model and create new table, but with different index.

<itemtype code="NewPriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field3"/>
      </index>
   </indexes>
</itemtype>

Like you can see I’ve tried to redefine index unique_listprice. But the result was that old index was created in old version, and the new one was not created at all.

To workaround this situation we need to move unique_listprice to upper abstract class and set autocreate and generate flag to false. Our new working xml will look like this:

<itemtype code="PriceRow" autocreate="false" generate="false">
   (...)
   <!-- indexes element removed -->
</itemtype>
 
<itemtype code="CustomPriceRow" extends="PriceRow" autocreate="true" generate="true">
   (...)
   <indexes>
      <index name="unique_listprice" unique="true">
         <key attribute="field1"/>
         <key attribute="field2"/>
      </index>
   </indexes>
</itemtype>
 
<itemtype code="NewPriceRow" extends="PriceRow" autocreate="true" generate="true">
    (...)
    <indexes>
        <index name="unique_listprice" unique="true">
            <key attribute="field1"/>
            <key attribute="field3"/>
        </index>
    </indexes>
</itemtype>

You can see discussion around this topic in hybris experts community.