Skip to content

Commit

Permalink
Add quotes around column names for unique constraints in sqlite (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoDalpiaz committed Feb 9, 2017
1 parent 8cbd375 commit 85affb9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -48,6 +48,7 @@
- [INTERNAL] Updated to `generic-pool@3.1.6` [#7109](https://github.com/sequelize/sequelize/issues/7109)
- [FIXED] findAll throws error if attributes option is formatted incorrectly [#7162](https://github.com/sequelize/sequelize/issues/7163)
- [FIXED] previous gave wrong value back [#7189](https://github.com/sequelize/sequelize/pull/7189)
- [FIXED] Add quotes around column names for unique constraints in sqlite [#7224](https://github.com/sequelize/sequelize/pull/7224)

## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
Expand Down
2 changes: 1 addition & 1 deletion lib/dialects/sqlite/query-generator.js
Expand Up @@ -62,7 +62,7 @@ const QueryGenerator = {
if (!!options.uniqueKeys) {
Utils._.each(options.uniqueKeys, columns => {
if (!columns.singleField) { // If it's a single field its handled in column def, not as an index
attrStr += ', UNIQUE (' + columns.fields.join(', ') + ')';
attrStr += ', UNIQUE (' + columns.fields.map(field => this.quoteIdentifier(field)).join(', ') + ')';
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/dialects/sqlite/query-generator.test.js
Expand Up @@ -135,6 +135,10 @@ if (dialect === 'sqlite') {
{
arguments: ['myTable', {id: 'INTEGER PRIMARY KEY AUTOINCREMENT', name: 'VARCHAR(255)'}],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255));'
},
{
arguments: ['myTable', {id: 'INTEGER PRIMARY KEY AUTOINCREMENT', name: 'VARCHAR(255)', surname: 'VARCHAR(255)'}, {uniqueKeys: {uniqueConstraint: {fields: ['name', 'surname']}}}],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255), `surname` VARCHAR(255), UNIQUE (`name`, `surname`));'
}
],

Expand Down

0 comments on commit 85affb9

Please sign in to comment.