fix(drizzle): enforce uniqueness on index names (#8754)

Fixes https://github.com/payloadcms/payload/issues/8752

Previously, trying to define a config like this:
```ts
{
  type: 'text',
  name: 'someText',
  index: true,
},
{
  type: 'array',
  name: 'some',
  index: true,
  fields: [
    {
      type: 'text',
      name: 'text',
      index: true,
    },
  ],
}
```

Lead to the error:
```
Warning  We've found duplicated index name across public schema. Please rename your index in either the demonstration table or the table with the duplicated index name
```

Now, if we encounter duplicates, we increment the name like this:
`collection_some_text_idx`
`collection_some_text_1_idx`

---------

Co-authored-by: Dan Ribbens <dan.ribbens@gmail.com>
This commit is contained in:
Sasha
2024-10-17 05:05:27 +03:00
committed by GitHub
parent 872b205acc
commit 90bca15f52
14 changed files with 102 additions and 31 deletions

View File

@@ -1062,6 +1062,13 @@ export interface IndexedField {
};
collapsibleLocalizedUnique?: string | null;
collapsibleTextUnique?: string | null;
someText?: string | null;
some?:
| {
text?: string | null;
id?: string | null;
}[]
| null;
updatedAt: string;
createdAt: string;
}