node-pg-migrate
Advanced tools
Comparing version 2.21.0 to 2.22.0
# Change Log | ||
## [2.22.0] (2018-02-20) | ||
### Added | ||
- Auto create configured schemas if they don't exist [#192](https://github.com/salsita/node-pg-migrate/pull/192) | ||
- Add ifNotExists option to create extension [#188](https://github.com/salsita/node-pg-migrate/pull/188) | ||
- Programmatic API docs [#187](https://github.com/salsita/node-pg-migrate/pull/187) | ||
## [2.21.0] (2018-02-12) | ||
@@ -4,0 +12,0 @@ |
@@ -16,6 +16,8 @@ 'use strict'; | ||
var create = exports.create = function create(extensions) { | ||
var create = exports.create = function create(extensions, _ref) { | ||
var ifNotExists = _ref.ifNotExists; | ||
if (!_lodash2.default.isArray(extensions)) extensions = [extensions]; // eslint-disable-line no-param-reassign | ||
return _lodash2.default.map(extensions, function (extension) { | ||
return _utils.template`CREATE EXTENSION "${extension}";`; | ||
return _utils.template`CREATE EXTENSION${ifNotExists ? ' IF NOT EXISTS' : ''} "${extension}";`; | ||
}); | ||
@@ -25,5 +27,5 @@ }; | ||
var drop = exports.drop = function drop(extensions) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
ifExists = _ref.ifExists, | ||
cascade = _ref.cascade; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
ifExists = _ref2.ifExists, | ||
cascade = _ref2.cascade; | ||
@@ -30,0 +32,0 @@ if (!_lodash2.default.isArray(extensions)) extensions = [extensions]; // eslint-disable-line no-param-reassign |
@@ -172,3 +172,11 @@ 'use strict'; | ||
return (_Promise$resolve$then = Promise.resolve().then(function () { | ||
return options.schema ? db.query(`SET SCHEMA '${options.schema}'`) : null; | ||
if (options.schema) { | ||
if (options.create_schema) { | ||
db.query(`CREATE SCHEMA IF NOT EXISTS '${options.schema}'`); | ||
} | ||
db.query(`SET SCHEMA '${options.schema}'`); | ||
} | ||
if (options.migrations_schema && options.create_migrations_schema) { | ||
db.query(`CREATE SCHEMA IF NOT EXISTS '${options.migrations_schema}'`); | ||
} | ||
}).then(function () { | ||
@@ -175,0 +183,0 @@ return Promise.all([loadMigrationFiles(db, options), getRunMigrations(db, options)]); |
@@ -309,4 +309,4 @@ // Type definitions for node-pg-migrate | ||
// Extensions | ||
createExtension(extension: string | string[]): void | ||
addExtension(extension: string | string[]): void | ||
createExtension(extension: string | string[], options: { ifNotExists?: boolean }): void | ||
addExtension(extension: string | string[], options: { ifNotExists?: boolean }): void | ||
dropExtension(extension: string | string[], dropOptions: DropOptions): void | ||
@@ -405,6 +405,7 @@ | ||
count: number | ||
timestamp?: boolean | ||
ignorePattern: string | ||
file?: string | ||
dryRun?: boolean | ||
typeShorthands?: { [name: string]: string } | ||
typeShorthands?: { [name: string]: ColumnDefinition } | ||
noLock?: boolean | ||
@@ -411,0 +412,0 @@ } |
@@ -33,3 +33,3 @@ { | ||
], | ||
"version": "2.21.0", | ||
"version": "2.22.0", | ||
"engines": { | ||
@@ -36,0 +36,0 @@ "node": ">=4.0.0" |
@@ -87,5 +87,7 @@ # node-pg-migrate | ||
* `schema` (`s`) - The schema on which migration will be run (defaults to `public`) | ||
* `create-schema` - Create the configured schema if it doesn't exist (defaults to `false`) | ||
* `database-url-var` (`d`) - Name of env variable with database url string (defaults to `DATABASE_URL`) | ||
* `migrations-dir` (`m`) - The directory containing your migration files (defaults to `migrations`) | ||
* `migrations-schema` - The schema storing table which migrations have been run (defaults to same value as `schema`) | ||
* `create-migrations-schema` - Create the configured migrations schema if it doesn't exist (defaults to `false`) | ||
* `migrations-table` (`t`) - The table storing which migrations have been run (defaults to `pgmigrations`) | ||
@@ -147,2 +149,23 @@ * `ignore-pattern` - Regex pattern for file names to ignore (e.g. `ignore_file|\..*|.*\.spec\.js`) | ||
## Programmatic API | ||
Alongside with command line, you can use `node-pg-migrate` also programmatically. It exports runner function, | ||
which takes options argument with following structure (similar to [command line arguments](#configuration)): | ||
* `database_url` _[string or object]_ - Connection string or client config which is passed to [new pg.Client](https://node-postgres.com/api/client#new-client-config-object-) | ||
* `migrations_table` _[string]_ - The table storing which migrations have been run | ||
* `migrations_schema` _[string]_ - The schema storing table which migrations have been run (defaults to same value as `schema`) | ||
* `schema` _[string]_ - The schema on which migration will be run (defaults to `public`) | ||
* `dir` _[string]_ - The directory containing your migration files | ||
* `checkOrder` _[boolean]_ - Check order of migrations before running them | ||
* `direction` _[enum]_ - `up` or `down` | ||
* `count` _[number]_ - Number of migration to run | ||
* `timestamp` _[boolean]_ - Treats `count` as timestamp | ||
* `ignorePattern` _[string]_ - Regex pattern for file names to ignore | ||
* `file` _[string]_ - Run only migration with this name | ||
* `typeShorthands` _[object]_ - Object with column type shorthands | ||
* `noLock` _[boolean]_ - Disables locking mechanism and checks | ||
* `dryRun` _[boolean]_ | ||
## Defining Migrations | ||
@@ -149,0 +172,0 @@ |
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
169647
2063
1099