node-pg-migrate
Advanced tools
Comparing version 2.8.2 to 2.9.0
# Change Log | ||
## [2.9.0] (2017-09-12) | ||
### Added | ||
- Alter type functions [#111](https://github.com/theoephraim/node-pg-migrate/pull/111) | ||
- redo command [#112](https://github.com/theoephraim/node-pg-migrate/pull/112) | ||
## [2.8.2] (2017-09-11) | ||
@@ -4,0 +11,0 @@ |
@@ -104,4 +104,9 @@ 'use strict'; | ||
this.dropType = wrap(types.drop); | ||
this.alterType = wrap(types.alter); | ||
this.addType = this.createType; | ||
this.renameType = wrap(types.rename); | ||
this.renameTypeAttribute = wrap(types.renameTypeAttribute); | ||
this.addTypeAttribute = wrap(types.addTypeAttribute(options.typeShorthands)); | ||
this.dropTypeAttribute = wrap(types.dropTypeAttribute); | ||
this.setTypeAttribute = wrap(types.setTypeAttribute(options.typeShorthands)); | ||
this.addTypeValue = wrap(types.addTypeValue); | ||
@@ -108,0 +113,0 @@ this.createIndex = wrap(indexes.create); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.alter = exports.create = exports.drop = undefined; | ||
exports.undoRenameTypeAttribute = exports.renameTypeAttribute = exports.undoRename = exports.rename = exports.addTypeValue = exports.setTypeAttribute = exports.addTypeAttribute = exports.dropTypeAttribute = exports.create = exports.drop = undefined; | ||
@@ -24,8 +24,8 @@ var _lodash = require('lodash'); | ||
if (_lodash2.default.isArray(options)) { | ||
return _utils.template`CREATE TYPE "${type_name}" AS ENUM ('${options.join('\', \'')}');`; | ||
return _utils.template`CREATE TYPE "${type_name}" AS ENUM (${options.map(_utils.escapeValue).join(', ')});`; | ||
} | ||
var columns = _lodash2.default.map(options, function (column, column_name) { | ||
return _utils.template`"${column_name}" ${(0, _utils.applyType)(column, type_shorthands).type}`; | ||
var attributes = _lodash2.default.map(options, function (attribute, attribute_name) { | ||
return _utils.template`"${attribute_name}" ${(0, _utils.applyType)(attribute, type_shorthands).type}`; | ||
}).join(',\n'); | ||
return _utils.template`CREATE TYPE "${type_name}" AS (\n${columns}\n);`; | ||
return _utils.template`CREATE TYPE "${type_name}" AS (\n${attributes}\n);`; | ||
}; | ||
@@ -36,4 +36,57 @@ _create.reverse = drop; | ||
var alter = exports.alter = function alter() { | ||
return null; | ||
}; | ||
var dropTypeAttribute = exports.dropTypeAttribute = function dropTypeAttribute(type_name, attribute_name) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
ifExists = _ref.ifExists; | ||
return _utils.template`ALTER TYPE "${type_name}" DROP ATTRIBUTE "${attribute_name}"${ifExists ? ' IF EXISTS' : ''};`; | ||
}; | ||
var addTypeAttribute = exports.addTypeAttribute = function addTypeAttribute(type_shorthands) { | ||
var _alterAttributeAdd = function _alterAttributeAdd(type_name, attribute_name, attribute_type) { | ||
return _utils.template`ALTER TYPE "${type_name}" ADD ATTRIBUTE "${attribute_name}" ${(0, _utils.applyType)(attribute_type, type_shorthands).type};`; | ||
}; | ||
_alterAttributeAdd.reverse = dropTypeAttribute; | ||
return _alterAttributeAdd; | ||
}; | ||
var setTypeAttribute = exports.setTypeAttribute = function setTypeAttribute(type_shorthands) { | ||
return function (type_name, attribute_name, attribute_type) { | ||
return _utils.template`ALTER TYPE "${type_name}" ALTER ATTRIBUTE "${attribute_name}" SET DATA TYPE ${(0, _utils.applyType)(attribute_type, type_shorthands).type};`; | ||
}; | ||
}; | ||
var addTypeValue = exports.addTypeValue = function addTypeValue(type_name, value) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var ifNotExists = options.ifNotExists, | ||
before = options.before, | ||
after = options.after; | ||
if (before && after) { | ||
throw new Error('"before" and "after" can\'t be specified together'); | ||
} | ||
var beforeClause = before ? ` BEFORE ${before}` : ''; | ||
var afterClause = after ? ` BEFORE ${after}` : ''; | ||
return _utils.template`ALTER TYPE "${type_name}" ADD VALUE${ifNotExists ? ' IF NOT EXISTS' : ''} ${(0, _utils.escapeValue)(value)}${beforeClause}${afterClause};`; | ||
}; | ||
// RENAME | ||
var rename = exports.rename = function rename(type_name, new_type_name) { | ||
return _utils.template`ALTER TYPE "${type_name}" RENAME TO "${new_type_name}";`; | ||
}; | ||
var undoRename = exports.undoRename = function undoRename(type_name, new_type_name) { | ||
return rename(new_type_name, type_name); | ||
}; | ||
var renameTypeAttribute = exports.renameTypeAttribute = function renameTypeAttribute(type_name, attribute_name, new_attribute_name) { | ||
return _utils.template`ALTER TYPE "${type_name}" RENAME ATTRIBUTE "${attribute_name}" TO "${new_attribute_name}";`; | ||
}; | ||
var undoRenameTypeAttribute = exports.undoRenameTypeAttribute = function undoRenameTypeAttribute(type_name, attribute_name, new_attribute_name) { | ||
return renameTypeAttribute(type_name, new_attribute_name, attribute_name); | ||
}; | ||
rename.reverse = undoRename; | ||
renameTypeAttribute.reverse = undoRenameTypeAttribute; |
@@ -22,3 +22,3 @@ { | ||
], | ||
"version": "2.8.2", | ||
"version": "2.9.0", | ||
"engines": { | ||
@@ -25,0 +25,0 @@ "node": ">=4.0.0" |
@@ -65,2 +65,4 @@ # pg-migrate | ||
- `pg-migrate unlock` - unlocks migrations (if previous up/down migration failed and was not automatically unlocked). | ||
- `pg-migrate redo` - redoes last migration (runs a single down migration, then single up migration). | ||
- `pg-migrate redo {N}` - redoes N last migrations (runs N down migrations, then N up migrations). | ||
@@ -356,2 +358,71 @@ ### Configuration | ||
#### `pgm.renameType( type_name, new_type_name )` | ||
> Rename a data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type to rename | ||
- `new_type_name` _[string]_ - name of the new type | ||
----------------------------------------------------- | ||
#### `pgm.addTypeAttribute( type_name, attribute_name, attribute_type )` | ||
> Add attribute to an existing data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type | ||
- `attribute_name` _[string]_ - name of the attribute to add | ||
- `attribute_type` _[string]_ - type of the attribute to add | ||
----------------------------------------------------- | ||
#### `pgm.dropTypeAttribute( type_name, attribute_name, options )` | ||
> Drop attribute from a data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type | ||
- `attribute_name` _[string]_ - name of the attribute to drop | ||
- `options` _[object]_ - options: | ||
- `ifExists` _[boolean]_ - default false | ||
----------------------------------------------------- | ||
#### `pgm.setTypeAttribute( type_name, attribute_name, attribute_type )` | ||
> Set data type of an existing attribute of data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type | ||
- `attribute_name` _[string]_ - name of the attribute | ||
- `attribute_type` _[string]_ - new type of the attribute | ||
----------------------------------------------------- | ||
#### `pgm.addTypeValue( type_name, value, options )` | ||
> Add value to a list of enum data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type | ||
- `value` _[string]_ - value to add to list | ||
- `options` _[object]_ - options: | ||
- `ifNotExists` _[boolean]_ - default false | ||
- `before` _[string]_ - value before which the new value should be add | ||
- `after` _[string]_ - value after which the new value should be add | ||
----------------------------------------------------- | ||
#### `pgm.renameTypeAttribute( type_name, attribute_name, new_attribute_name )` | ||
> Rename an attribute of data type - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertype.html) | ||
**Arguments:** | ||
- `type_name` _[string]_ - name of the type | ||
- `attribute_name` _[string]_ - name of the attribute to rename | ||
- `new_attribute_name` _[string]_ - new name of the attribute | ||
----------------------------------------------------- | ||
### Role Operations | ||
@@ -396,3 +467,3 @@ | ||
> Alters a role - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterrole.html) | ||
> Alter a role - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterrole.html) | ||
@@ -407,3 +478,3 @@ **Arguments:** | ||
> Renames a role - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterrole.html) | ||
> Rename a role - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterrole.html) | ||
@@ -462,3 +533,3 @@ **Arguments:** | ||
> Renames a function - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterfunction.html) | ||
> Rename a function - [postgres docs](http://www.postgresql.org/docs/current/static/sql-alterfunction.html) | ||
@@ -511,3 +582,3 @@ **Arguments:** | ||
> Renames a trigger - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertrigger.html) | ||
> Rename a trigger - [postgres docs](http://www.postgresql.org/docs/current/static/sql-altertrigger.html) | ||
@@ -514,0 +585,0 @@ **Arguments:** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
190251
1159
687