(
collection: string,
field: Field | RawField,
options?: { attemptConcurrentIndex?: boolean; knex?: Knex; existing?: Column | null },
)
| 1020 | } |
| 1021 | |
| 1022 | public async addColumnIndex( |
| 1023 | collection: string, |
| 1024 | field: Field | RawField, |
| 1025 | options?: { attemptConcurrentIndex?: boolean; knex?: Knex; existing?: Column | null }, |
| 1026 | ): Promise<void> { |
| 1027 | const attemptConcurrentIndex = Boolean(options?.attemptConcurrentIndex); |
| 1028 | const knex = options?.knex ?? this.knex; |
| 1029 | const existing = options?.existing ?? null; |
| 1030 | |
| 1031 | // Don't attempt to index a DB column for alias / corrupt fields |
| 1032 | if (field.type === 'alias' || field.type === 'unknown') return; |
| 1033 | |
| 1034 | // primary key will already have unique/index constraints |
| 1035 | if (field.schema?.is_primary_key || existing?.is_primary_key) return; |
| 1036 | |
| 1037 | const helpers = getHelpers(knex); |
| 1038 | |
| 1039 | if (field.schema?.is_unique === true && (!existing || existing.is_unique == false)) { |
| 1040 | await helpers.schema.createIndex(collection, field.field, { |
| 1041 | unique: true, |
| 1042 | attemptConcurrentIndex, |
| 1043 | }); |
| 1044 | } |
| 1045 | |
| 1046 | if (field.schema?.is_indexed === true && (!existing || existing.is_indexed === false)) { |
| 1047 | await helpers.schema.createIndex(collection, field.field, { |
| 1048 | unique: false, |
| 1049 | attemptConcurrentIndex, |
| 1050 | }); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
no test coverage detected