node-pg-migrate
Advanced tools
Comparing version 3.19.0 to 3.20.0
# Change Log | ||
## [3.19.0](2019-05-06) | ||
### Added | ||
- Add ifNotExists to addColumns [#427](https://github.com/salsita/node-pg-migrate/pull/427) | ||
## [3.19.0](2019-04-30) | ||
@@ -4,0 +10,0 @@ |
@@ -282,3 +282,5 @@ "use strict"; | ||
function addColumns(typeShorthands) { | ||
const _add = (tableName, columns) => { | ||
const _add = (tableName, columns, { | ||
ifNotExists | ||
} = {}) => { | ||
const _parseColumns2 = parseColumns(tableName, columns, typeShorthands), | ||
@@ -289,3 +291,3 @@ columnLines = _parseColumns2.columns, | ||
const columnsStr = formatLines(columnLines, " ADD "); | ||
const columnsStr = formatLines(columnLines, ` ADD ${ifNotExists ? "IF NOT EXISTS " : ""}`); | ||
const alterTableQuery = template`ALTER TABLE "${tableName}"\n${columnsStr};`; | ||
@@ -292,0 +294,0 @@ const columnCommentsStr = columnComments.length > 0 ? `\n${columnComments.join("\n")}` : ""; |
@@ -45,3 +45,3 @@ # Column Operations | ||
### `pgm.addColumns( tablename, new_columns )` | ||
### `pgm.addColumns( tablename, new_columns, options )` | ||
@@ -54,2 +54,4 @@ > Add columns to an existing table - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertable.html) | ||
- `new_columns` _[object]_ - column names / options -- see [column definitions section](#column-definitions) | ||
- `options` _[object]_ - options: | ||
- `ifNotExists` _[boolean]_ adds column only if it does not exist | ||
@@ -56,0 +58,0 @@ **Aliases:** `addColumn` |
@@ -186,2 +186,6 @@ // Type definitions for node-pg-migrate | ||
export interface IfNotExistsOption { | ||
ifNotExists?: boolean | ||
} | ||
export interface CascadeOption { | ||
@@ -191,2 +195,3 @@ cascade?: boolean | ||
export type AddOptions = IfNotExistsOption | ||
export type DropOptions = IfExistsOption & CascadeOption | ||
@@ -374,4 +379,4 @@ | ||
// Columns | ||
addColumns(tableName: Name, newColumns: ColumnDefinitions): void | ||
addColumn(tableName: Name, newColumns: ColumnDefinitions): void | ||
addColumns(tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions): void | ||
addColumn(tableName: Name, newColumns: ColumnDefinitions, addOptions?: AddOptions): void | ||
dropColumns(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions?: DropOptions): void | ||
@@ -378,0 +383,0 @@ dropColumn(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions?: DropOptions): void |
@@ -308,3 +308,3 @@ const _ = require("lodash"); | ||
function addColumns(typeShorthands) { | ||
const _add = (tableName, columns) => { | ||
const _add = (tableName, columns, { ifNotExists } = {}) => { | ||
const { | ||
@@ -314,3 +314,6 @@ columns: columnLines, | ||
} = parseColumns(tableName, columns, typeShorthands); | ||
const columnsStr = formatLines(columnLines, " ADD "); | ||
const columnsStr = formatLines( | ||
columnLines, | ||
` ADD ${ifNotExists ? "IF NOT EXISTS " : ""}` | ||
); | ||
const alterTableQuery = template`ALTER TABLE "${tableName}"\n${columnsStr};`; | ||
@@ -317,0 +320,0 @@ const columnCommentsStr = |
{ | ||
"name": "node-pg-migrate", | ||
"version": "3.19.0", | ||
"version": "3.20.0", | ||
"description": "Postgresql database migration management tool for node.js", | ||
@@ -63,3 +63,3 @@ "author": "Theo Ephraim", | ||
"cross-env": "5.2.0", | ||
"dotenv": "7.0.0", | ||
"dotenv": "8.0.0", | ||
"eslint": "5.16.0", | ||
@@ -71,4 +71,4 @@ "eslint-config-airbnb-base": "13.1.0", | ||
"eslint-plugin-security": "1.4.0", | ||
"husky": "2.1.0", | ||
"lint-staged": "8.1.5", | ||
"husky": "2.2.0", | ||
"lint-staged": "8.1.6", | ||
"mocha": "6.1.4", | ||
@@ -75,0 +75,0 @@ "pg": "7.10.0", |
279297
4869