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

Commit 6ca925b0 by Stefano Dalpiaz Committed by Sushant

Add quotes around column names for unique constraints in sqlite (fixes #4407) (#7270)

1 parent 99d406ea
# Future
- [FIXED] Add quotes around column names for unique constraints in sqlite [#4407](https://github.com/sequelize/sequelize/issues/4407)
# 3.30.2 # 3.30.2
- [FIXED] `previous` method gave wrong value back [#7189](https://github.com/sequelize/sequelize/pull/7189) - [FIXED] `previous` method gave wrong value back [#7189](https://github.com/sequelize/sequelize/pull/7189)
- [FIXED] Fixes setAssociation with scope [#7223](https://github.com/sequelize/sequelize/pull/7223) - [FIXED] Fixes setAssociation with scope [#7223](https://github.com/sequelize/sequelize/pull/7223)
......
...@@ -69,9 +69,10 @@ var QueryGenerator = { ...@@ -69,9 +69,10 @@ var QueryGenerator = {
, pkString = primaryKeys.map(function(pk) { return this.quoteIdentifier(pk); }.bind(this)).join(', '); , pkString = primaryKeys.map(function(pk) { return this.quoteIdentifier(pk); }.bind(this)).join(', ');
if (!!options.uniqueKeys) { if (!!options.uniqueKeys) {
var quoteIdentifier = this.quoteIdentifier.bind(this);
Utils._.each(options.uniqueKeys, function(columns) { Utils._.each(options.uniqueKeys, function(columns) {
if (!columns.singleField) { // If it's a single field its handled in column def, not as an index if (!columns.singleField) { // If it's a single field its handled in column def, not as an index
values.attributes += ', UNIQUE (' + columns.fields.join(', ') + ')'; values.attributes += ', UNIQUE (' + columns.fields.map(function(field) { return quoteIdentifier(field); }).join(', ') + ')';
} }
}); });
} }
......
...@@ -135,6 +135,10 @@ if (dialect === 'sqlite') { ...@@ -135,6 +135,10 @@ if (dialect === 'sqlite') {
{ {
arguments: ['myTable', {id: 'INTEGER PRIMARY KEY AUTOINCREMENT', name: 'VARCHAR(255)'}], 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));' 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`));'
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!