query-interface.test.js
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../../support')
, dialect = Support.getTestDialect()
, DataTypes = require(__dirname + '/../../../../lib/data-types')
, _ = require('lodash');
if (dialect.match(/^postgres/)) {
describe('[POSTGRES Specific] QueryInterface', function () {
beforeEach(function () {
this.sequelize.options.quoteIdenifiers = true;
this.queryInterface = this.sequelize.getQueryInterface();
});
describe('indexes', function () {
beforeEach(function () {
var self = this;
return this.queryInterface.dropTable('Group').then(function () {
return self.queryInterface.createTable('Group', {
username: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN,
from: DataTypes.STRING
});
});
});
it('adds, reads and removes a named functional index to the table', function () {
var self = this;
return this.queryInterface.addIndex('Group', [this.sequelize.fn('lower', this.sequelize.col('username'))], {
name: 'group_username_lower'
}).then(function () {
return self.queryInterface.showIndex('Group').then(function (indexes) {
var indexColumns = _.uniq(indexes.map(function (index) {
return index.name;
}));
expect(indexColumns).to.include('group_username_lower');
return self.queryInterface.removeIndex('Group', 'group_username_lower').then(function () {
return self.queryInterface.showIndex('Group').then(function (indexes) {
indexColumns = _.uniq(indexes.map(function (index) {
return index.name;
}));
expect(indexColumns).to.be.empty;
});
});
});
});
});
});
});
}