Important Consideration: Custom Index Support in Strapi

Can’t remember where I found this, but in the register cycle in for instance a Plugin, you can do something like this to add an index to a column in a contentType.

// create index column for content type
const prefix = contentType.split('::')[1].replace('.', '_');
const indexes = strapi.contentTypes[contentType].indexes || [];

// using postgres max length of index name is 64 characters so keep it short.
if (!indexes.some((i) => i.name === `${prefix}_dki`)) {
  strapi.contentTypes[contentType].indexes = [
    {
      name: `${prefix}_dki`,
      columns: ['your column name here'],
    },
  ];
}
1 Like