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

Properties with underscores in their name cannot be indexed

Open ewrayjohnson opened this issue 3 years ago • 6 comments

Steps to reproduce

  1. create a model with a property name that contains an underscore in it (e.g. short_name).
  2. set that property to be indexed (e.g. "index": true)
  3. call pg.autoupdate() (e.g. where app.datasources.pg);

Current Behavior

  1. The index is added
  2. Then the index is dropped

Expected Behavior

  1. The index is added

Additional information

The bug shown here is a bad regular expression in migration.js (on or about line 777): const propNameRegEx = new RegExp('^' + self.table(model) + '_([^_]+)_idx');

The simple fix is: const propNameRegEx = new RegExp('^' + self.table(model) + '_(.*)(?:_idx)$');

ewrayjohnson avatar Oct 07 '20 08:10 ewrayjohnson

@ewrayjohnson, would you be interested to submit a PR?

dhmlau avatar Oct 10 '20 00:10 dhmlau

A workaround would be to specify a "valid" column name in the @property decorator. See https://github.com/dhmlau/loopback4-example-todo-customized#if-i-have-a-table-name-or-column-name-that-is-different-from-the-model-name-and-property-what-should-i-change for an example. Thanks.

dhmlau avatar Oct 10 '20 00:10 dhmlau

A workaround would be to specify a "valid" column name in the @property decorator. See https://github.com/dhmlau/loopback4-example-todo-customized#if-i-have-a-table-name-or-column-name-that-is-different-from-the-model-name-and-property-what-should-i-change for an example. Thanks.

ewrayjohnson avatar Oct 11 '20 17:10 ewrayjohnson

For those of us that have not taken the leap to LoopBack 4, the @property decorator is not an option. Instead we would have to use postgresql.columnName

ewrayjohnson avatar Oct 11 '20 17:10 ewrayjohnson

@ewrayjohnson, would you be interested to submit a PR?

Yes

ewrayjohnson avatar Oct 11 '20 17:10 ewrayjohnson

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 19 '20 08:12 stale[bot]