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

Commit bea65490 by Mick Hansen

test(schemas): add test for model dropping with schema

1 parent 544429ab
Showing with 16 additions and 12 deletions
...@@ -392,10 +392,10 @@ module.exports = (function() { ...@@ -392,10 +392,10 @@ module.exports = (function() {
return self.drop(options); return self.drop(options);
} }
}).then(function () { }).then(function () {
return self.QueryInterface.createTable(self.getTableName(options), attributes, options); return self.QueryInterface.createTable(self.getTableName(), attributes, options);
}).then(function () { }).then(function () {
return Promise.map(self.options.indexes, function (index) { return Promise.map(self.options.indexes, function (index) {
return self.QueryInterface.addIndex(self.getTableName(options), index.fields, index, self.tableName); return self.QueryInterface.addIndex(self.getTableName(), index.fields, index, self.tableName);
}); });
}).return(this); }).return(this);
}; };
...@@ -407,7 +407,7 @@ module.exports = (function() { ...@@ -407,7 +407,7 @@ module.exports = (function() {
* @return {Promise} * @return {Promise}
*/ */
Model.prototype.drop = function(options) { Model.prototype.drop = function(options) {
return this.QueryInterface.dropTable(this.getTableName(options), options); return this.QueryInterface.dropTable(this.getTableName(), options);
}; };
Model.prototype.dropSchema = function(schema) { Model.prototype.dropSchema = function(schema) {
...@@ -446,7 +446,7 @@ module.exports = (function() { ...@@ -446,7 +446,7 @@ module.exports = (function() {
* @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2) * @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2)
* @return {String|Object} * @return {String|Object}
*/ */
Model.prototype.getTableName = function(options) { Model.prototype.getTableName = function() {
return this.QueryGenerator.addSchema(this); return this.QueryGenerator.addSchema(this);
}; };
...@@ -690,7 +690,7 @@ module.exports = (function() { ...@@ -690,7 +690,7 @@ module.exports = (function() {
options = paranoidClause.call(this, options); options = paranoidClause.call(this, options);
return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({ return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
type: QueryTypes.SELECT, type: QueryTypes.SELECT,
hasJoin: hasJoin, hasJoin: hasJoin,
tableNames: Object.keys(tableNames) tableNames: Object.keys(tableNames)
...@@ -704,7 +704,7 @@ module.exports = (function() { ...@@ -704,7 +704,7 @@ module.exports = (function() {
// whereCollection is used for non-primary key updates // whereCollection is used for non-primary key updates
this.options.whereCollection = optcpy.where || null; this.options.whereCollection = optcpy.where || null;
return this.QueryInterface.select(this, [[this.getTableName(options), this.name], joinTableName], optcpy, Utils._.defaults({ return this.QueryInterface.select(this, [[this.getTableName(), this.name], joinTableName], optcpy, Utils._.defaults({
type: QueryTypes.SELECT type: QueryTypes.SELECT
}, queryOptions, { transaction: (options || {}).transaction })); }, queryOptions, { transaction: (options || {}).transaction }));
}; };
...@@ -798,7 +798,7 @@ module.exports = (function() { ...@@ -798,7 +798,7 @@ module.exports = (function() {
mapFieldNames.call(this, options, this); mapFieldNames.call(this, options, this);
options = paranoidClause.call(this, options); options = paranoidClause.call(this, options);
return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({ return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({
plain: true, plain: true,
type: QueryTypes.SELECT, type: QueryTypes.SELECT,
hasJoin: hasJoin, hasJoin: hasJoin,
...@@ -837,7 +837,7 @@ module.exports = (function() { ...@@ -837,7 +837,7 @@ module.exports = (function() {
options = paranoidClause.call(this, options); options = paranoidClause.call(this, options);
return this.QueryInterface.rawSelect(this.getTableName(options), options, aggregateFunction, this); return this.QueryInterface.rawSelect(this.getTableName(), options, aggregateFunction, this);
}; };
/** /**
...@@ -1284,7 +1284,7 @@ module.exports = (function() { ...@@ -1284,7 +1284,7 @@ module.exports = (function() {
} }
// Insert all records at once // Insert all records at once
return self.QueryInterface.bulkInsert(self.getTableName(options), records, options, attributes); return self.QueryInterface.bulkInsert(self.getTableName(), records, options, attributes);
} }
}).then(function() { }).then(function() {
// Run after hook // Run after hook
...@@ -1348,9 +1348,9 @@ module.exports = (function() { ...@@ -1348,9 +1348,9 @@ module.exports = (function() {
if (self._timestampAttributes.deletedAt && !options.force) { if (self._timestampAttributes.deletedAt && !options.force) {
var attrValueHash = {}; var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = Utils.now(self.modelManager.sequelize.options.dialect); attrValueHash[self._timestampAttributes.deletedAt] = Utils.now(self.modelManager.sequelize.options.dialect);
return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, where, options, self.rawAttributes); return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, where, options, self.rawAttributes);
} else { } else {
return self.QueryInterface.bulkDelete(self.getTableName(options), where, options, self); return self.QueryInterface.bulkDelete(self.getTableName(), where, options, self);
} }
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
...@@ -1497,7 +1497,7 @@ module.exports = (function() { ...@@ -1497,7 +1497,7 @@ module.exports = (function() {
} }
// Run query to update all rows // Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHashUse, where, options, self.tableAttributes).then(function(affectedRows) { return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHashUse, where, options, self.tableAttributes).then(function(affectedRows) {
if (options.returning) { if (options.returning) {
return [affectedRows.length, affectedRows]; return [affectedRows.length, affectedRows];
} }
......
...@@ -1665,6 +1665,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () { ...@@ -1665,6 +1665,10 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
}) })
}) })
it('should be able to drop with schemas', function () {
return this.UserSpecial.drop();
});
it("should be able to list schemas", function(done){ it("should be able to list schemas", function(done){
this.sequelize.showAllSchemas().then(function(schemas) { this.sequelize.showAllSchemas().then(function(schemas) {
expect(schemas).to.be.instanceof(Array) expect(schemas).to.be.instanceof(Array)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!