MCPcopy
hub / github.com/directus/directus / addColumnIndex

Method addColumnIndex

api/src/services/fields.ts:1022–1052  ·  view source on GitHub ↗
(
		collection: string,
		field: Field | RawField,
		options?: { attemptConcurrentIndex?: boolean; knex?: Knex; existing?: Column | null },
	)

Source from the content-addressed store, hash-verified

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}

Callers 4

createOneMethod · 0.95
createFieldMethod · 0.95
updateFieldMethod · 0.95
fields.test.tsFile · 0.80

Calls 2

getHelpersFunction · 0.50
createIndexMethod · 0.45

Tested by

no test coverage detected