buildAutoGeneratedUniqueIndexName static method

String buildAutoGeneratedUniqueIndexName(
  1. String tableName,
  2. List<String> indexColumnNames
)

Builds the auto-generated unique index name, keeping it within the PostgreSQL identifier limit.

Composite indexes can easily exceed the limit, so when the full <table>__<col>__…__unique_idx name is too long the middle is replaced with a deterministic digest while the readable head and the __unique_idx suffix are preserved.

Implementation

static String buildAutoGeneratedUniqueIndexName(
  String tableName,
  List<String> indexColumnNames,
) {
  const suffix = '__unique_idx';
  var baseName = '${tableName}__${indexColumnNames.join('__')}';

  return truncateIdentifier(
        baseName,
        DatabaseConstants.pgsqlMaxNameLimitation - suffix.length,
        hashLength: 10,
      ) +
      suffix;
}