Skip to content

mysql.index is not work on property #467

Description

@forno

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.

class Post {
@property({
type: 'string',
mysql: {
index: {
kind: 'FULLTEXT'
}
},
})
content: string;
}

Or,

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

const i = prop && prop.index;

const i = m.properties[propName].index;

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

#350

See Reporting Issues for more tips on writing good issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Icebox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions