Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Partial Indexes #12

Open
rickarubio opened this issue Jul 23, 2018 · 0 comments
Open

Feature Request: Partial Indexes #12

rickarubio opened this issue Jul 23, 2018 · 0 comments

Comments

@rickarubio
Copy link

rickarubio commented Jul 23, 2018

Currently, I can do db.addIndex to add a new index to a table.

However, there is no support for partial indexes.

Partial index example in raw sql for postgresql:

 'create unique index account_id_name_index on foo(account_id, name) where bar_id IS NULL'

Currently the addIndex method signature looks like this:

   addIndex: function(tableName, indexName, columns, unique, callback) {
    if (typeof(unique) === 'function') {
      callback = unique;
      unique = false;
    }

    if (!Array.isArray(columns)) {
      columns = [columns];
    }
    var sql = util.format('CREATE %s INDEX "%s" ON "%s" (%s)', (unique ? 'UNIQUE' : ''),
      indexName, tableName, this.quoteDDLArr(columns).join(', '));

    return this.runSql(sql).nodeify(callback);
  },

We could either modify the existing method signature by accepting another parameter that specifies the where clause, or a new method addPartialIndex.

Do you think that this is something you'd like added in? If yes, I wouldn't mind working on adding this feature in as I am currently using db-migrate for work and currently we resort to using raw sql to create the partial indexes, but it would be a nice to have if the db-migrate SQL API allowed for this.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant