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

Commit a14773ab by Jan Aagaard Meier

Fix handling of INTEGER PRIMARY KEY for sqlite (remove length, unsigned etc.)

1 parent fdba0dd4
...@@ -93,12 +93,17 @@ module.exports = (function() { ...@@ -93,12 +93,17 @@ module.exports = (function() {
modifierLastIndex = -1 modifierLastIndex = -1
} }
if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) { if (Utils._.includes(dataType, 'PRIMARY KEY')) {
primaryKeys.push(attr) if (Utils._.includes(dataType, 'INTEGER')) {
attrStr.push(this.quoteIdentifier(attr) + " " + dataType.replace(/PRIMARY KEY/, 'NOT NULL')) dataType = 'INTEGER PRIMARY KEY' // Only INTEGER is allowed for primary key, see https://github.com/sequelize/sequelize/issues/969 (no lenght, unsigned etc)
} else { }
attrStr.push(this.quoteIdentifier(attr) + " " + dataType)
if (needsMultiplePrimaryKeys) {
primaryKeys.push(attr)
dataType = dataType.replace(/PRIMARY KEY/, 'NOT NULL')
}
} }
attrStr.push(this.quoteIdentifier(attr) + " " + dataType)
} }
} }
......
...@@ -91,8 +91,8 @@ if (dialect === 'sqlite') { ...@@ -91,8 +91,8 @@ if (dialect === 'sqlite') {
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255));" expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255));"
}, },
{ {
arguments: ['myTable', {title: 'VARCHAR(255) BINARY', number: 'INTEGER(5) UNSIGNED PRIMARY KEY '}], arguments: ['myTable', {title: 'VARCHAR(255) BINARY', number: 'INTEGER(5) UNSIGNED PRIMARY KEY '}], // length and unsigned are not allowed on primary key
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR BINARY(255), `number` INTEGER UNSIGNED(5) PRIMARY KEY);" expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR BINARY(255), `number` INTEGER PRIMARY KEY);"
}, },
{ {
arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}], arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!