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

Commit a9dbf12f by Jan Aagaard Meier

Sqlite tests almost works now. Postgres = :(

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