node-pg-migrate
Advanced tools
Comparing version 2.19.0 to 2.21.0
# Change Log | ||
## [2.21.0] (2018-02-12) | ||
### Added | ||
- Table and column comments [#183](https://github.com/salsita/node-pg-migrate/pull/183) | ||
## [2.19.0] (2018-02-06) | ||
@@ -4,0 +10,0 @@ |
@@ -51,4 +51,4 @@ 'use strict'; | ||
var parseColumns = function parseColumns(columns) { | ||
var extendingTypeShorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var parseColumns = function parseColumns(tableName, columns) { | ||
var extendingTypeShorthands = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
@@ -70,2 +70,6 @@ var columnsWithOptions = _lodash2.default.mapValues(columns, function (column) { | ||
var comments = _lodash2.default.chain(columnsWithOptions).map(function (options, columnName) { | ||
return typeof options.comment !== 'undefined' && (0, _utils.comment)('COLUMN', `${tableName}"."${columnName}`, options.comment); | ||
}).filter().value(); | ||
return { | ||
@@ -113,3 +117,4 @@ columns: _lodash2.default.map(columnsWithOptions, function (options, columnName) { | ||
}), | ||
constraints: _extends({}, multiplePrimaryColumns ? { primaryKey: primaryColumns } : {}) | ||
constraints: _extends({}, multiplePrimaryColumns ? { primaryKey: primaryColumns } : {}), | ||
comments | ||
}; | ||
@@ -178,7 +183,10 @@ }; | ||
_options$constraints = options.constraints, | ||
optionsConstraints = _options$constraints === undefined ? {} : _options$constraints; | ||
optionsConstraints = _options$constraints === undefined ? {} : _options$constraints, | ||
tableComment = options.comment; | ||
var _parseColumns = parseColumns(columns, typeShorthands), | ||
var _parseColumns = parseColumns(tableName, columns, typeShorthands), | ||
columnLines = _parseColumns.columns, | ||
columnsConstraints = _parseColumns.constraints; | ||
columnsConstraints = _parseColumns.constraints, | ||
_parseColumns$comment = _parseColumns.comments, | ||
columnComments = _parseColumns$comment === undefined ? [] : _parseColumns$comment; | ||
@@ -194,5 +202,10 @@ var dupes = _lodash2.default.intersection(Object.keys(optionsConstraints), Object.keys(columnsConstraints)); | ||
return _utils.template`CREATE TABLE${temporary ? ' TEMPORARY' : ''}${ifNotExists ? ' IF NOT EXISTS' : ''} "${tableName}" ( | ||
var createTable = _utils.template`CREATE TABLE${temporary ? ' TEMPORARY' : ''}${ifNotExists ? ' IF NOT EXISTS' : ''} "${tableName}" ( | ||
${formatLines(tableDefinition, ' ')} | ||
)${inherits ? _utils.template` INHERITS "${inherits}"` : ''};`; | ||
var comments = columnComments; | ||
if (typeof tableComment !== 'undefined') { | ||
comments.push((0, _utils.comment)('TABLE ', tableName, tableComment)); | ||
} | ||
return `${createTable}${comments.length > 0 ? `\n${comments.join('\n')}` : ''}`; | ||
}; | ||
@@ -220,6 +233,9 @@ _create.reverse = drop; | ||
var _add = function _add(tableName, columns) { | ||
var _parseColumns2 = parseColumns(columns, typeShorthands), | ||
columnLines = _parseColumns2.columns; | ||
var _parseColumns2 = parseColumns(tableName, columns, typeShorthands), | ||
columnLines = _parseColumns2.columns, | ||
_parseColumns2$commen = _parseColumns2.comments, | ||
columnComments = _parseColumns2$commen === undefined ? [] : _parseColumns2$commen; | ||
return _utils.template`ALTER TABLE "${tableName}"\n${formatLines(columnLines, ' ADD ')};`; | ||
var alter = _utils.template`ALTER TABLE "${tableName}"\n${formatLines(columnLines, ' ADD ')};`; | ||
return `${alter}${columnComments.length > 0 ? `\n${columnComments.join('\n')}` : ''}`; | ||
}; | ||
@@ -236,3 +252,4 @@ _add.reverse = dropColumns; | ||
notNull = options.notNull, | ||
allowNull = options.allowNull; | ||
allowNull = options.allowNull, | ||
columnComment = options.comment; | ||
@@ -254,3 +271,3 @@ var actions = []; | ||
return _utils.template`ALTER TABLE "${tableName}"\n${formatLines(actions, ` ALTER "${columnName}" `)};`; | ||
return _utils.template`ALTER TABLE "${tableName}"\n${formatLines(actions, ` ALTER "${columnName}" `)};${typeof columnComment !== 'undefined' ? `\n${(0, _utils.comment)('TABLE ', columnName, columnComment)}` : ''}`; | ||
}; | ||
@@ -257,0 +274,0 @@ |
@@ -205,2 +205,6 @@ 'use strict'; | ||
return `(${params.map(formatParam(typeShorthands)).join(', ')})`; | ||
}; | ||
var comment = exports.comment = function comment(object, name, text) { | ||
return template`COMMENT ON ${object} "${name}" IS ${text ? `'${text}'` : 'NULL'};`; | ||
}; |
@@ -47,2 +47,3 @@ // Type definitions for node-pg-migrate | ||
deferred?: boolean | ||
comment: string | null | ||
} | ||
@@ -56,2 +57,3 @@ | ||
constraints?: ConstraintOptions | ||
comment: string | null | ||
} | ||
@@ -66,2 +68,3 @@ | ||
using?: string | ||
comment: string | null | ||
} | ||
@@ -68,0 +71,0 @@ |
@@ -33,3 +33,3 @@ { | ||
], | ||
"version": "2.19.0", | ||
"version": "2.21.0", | ||
"engines": { | ||
@@ -36,0 +36,0 @@ "node": ">=4.0.0" |
@@ -226,2 +226,3 @@ # node-pg-migrate | ||
- `like` _[string]_ - table(s) to inherit from | ||
- `comment` _[string]_ - adds comment on table | ||
@@ -311,2 +312,3 @@ **Reverse Operation:** `dropTable` | ||
- `collation` _[string]_ - adds COLLATE clause to change values in column | ||
- `comment` _[string]_ - adds comment on column | ||
@@ -1009,2 +1011,3 @@ ----------------------------------------------------- | ||
- `deferred` _[boolean]_ - flag for initially deferred deferrable column constraint | ||
- `comment` _[string]_ - adds comment on column | ||
@@ -1011,0 +1014,0 @@ #### Data types & Convenience Shorthand |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
166685
2053
1076