@@ -223,7 +223,7 @@ class MySQLRecordManager implements RecordManagerInterface {
223223 `SELECT COUNT(1) ColumnExists FROM INFORMATION_SCHEMA.COLUMNS
224224 WHERE table_schema=DATABASE() AND table_name='${ tableName } ' AND column_name='doc_id';`
225225 )
226- if ( checkColumn [ 0 ] . ColumnExists === 0 ) {
226+ if ( Number ( checkColumn [ 0 ] . ColumnExists ) === 0 ) {
227227 await queryRunner . manager . query ( `ALTER TABLE \`${ tableName } \` ADD COLUMN \`doc_id\` longtext;` )
228228 }
229229
@@ -234,9 +234,26 @@ class MySQLRecordManager implements RecordManagerInterface {
234234 `SELECT COUNT(1) IndexIsThere FROM INFORMATION_SCHEMA.STATISTICS
235235 WHERE table_schema=DATABASE() AND table_name='${ tableName } ' AND index_name='${ column } _index';`
236236 )
237- if ( Check [ 0 ] . IndexIsThere === 0 )
238- await queryRunner . manager . query ( `CREATE INDEX \`${ column } _index\`
237+
238+ if ( Number ( Check [ 0 ] . IndexIsThere ) === 0 ) {
239+ // Check column data type to determine if prefix length is needed
240+ const columnTypeCheck = await queryRunner . manager . query (
241+ `SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS
242+ WHERE table_schema=DATABASE() AND table_name='${ tableName } ' AND column_name='${ column } ';`
243+ )
244+
245+ // For TEXT/BLOB columns, use prefix length of 255
246+ if ( columnTypeCheck . length > 0 ) {
247+ const dataType = columnTypeCheck [ 0 ] . DATA_TYPE . toLowerCase ( )
248+ if ( dataType . includes ( 'text' ) || dataType . includes ( 'blob' ) ) {
249+ await queryRunner . manager . query ( `CREATE INDEX \`${ column } _index\`
250+ ON \`${ tableName } \` (\`${ column } \`(255));` )
251+ } else {
252+ await queryRunner . manager . query ( `CREATE INDEX \`${ column } _index\`
239253 ON \`${ tableName } \` (\`${ column } \`);` )
254+ }
255+ }
256+ }
240257 }
241258
242259 await queryRunner . release ( )
0 commit comments