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

Commit a7436d35 by Sascha Depold

Merge pull request #635 from sevastos/override-default-attributes

Enable the override of the default attributes
2 parents 15977057 16e13f6c
...@@ -481,7 +481,9 @@ module.exports = (function() { ...@@ -481,7 +481,9 @@ module.exports = (function() {
} }
Utils._.each(defaultAttributes, function(value, attr) { Utils._.each(defaultAttributes, function(value, attr) {
if (Utils._.isUndefined(self.rawAttributes[attr])) {
self.rawAttributes[attr] = value self.rawAttributes[attr] = value
}
}) })
} }
......
...@@ -726,10 +726,16 @@ module.exports = (function() { ...@@ -726,10 +726,16 @@ module.exports = (function() {
} }
if (Utils._.includes(dataType, 'SERIAL')) { if (Utils._.includes(dataType, 'SERIAL')) {
if (Utils._.includes(dataType, 'BIGINT')) {
dataType = dataType.replace(/SERIAL/, 'BIGSERIAL')
dataType = dataType.replace(/BIGINT/, '')
tables[tableName][attr] = 'bigserial'
} else {
dataType = dataType.replace(/INTEGER/, '') dataType = dataType.replace(/INTEGER/, '')
dataType = dataType.replace(/NOT NULL/, '')
tables[tableName][attr] = 'serial' tables[tableName][attr] = 'serial'
} }
dataType = dataType.replace(/NOT NULL/, '')
}
if (dataType.match(/^ENUM\(/)) { if (dataType.match(/^ENUM\(/)) {
dataType = dataType.replace(/^ENUM\(.+\)/, QueryGenerator.pgEscapeAndQuote("enum_" + tableName + "_" + attr)) dataType = dataType.replace(/^ENUM\(.+\)/, QueryGenerator.pgEscapeAndQuote("enum_" + tableName + "_" + attr))
......
...@@ -76,6 +76,10 @@ module.exports = (function() { ...@@ -76,6 +76,10 @@ module.exports = (function() {
if (attributes.hasOwnProperty(attr)) { if (attributes.hasOwnProperty(attr)) {
var dataType = attributes[attr] var dataType = attributes[attr]
if (Utils._.includes(dataType, 'AUTOINCREMENT')) {
dataType = dataType.replace(/BIGINT/, 'INTEGER')
}
if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) { if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) {
primaryKeys.push(attr) primaryKeys.push(attr)
attrStr.push(Utils.addTicks(attr) + " " + dataType.replace(/PRIMARY KEY/, 'NOT NULL')) attrStr.push(Utils.addTicks(attr) + " " + dataType.replace(/PRIMARY KEY/, 'NOT NULL'))
......
...@@ -194,5 +194,29 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() { ...@@ -194,5 +194,29 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}) })
}) })
}) })
describe('table', function() {
[
{ id: { type: Helpers.Sequelize.BIGINT } },
{ id: { type: Helpers.Sequelize.STRING, allowNull: true } },
{ id: { type: Helpers.Sequelize.BIGINT, allowNull: false, primaryKey: true, autoIncrement: true } }
].forEach(function(customAttributes) {
it('should be able to override options on the default attributes', function(done) {
var Picture = this.sequelize.define('picture', Helpers.Sequelize.Utils._.cloneDeep(customAttributes))
Picture.sync({ force: true }).success(function() {
Object.keys(customAttributes).forEach(function(attribute) {
Object.keys(customAttributes[attribute]).forEach(function(option) {
var optionValue = customAttributes[attribute][option];
expect(Picture.rawAttributes[attribute][option]).toBe(optionValue)
});
})
done()
})
})
})
})
}) })
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!