db-migrate / db-migrate/db-migrate-base

Feature Request: Partial Indexes

Open
#12 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7
Forks
16
PR merge metrics
No merged PRs in 30d

Description

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:

```sql
'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:

```javascript
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!](https://www.bountysource.com/issues/61244961-feature-request-partial-indexes?utm_campaign=plugin&utm_content=tracker%2F11792942&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F11792942&utm_medium=issues&utm_source=github).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.