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

Commit a35ec013 by Ivan Rubinson Committed by GitHub

fix(sqlite): multiple primary keys results in syntax error (#12237)

1 parent 4c1ce2b0
...@@ -44,7 +44,11 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator { ...@@ -44,7 +44,11 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
if (needsMultiplePrimaryKeys) { if (needsMultiplePrimaryKeys) {
primaryKeys.push(attr); primaryKeys.push(attr);
dataTypeString = dataType.replace('PRIMARY KEY', 'NOT NULL'); if (dataType.includes('NOT NULL')) {
dataTypeString = dataType.replace(' PRIMARY KEY', '');
} else {
dataTypeString = dataType.replace('PRIMARY KEY', 'NOT NULL');
}
} }
} }
attrArray.push(`${this.quoteIdentifier(attr)} ${dataTypeString}`); attrArray.push(`${this.quoteIdentifier(attr)} ${dataTypeString}`);
......
...@@ -152,6 +152,10 @@ if (dialect === 'sqlite') { ...@@ -152,6 +152,10 @@ if (dialect === 'sqlite') {
{ {
arguments: ['myTable', { id: 'INTEGER PRIMARY KEY AUTOINCREMENT', name: 'VARCHAR(255)', surname: 'VARCHAR(255)' }, { uniqueKeys: { uniqueConstraint: { fields: ['name', 'surname'], customIndex: true } } }], arguments: ['myTable', { id: 'INTEGER PRIMARY KEY AUTOINCREMENT', name: 'VARCHAR(255)', surname: 'VARCHAR(255)' }, { uniqueKeys: { uniqueConstraint: { fields: ['name', 'surname'], customIndex: true } } }],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255), `surname` VARCHAR(255), UNIQUE (`name`, `surname`));' expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255), `surname` VARCHAR(255), UNIQUE (`name`, `surname`));'
},
{
arguments: ['myTable', { foo1: 'INTEGER PRIMARY KEY NOT NULL', foo2: 'INTEGER PRIMARY KEY NOT NULL' }],
expectation: 'CREATE TABLE IF NOT EXISTS `myTable` (`foo1` INTEGER NOT NULL, `foo2` INTEGER NOT NULL, PRIMARY KEY (`foo1`, `foo2`));'
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!