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

Commit 447a5f34 by Jan Aagaard Meier

Move lenght to the end of data type for sqlite

1 parent 94ec0379
...@@ -55,6 +55,7 @@ module.exports = (function() { ...@@ -55,6 +55,7 @@ module.exports = (function() {
return Utils._.includes(definition, 'PRIMARY KEY') return Utils._.includes(definition, 'PRIMARY KEY')
}).length > 1) }).length > 1)
, attrStr = [] , attrStr = []
, endParen
for (var attr in attributes) { for (var attr in attributes) {
...@@ -65,6 +66,17 @@ module.exports = (function() { ...@@ -65,6 +66,17 @@ module.exports = (function() {
dataType = dataType.replace(/BIGINT/, 'INTEGER') dataType = dataType.replace(/BIGINT/, 'INTEGER')
} }
if ((endParen = dataType.indexOf(')')) !== -1 && endParen !== (dataType.length - 1)) {
// Move the length to the end of the string, as required by SQLite (needed for things like INTEGER(5) UNSIGNED -> INTEGER UNSIGNED(5))
var match = dataType.match(/\(\d+\)/)
if (match) {
match = match[0]
dataType = dataType.replace(match, '')
dataType += match
}
}
if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) { if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) {
primaryKeys.push(attr) primaryKeys.push(attr)
attrStr.push(this.quoteIdentifier(attr) + " " + dataType.replace(/PRIMARY KEY/, 'NOT NULL')) attrStr.push(this.quoteIdentifier(attr) + " " + dataType.replace(/PRIMARY KEY/, 'NOT NULL'))
......
...@@ -91,6 +91,10 @@ if (dialect === 'sqlite') { ...@@ -91,6 +91,10 @@ 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'}],
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR BINARY(255), `number` INTEGER UNSIGNED(5));"
},
{
arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}], arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` ENUM(\"A\", \"B\", \"C\"), `name` VARCHAR(255));" expectation: "CREATE TABLE IF NOT EXISTS `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!