Skip to content

Commit

Permalink
Support creating indexes on table with schema
Browse files Browse the repository at this point in the history
When creating an index on a table where the schema is specified, the
schema shouldn't be included in the index name.
  • Loading branch information
aschrab committed Aug 26, 2017
1 parent 73ed8cc commit 8d04852
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/operations/indexes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import _ from 'lodash';
import { template } from '../utils';

function generateIndexName(table_name, columns, options) {
function generateIndexName(table, columns, options) {
const table_name = typeof table === 'object'
? table.name
: table;
return options.name
? options.name
: template`${table_name}_${_.isArray(columns) ? columns.join('_') : columns}${options.unique ? '_unique' : ''}_index`;
Expand Down
11 changes: 11 additions & 0 deletions test/indexes-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect } from 'chai';
import * as Indexes from '../lib/operations/indexes';

describe('lib/operations/indexes', () => {
describe('.create', () => {
it('check schema not included in index name', () => {
const sql = Indexes.create({ schema: 'a', name: 'b' }, ['c', 'd']);
expect(sql).to.equal('CREATE INDEX "b_c_d_index" ON "a"."b" ("c", "d");');
});
});
});

0 comments on commit 8d04852

Please sign in to comment.