不要怂,就是干,撸起袖子干!

Commit d47e5053 by Ben Stephenson

Merge branch 'master' of https://github.com/sequelize/sequelize into update-fix

2 parents 21a31906 4397dbac
# Next
- [BUG] fix showIndexQuery so appropriate indexes are returned when a schema is used
- [BUG] Fix addIndexQuery error when the model has a schema
# 2.1.3 # 2.1.3
- [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667) - [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
- [BUG] Fix managed transactions not rolling back if no thenable was provided in the transaction block [3667](https://github.com/sequelize/sequelize/pull/3667) - [BUG] Fix managed transactions not rolling back if no thenable was provided in the transaction block [3667](https://github.com/sequelize/sequelize/pull/3667)
......
...@@ -479,7 +479,7 @@ module.exports = (function() { ...@@ -479,7 +479,7 @@ module.exports = (function() {
} }
options.prefix = options.prefix || rawTablename || tableName; options.prefix = options.prefix || rawTablename || tableName;
if (options.prefix) { if (options.prefix && _.isString(options.prefix)) {
options.prefix = options.prefix.replace(/\./g, '_'); options.prefix = options.prefix.replace(/\./g, '_');
options.prefix = options.prefix.replace(/(\"|\')/g, ''); options.prefix = options.prefix.replace(/(\"|\')/g, '');
} }
...@@ -542,6 +542,12 @@ module.exports = (function() { ...@@ -542,6 +542,12 @@ module.exports = (function() {
options.where = this.whereQuery(options.where); options.where = this.whereQuery(options.where);
} }
if (_.isString(tableName)) {
tableName = this.quoteIdentifiers(tableName);
} else {
tableName = this.quoteTable(tableName);
}
return Utils._.compact([ return Utils._.compact([
'CREATE', 'CREATE',
options.unique ? 'UNIQUE' : '', options.unique ? 'UNIQUE' : '',
...@@ -549,7 +555,7 @@ module.exports = (function() { ...@@ -549,7 +555,7 @@ module.exports = (function() {
this._dialect.supports.index.concurrently && options.concurrently ? 'CONCURRENTLY' : undefined, this._dialect.supports.index.concurrently && options.concurrently ? 'CONCURRENTLY' : undefined,
this.quoteIdentifiers(options.name), this.quoteIdentifiers(options.name),
this._dialect.supports.index.using === 1 && options.using ? 'USING ' + options.using : '', this._dialect.supports.index.using === 1 && options.using ? 'USING ' + options.using : '',
'ON', this.quoteIdentifiers(tableName), 'ON', tableName,
this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '', this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '',
'(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')', '(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')',
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined), (this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined),
......
...@@ -426,6 +426,10 @@ module.exports = (function() { ...@@ -426,6 +426,10 @@ module.exports = (function() {
}, },
showIndexesQuery: function(tableName) { showIndexesQuery: function(tableName) {
if (!Utils._.isString(tableName)) {
tableName = tableName.tableName;
}
// This is ARCANE! // This is ARCANE!
var query = 'SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, ' + var query = 'SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, ' +
'array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) ' + 'array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) ' +
......
...@@ -680,7 +680,7 @@ module.exports = (function() { ...@@ -680,7 +680,7 @@ module.exports = (function() {
* @param {Number} [options.limit] * @param {Number} [options.limit]
* @param {Number} [options.offset] * @param {Number} [options.offset]
* @param {Transaction} [options.transaction] * @param {Transaction} [options.transaction]
* @param {String} [options.lock] Lock the selected rows in either share or update mode. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. See [transaction.LOCK for an example](https://github.com/sequelize/sequelize/wiki/API-Reference-Transaction#LOCK) * @param {String|Object} [options.lock] Lock the selected rows. Possible options are transaction.LOCK.UPDATE and transaction.LOCK.SHARE. Postgres also supports transaction.LOCK.KEY_SHARE, transaction.LOCK.NO_KEY_UPDATE and specific model locks with joins. See [transaction.LOCK for an example](api/transaction#lock)
* @param {Boolean} [options.raw] Return raw result. See sequelize.query for more information. * @param {Boolean} [options.raw] Return raw result. See sequelize.query for more information.
* *
* @see {Sequelize#query} * @see {Sequelize#query}
...@@ -856,7 +856,7 @@ module.exports = (function() { ...@@ -856,7 +856,7 @@ module.exports = (function() {
var col = '*'; var col = '*';
if (options.include) { if (options.include) {
col = this.name + '.' + this.primaryKeyAttribute; col = this.name + '.' + this.primaryKeyField;
expandIncludeAll.call(this, options); expandIncludeAll.call(this, options);
validateIncludedElements.call(this, options); validateIncludedElements.call(this, options);
} }
......
...@@ -55,16 +55,36 @@ Transaction.ISOLATION_LEVELS = { ...@@ -55,16 +55,36 @@ Transaction.ISOLATION_LEVELS = {
* *
* ```js * ```js
* t1 // is a transaction * t1 // is a transaction
* t1.LOCK.UPDATE,
* t1.LOCK.SHARE,
* t1.LOCK.KEY_SHARE, // Postgres 9.3+ only
* t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only
* ```
*
* Usage:
* ```js
* t1 // is a transaction
* Model.findAll({ * Model.findAll({
* where: ... * where: ...,
* }, { * transaction: t1,
* lock: t1.LOCK...
* });
* ```
*
* Postgres also supports specific locks while eager loading by using OF:
* ```js
* UserModel.findAll({
* where: ...,
* include: [TaskModel, ...],
* transaction: t1, * transaction: t1,
* lock: t1.LOCK.UPDATE, * lock: {
* lock: t1.LOCK.SHARE, * level: t1.LOCK...,
* lock: t1.LOCK.KEY_SHARE, // Postgres 9.3+ only * of: UserModel
* lock: t1.LOCK.NO_KEY_UPDATE // Postgres 9.3+ only * }
* }) * });
* ``` * ```
* UserModel will be locked but TaskModel won't!
*
* @property LOCK * @property LOCK
*/ */
Transaction.LOCK = Transaction.prototype.LOCK = { Transaction.LOCK = Transaction.prototype.LOCK = {
......
...@@ -107,6 +107,39 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() { ...@@ -107,6 +107,39 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}); });
}); });
it('works with schemas', function() {
var self = this;
return self.sequelize.dropAllSchemas({logging: log}).then(function() {
return self.sequelize.createSchema('schema', {logging: log});
}).then(function() {
return self.queryInterface.createTable('table', {
name: {
type: DataTypes.STRING
},
isAdmin: {
type: DataTypes.STRING
}
}, {
schema: 'schema'
});
}).then(function() {
return self.queryInterface.addIndex({
schema: 'schema',
tableName: 'table'
}, ['name', 'isAdmin'], {
logging: log
}, 'schema_table').then(function() {
return self.queryInterface.showIndex({
schema: 'schema',
tableName: 'table'
}, {logging: log}).then(function(indexes) {
expect(indexes.length).to.eq(1);
count = 0;
});
});
});
});
it('does not fail on reserved keywords', function() { it('does not fail on reserved keywords', function() {
return this.queryInterface.addIndex('Group', ['from']); return this.queryInterface.addIndex('Group', ['from']);
}); });
......
...@@ -20,6 +20,13 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -20,6 +20,13 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])' default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
}); });
expectsql(sql.addIndexQuery({
schema: 'schema',
tableName: 'table'
}, ['column1', 'column2'], {}, 'schema_table'), {
default: 'CREATE INDEX [schema_table_column1_column2] ON [schema].[table] ([column1], [column2])'
});
expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({ expectsql(sql.addIndexQuery(sql.quoteTable(sql.addSchema({
schema: 'schema', schema: 'schema',
tableName: 'table' tableName: 'table'
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!