Skip to content

Commit

Permalink
Merge pull request sequelize#1058 from janmeier/sqliteweirdness
Browse files Browse the repository at this point in the history
Make the logic for manipulating sqlite data types a bit more solid
  • Loading branch information
janmeier committed Nov 13, 2013
2 parents b85e232 + 635d11b commit 1766a8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/dialects/sqlite/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,15 @@ module.exports = (function() {
var length = dataType.match(/\(\s*\d+(\s*,\s*\d)?\s*\)/)
if (length && length.index < modifierLastIndex) {
dataType = dataType.replace(length[0], '')
dataType = Utils._.insert(dataType, modifierLastIndex, length[0])

// Since the legnth was placed before the modifier, removing the legnth has changed the index
if (length.index < modifierLastIndex) {
modifierLastIndex -= length[0].length
}
dataType = Utils._.insert(dataType, modifierLastIndex, length[0]).trim()
}

modifierLastIndex = -1
}

if (Utils._.includes(dataType, 'PRIMARY KEY') && needsMultiplePrimaryKeys) {
Expand Down
4 changes: 2 additions & 2 deletions test/sqlite/query-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ if (dialect === 'sqlite') {
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: 'VARCHAR(255) BINARY', number: 'INTEGER(5) UNSIGNED PRIMARY KEY '}],
expectation: "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR BINARY(255), `number` INTEGER UNSIGNED(5) PRIMARY KEY);"
},
{
arguments: ['myTable', {title: 'ENUM("A", "B", "C")', name: 'VARCHAR(255)'}],
Expand Down

0 comments on commit 1766a8c

Please sign in to comment.