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

Commit a7f18ba6 by Pete Peterson Committed by Jan Aagaard Meier

fix(sqlite/querygenerator): quote attributes in alterConstraint and renameColumn…

… queries for sqlite (Closes #7759)
1 parent 5c4ce94c
......@@ -386,7 +386,7 @@ const QueryGenerator = {
const quotedTableName = this.quoteTable(tableName);
const quotedBackupTableName = this.quoteTable(backupTableName);
const attributeNames = Object.keys(attributes).join(', ');
const attributeNames = Object.keys(attributes).map(attr => this.quoteIdentifier(attr)).join(', ');
return this.createTableQuery(backupTableName, attributes).replace('CREATE TABLE', 'CREATE TEMPORARY TABLE')
+ `INSERT INTO ${quotedBackupTableName} SELECT ${attributeNames} FROM ${quotedTableName};`
......@@ -411,7 +411,7 @@ const QueryGenerator = {
}
const quotedTableName = this.quoteTable(tableName);
const quotedBackupTableName = this.quoteTable(backupTableName);
const attributeNames = Object.keys(attributes).join(', ');
const attributeNames = Object.keys(attributes).map(attr => this.quoteIdentifier(attr)).join(', ');
return createTableSql.replace(`CREATE TABLE ${quotedTableName}`, `CREATE TABLE ${quotedBackupTableName}`)
+ `INSERT INTO ${quotedBackupTableName} SELECT ${attributeNames} FROM ${quotedTableName};`
......
......@@ -502,6 +502,32 @@ if (dialect === 'sqlite') {
expectation: "UPDATE `myTable` SET `bar`=`foo` WHERE `name` = 'foo'",
needsSequelize: true
}
],
renameColumnQuery: [
{
title: 'Properly quotes column names',
arguments: ['myTable', 'foo', 'commit', {commit: 'VARCHAR(255)', bar: 'VARCHAR(255)'}],
expectation:
'CREATE TEMPORARY TABLE IF NOT EXISTS `myTable_backup` (`commit` VARCHAR(255), `bar` VARCHAR(255));' +
'INSERT INTO `myTable_backup` SELECT `foo` AS `commit`, `bar` FROM `myTable`;' +
'DROP TABLE `myTable`;' +
'CREATE TABLE IF NOT EXISTS `myTable` (`commit` VARCHAR(255), `bar` VARCHAR(255));' +
'INSERT INTO `myTable` SELECT `commit`, `bar` FROM `myTable_backup`;' +
'DROP TABLE `myTable_backup`;'
}
],
removeColumnQuery: [
{
title: 'Properly quotes column names',
arguments: ['myTable', {commit: 'VARCHAR(255)', bar: 'VARCHAR(255)'}],
expectation:
'CREATE TEMPORARY TABLE IF NOT EXISTS `myTable_backup` (`commit` VARCHAR(255), `bar` VARCHAR(255));' +
'INSERT INTO `myTable_backup` SELECT `commit`, `bar` FROM `myTable`;' +
'DROP TABLE `myTable`;' +
'CREATE TABLE IF NOT EXISTS `myTable` (`commit` VARCHAR(255), `bar` VARCHAR(255));' +
'INSERT INTO `myTable` SELECT `commit`, `bar` FROM `myTable_backup`;' +
'DROP TABLE `myTable_backup`;'
}
]
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!