How to add index to custom module?

Hello, I am trying to add indexes to custom module. But they are not applied to the database while installing the package.
I tried to add indices to the file:
custom/modulebuilder/packages/MY PACKAGE/modules/MY MODULE/vardefs.php
but they are ignored
I also tried to add them to
custom/modulebuilder/builds/MY PACKAGE/SugarModules/modules/MY MODULE/vardefs.php
but they are automatically removed during the build

How should I add them?

It is possible to add them later using customisation:
custom/Extension/modules/MY MODULE/Ext/Vardefs/my_vardefs.php
and it works but I would like to have all integrated with my package…

You can do this in a post_install or post_execute command in your manifest.

You could first check if the index exists on the table with the get_indices function in include/database/DBManager.php (global $db; $db->get_indices). Also look at the addIndexes method. Unfortunately it takes an array of indexes for a table as the second parameter. I have an example here you can use as a start. This is for a two column index but you can modify as needed.

You could also just generate your own sql but this is how you’d do it the ‘standard’ way.

$indexDef1 = array(
        array(
            'name'   => 'idx_invoice_date_company_id',
            'type'   => 'index',
            'fields' => array('invoice_date_c', 'company_id_c'),
        ),