docs: def create_current_version_unique_indexes(app_name, database=None):
      """
      Add unique indexes for models which have a VERSION_UNIQUE attribute.
      These must be defined as partially unique indexes, which django
      does not support.
      The unique indexes are defined so that no two *current* versions can have
      the same value.
      This will only try to create indexes if they do not exist in the database,
      so it should be safe to run in a post_migrate signal handler.  Running it
      several times should leave the database in the same state as running it
      once.
  
      :param str app_name: application name whose Versionable models will be
          acted on.
      :param str database: database alias to use.  If None, use default
          connection.
      :return: number of partial unique indexes created
      :rtype: int
      """
  
      indexes_created = 0
      connection = database_connection(database)
      with connection.cursor() as cursor:
          for model in versionable_models(app_name):
              unique_field_groups = getattr(model, 'VERSION_UNIQUE', None)
              if not unique_field_groups:
                  continue
  
              table_name = model._meta.db_table
              for group in unique_field_groups:
                  col_prefixes = []
                  columns = []
                  for field in group:
                      column = model._meta.get_field(field).column
                      col_prefixes.append(column[0:3])
                      columns.append(column)
                  index_name = '%s_%s_%s_v_uniq' % (
                      app_name, table_name, '_'.join(col_prefixes))
                  if not index_exists(cursor, index_name):
                      cursor.execute(
                          "CREATE UNIQUE INDEX %s ON %s(%s) "
                          "WHERE version_end_date IS NULL"
                          % (index_name, table_name, ','.join(columns)))
                      indexes_created += 1
  
      return indexes_created