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

Commit a9dbf12f by Jan Aagaard Meier

Sqlite tests almost works now. Postgres = :(

1 parent bea2e11e
......@@ -52,24 +52,32 @@ module.exports = (function() {
this.daos.forEach(function(dao) {
var deps = []
, tableName = dao.getTableName()
daos[dao.tableName] = dao
if (_.isObject(tableName)) {
tableName = tableName.schema + '.' + tableName.tableName
}
daos[tableName] = dao
for (var attrName in dao.rawAttributes) {
if (dao.rawAttributes.hasOwnProperty(attrName)) {
if (dao.rawAttributes[attrName].references) {
dep = dao.rawAttributes[attrName].references
dep = dep.tableName || dep
if (_.isObject(dep)) {
dep = dep.schema + '.' + dep.tableName
}
deps.push(dep)
}
}
}
deps = deps.filter(function (dep) {
return dao.tableName !== dep
return tableName !== dep
})
sorter.add(dao.tableName, deps)
sorter.add(tableName, deps)
})
sorted = sorter.sort()
......
......@@ -326,11 +326,7 @@ module.exports = (function() {
}
DAOFactory.prototype.drop = function(options) {
// Only Postgres' QueryGenerator.dropTableQuery() will add schema manually
var isPostgres = this.options.dialect === "postgres" || (!!this.daoFactoryManager && this.daoFactoryManager.sequelize.options.dialect === "postgres")
, tableName = isPostgres ? this.tableName : this.getTableName()
return this.QueryInterface.dropTable(tableName, options)
return this.QueryInterface.dropTable(this.getTableName(), options)
}
DAOFactory.prototype.dropSchema = function(schema) {
......
......@@ -356,7 +356,7 @@ module.exports = (function() {
if (this._dialect.supports.schemas) {
if (param.schema) {
table += this.quoteIdentifier(param.schema) + param.delimiter
table += this.quoteIdentifier(param.schema) + '.'
}
table += this.quoteIdentifier(param.tableName)
......@@ -371,7 +371,7 @@ module.exports = (function() {
return table
}
return this.quoteIdentifier(param)
return this.quoteIdentifiers(param)
},
/*
......@@ -506,12 +506,19 @@ module.exports = (function() {
Split an identifier into .-separated tokens and quote each part
*/
quoteIdentifiers: function(identifiers, force) {
return identifiers.split('.').map(function(t) {
if (t.tableName) {
return this.quoteTable(t)
}
if (identifiers.indexOf('.') !== -1) {
identifiers = identifiers.split('.')
if (this._dialect.supports.schemas) { // quote every part
return identifiers.map(function(t) {
return this.quoteIdentifier(t, force)
}.bind(this)).join('.')
} else { // only quote the last part seperately
return this.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + this.quoteIdentifier(identifiers[identifiers.length - 1])
}
} else {
return this.quoteIdentifier(identifiers)
}
},
/*
......@@ -984,7 +991,7 @@ module.exports = (function() {
, _result = []
, _value
if (typeof value === 'object') {
if (_.isObject(value)) {
if (value.join) {
//using as sentinel for join column => value
result = [key, value.join].join("=")
......
......@@ -54,9 +54,9 @@ module.exports = (function() {
}
var values = {
table: this.quoteIdentifiers(tableName),
table: this.quoteTable(tableName),
attributes: attrStr.join(", "),
comments: Utils._.template(comments, { table: this.quoteIdentifiers(tableName)})
comments: Utils._.template(comments, { table: this.quoteTable(tableName)})
}
if (!!options.uniqueKeys) {
......@@ -456,7 +456,7 @@ module.exports = (function() {
if(dataType.references) {
template += " REFERENCES <%= referencesTable %> (<%= referencesKey %>)"
replacements.referencesTable = this.quoteIdentifiers(dataType.references)
replacements.referencesTable = this.quoteTable(dataType.references)
if(dataType.referencesKey) {
replacements.referencesKey = this.quoteIdentifiers(dataType.referencesKey)
......
......@@ -27,6 +27,9 @@ module.exports = (function() {
QueryInterface.prototype.dropAllSchemas = function() {
var self = this
if (!this.QueryGenerator._dialect.supports.schemas) {
return this.dropAllTables()
} else {
return new Utils.CustomEventEmitter(function(emitter) {
self.showAllSchemas().success(function(schemaNames) {
var chainer = new Utils.QueryChainer()
......@@ -37,6 +40,7 @@ module.exports = (function() {
}).proxy(emitter, {events: ['sql', 'error']})
}).run()
}
}
QueryInterface.prototype.showAllSchemas = function(options) {
var self = this
......
......@@ -601,8 +601,6 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
john.getTasks({where: {active: true}}).success(function (tasks) {
expect(tasks).to.have.length(1)
done()
}).on('sql', function (sql) {
console.log(sql)
})
})
})
......@@ -629,7 +627,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
username: DataTypes.STRING
}).schema('acme', '_')
, AcmeProject = self.sequelize.define('Project', {
title: DataTypes.STRING, active: DataTypes.BOOLEAN
title: DataTypes.STRING,
active: DataTypes.BOOLEAN
}).schema('acme', '_')
, AcmeProjectUsers = self.sequelize.define('ProjectUsers', {
status: DataTypes.STRING,
......@@ -639,7 +638,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
AcmeUser.hasMany(AcmeProject, {through: AcmeProjectUsers})
AcmeProject.hasMany(AcmeUser, {through: AcmeProjectUsers})
self.sequelize.dropAllSchemas().on('sql', function (sql) { console.log(sql); }).done(function(err)
self.sequelize.dropAllSchemas().done(function(err) {
expect(err).not.to.be.ok
self.sequelize.createSchema('acme').done(function(err) {
expect(err).not.to.be.ok
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!