loopbackio / loopbackio/loopback-connector-postgresql

Properties with underscores in their name cannot be indexed

Open
#462 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug good first issue help wanted
Dominant language
JavaScript
Stars
118
Forks
184
Avg merge
1d 22h
Merged PRs (30d)
5

Description

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)$');

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

Start in migration.js around line 777 and reproduce the reported model setup with an underscored property, then call pg.autoupdate(). Verify that the existing index remains after migration and that the property name is matched correctly when it contains underscores.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
databases
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.