loopbackio / loopbackio/loopback-connector-mysql

mysql.index is not work on property

Open
#467 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
126
Forks
181
Avg merge
4d 7h
Merged PRs (30d)
12

Description

## 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.

```ts
// 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) {
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](http://loopback.io/doc/en/contrib/Reporting-issues.html) for more tips on writing good issues_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use examples/todo/src/models/todo.model.ts as the reproduction, run npm run migrate, and inspect the cited locations around lines 361 and 661 in lib/migration.js. Compare those property lookups with the README guidance and the working @property.index example; done means the documented configuration and migration behavior consistently create the intended FULLTEXT index.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, nodejs, typescript
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.