loopback-connector-mysql icon indicating copy to clipboard operation
loopback-connector-mysql copied to clipboard

mysql.index is not work on property

Open forno opened this issue 2 years ago • 0 comments

Steps to reproduce

  1. Create the model, repository, and detasource with @property({type: 'string', mysql: {index: {kind: "FULLTEXT"}}}) on model.
  2. npm run migrate on cli.
  3. It should make FULLTEXT INDEX, however it isn't made on MySQL.

This is example of a model.

// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
// Node module: @loopback/example-todo
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {Entity, model, property} from '@loopback/repository';

@model()
export class Todo extends Entity {
  @property({
    type: 'number',
    id: true,
    generated: false,
  })
  id?: number;


  @property({
    type: 'string',
    required: true,
    // Not work for index creation
    mysql: {
      index: {
        kind: 'FULLTEXT',
      },
    },
  })
  title: string;

  @property({
    type: 'string',
    // work for index creation. but it is diffrent by README
    index: {
      kind: 'FULLTEXT',
      // also it can `unique: true` in here, not mysql.index.unique...
    },
  })
  desc?: string;

  constructor(data?: Partial<Todo>) {
    super(data);
  }
}

export interface TodoRelations {
  // describe navigational properties here
}

export type TodoWithRelations = Todo & TodoRelations;

Current Behavior

@property.mysql.index is not work.

But, I see work with @property.index.

Expected Behavior

We can replace @property.mysql.index with @property.index on README.

https://github.com/loopbackio/loopback-connector-mysql/blob/f8f40a1199b6ed63ba01d6d173a9314004c08c93/README.md?plain=1#L535-L545

Or,

Fix the prop.index to prop.mysql.index and m.properties[propName].index; to m.properties[propName].mysql.index; on migration.js.

https://github.com/loopbackio/loopback-connector-mysql/blob/f8f40a1199b6ed63ba01d6d173a9314004c08c93/lib/migration.js#L661

https://github.com/loopbackio/loopback-connector-mysql/blob/f8f40a1199b6ed63ba01d6d173a9314004c08c93/lib/migration.js#L361

Link to reproduction sandbox

https://github.com/forno/loopback-next/blob/index-bug-report/examples/todo/src/models/todo.model.ts

Additional information

the index creation function are already exist. But it is different config written by README. I don't know that either is correct.

Related Issues

https://github.com/loopbackio/loopback-connector-mysql/issues/350

See Reporting Issues for more tips on writing good issues

forno avatar Jul 08 '22 09:07 forno