Skip to content

Commit

Permalink
Correct handling of multiline constraints (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolezel authored Feb 21, 2018
1 parent 56ffbd5 commit 7a73621
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/operations/tables.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 7a73621

Please sign in to comment.