From d237b50e08dfcd18c0a99f22ade484f841680c79 Mon Sep 17 00:00:00 2001 From: Jan Dolezel Date: Wed, 21 Feb 2018 16:37:01 +0100 Subject: [PATCH] Correct handling of multiline constraints --- lib/operations/tables.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/operations/tables.js b/lib/operations/tables.js index ed492234..be1f0960 100644 --- a/lib/operations/tables.js +++ b/lib/operations/tables.js @@ -1,8 +1,11 @@ import _ from 'lodash'; import { escapeValue, template, quote, applyType, applyTypeAdapters, comment } from '../utils'; -const formatLines = (lines, replace, separator = ',\n') => - lines.join(separator).replace(/^/gm, replace); +const formatLines = (lines, replace, separator = ',') => + lines + .map(line => line.replace(/(?:\r\n|\r|\n)+/g, ' ')) + .join(`${separator}\n`) + .replace(/^/gm, replace); const parseReferences = (options) => { const { @@ -211,7 +214,7 @@ export const dropColumns = (tableName, columns, { ifExists, cascade } = {}) => { columns = _.keys(columns); // eslint-disable-line no-param-reassign } return template`ALTER TABLE "${tableName}" -${formatLines(quote(columns), ` DROP ${ifExists ? ' IF EXISTS' : ''}`, `${cascade ? ' CASCADE' : ''},\n`)};`; +${formatLines(quote(columns), ` DROP ${ifExists ? ' IF EXISTS' : ''}`, `${cascade ? ' CASCADE' : ''},`)};`; }; export const addColumns = (typeShorthands) => {