def METHOD_NAME(self, **options):
    verbose = options['verbosity'] >= 2
    if verbose:
        global log_sql
        log_sql = log_sql_verbose
    for db in get_db_aliases_for_partitioned_query():
        if _index_exists(db, UNIQIE_INDEX_NAME):
            print(self.style.SUCCESS('Unique index already exists on db: {}'.format(db)))
            continue
        _add_temp_index(db)
        case_ids = _get_case_ids_with_dupe_indices(db)
        attempts = 0
        while case_ids and attempts < 3:
            attempts += 1
            print('{} cases found with duplicate indices. DB: {}, attempt: {}'.format(
                len(case_ids), db, attempts)
            )
            _delete_duplicate_indices(case_ids, db)
            case_ids = _get_case_ids_with_dupe_indices(db)
        if case_ids:
            print(self.style.ERROR(
                '{} cases still have duplicate '
                'indices after 3 attempts for db: {}'.format(len(case_ids), db))
            )
            grouped_indices = groupby(
                CommCareCaseIndex.objects.using(db)
                .filter(case_id__in=case_ids), key=lambda c: c.case_id
            )
            for case_id, indices in grouped_indices:
                print('--> Case: {}\n'.format(case_id))
                print('    {}'.format('\n    '.join(str(i) for i in indices)))
            print('\n')
        else:
            print(self.style.WARNING('Attempting to create unique index and constraint for db: {}'.format(db)))
            try:
                _add_unique_constraint_to_case_index_table(db)
            except Exception as e:
                print(self.style.ERROR('Failed to create unique constraint on DB {}: {}'.format(db, e)))
                print(self.style.WARNING('Temporary index left in place'))
            else:
                print(self.style.SUCCESS('Unique constraint added to db {}'.format(db)))
                _drop_index(db, IDENTIFIER_INDEX_NAME)