Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of multiline SQL in SQLite3 schema #3411

Merged
merged 7 commits into from Oct 6, 2019

Handle multiline SQL correctly in SQLite3 schema

  • Loading branch information
6uliver committed Aug 24, 2019
commit 1b82781182e646ddd5fa051f13eacf6863d5ac17
@@ -129,7 +129,8 @@ assign(SQLite3_DDL.prototype, {
},

_doReplace(sql, from, to) {
const matched = sql.match(/^CREATE TABLE (\S+) \((.*)\)/);
const oneLineSql = sql.replace(/\s+/g, ' ');
const matched = oneLineSql.match(/^CREATE TABLE (\S+) \((.*)\)/);

const tableName = matched[1];
const defs = matched[2];
@@ -174,13 +175,13 @@ assign(SQLite3_DDL.prototype, {
//
// We have to replace the from+to field with double slashes in case you created your SQlite3
// database with Knex < 0.14.
if (sql.match(/CREATE\sTABLE\s".*"\s\("/)) {
if (oneLineSql.match(/CREATE\sTABLE\s".*"\s\("/)) {
from = from.replace(/[`]/g, '"');
to = to.replace(/[`]/g, '"');
}

args = args.map(function(item) {
let split = item.split(' ');
let split = item.trim().split(' ');

if (split[0] === from) {
// column definition
@@ -222,7 +223,7 @@ assign(SQLite3_DDL.prototype, {

return item;
});
return sql
return oneLineSql
.replace(/\(.*\)/, () => `(${args.join(', ')})`)
.replace(/,\s*([,)])/, '$1');
},
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.