Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-pg-migrate

Package Overview
Dependencies
Maintainers
3
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-pg-migrate - npm Package Compare versions

Comparing version 2.17.0 to 2.18.0

15

CHANGELOG.md
# Change Log
## [2.18.0] (2018-02-05)
### Added
- Add no lock option [#171](https://github.com/salsita/node-pg-migrate/pull/171)
- Updated docs [#174](https://github.com/salsita/node-pg-migrate/pull/174)
### Changed
- Remove old version number from index.d.ts [#173](https://github.com/salsita/node-pg-migrate/pull/173)
- Remove default match in column reference [#172](https://github.com/salsita/node-pg-migrate/pull/172)
- Refactor code to use camel casing [#167](https://github.com/salsita/node-pg-migrate/pull/167)
## [2.17.0] (2018-01-26)

@@ -33,3 +46,3 @@

- Operator operations [#156](https://github.com/salsita/node-pg-migrate/pull/156)
- Sequences operations [#157](https://github.com/salsita/node-pg-migrate/pull/157)
- Sequences operations [#157](https://github.com/salsita/node-pg-migrate/pull/157)

@@ -36,0 +49,0 @@ ## [2.15.0] (2018-01-11)

16

dist/db.js

@@ -16,7 +16,7 @@ 'use strict';

exports.default = function (connection_string) {
exports.default = function (connectionString) {
var log = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : console.error;
var client = new _pg2.default.Client(connection_string);
var client_active = false;
var client = new _pg2.default.Client(connectionString);
var clientActive = false;
var beforeCloseListeners = [];

@@ -26,3 +26,3 @@

return new Promise(function (resolve, reject) {
return client_active ? resolve() : client.connect(function (err) {
return clientActive ? resolve() : client.connect(function (err) {
if (err) {

@@ -32,3 +32,3 @@ log('could not connect to postgres', err);

} else {
client_active = true;
clientActive = true;
resolve();

@@ -79,6 +79,6 @@ }

};
var column = function column(string, column_name) {
var column = function column(string, columnName) {
return select(string).then(function (rows) {
return rows.map(function (r) {
return r[column_name];
return r[columnName];
});

@@ -103,3 +103,3 @@ });

}, Promise.resolve()).then(function () {
client_active = false;
clientActive = false;
if (client) {

@@ -106,0 +106,0 @@ client.end();

@@ -51,8 +51,8 @@ 'use strict';

// file name looks like migrations/1391877300255_migration-title.js
var new_file = _util2.default.format(`%s/%d_%s.${language}`, directory, +new Date(), name);
var newFile = _util2.default.format(`%s/%d_%s.${language}`, directory, +new Date(), name);
// copy the default migration template to the new file location
_fs2.default.createReadStream(_path2.default.resolve(__dirname, `./migration-template.${language}`)).pipe(_fs2.default.createWriteStream(new_file));
_fs2.default.createReadStream(_path2.default.resolve(__dirname, `./migration-template.${language}`)).pipe(_fs2.default.createWriteStream(newFile));
return new Migration(new_file, directory);
return new Migration(newFile, directory);
}

@@ -98,3 +98,3 @@ }]);

}).then(function () {
var sql_steps = pgm.getSqlSteps();
var sqlSteps = pgm.getSqlSteps();

@@ -105,7 +105,7 @@ var schema = (0, _utils.getMigrationTableSchema)(_this.options);

_this.log(`### MIGRATION ${_this.name} (DOWN) ###`);
sql_steps.push(`DELETE FROM "${schema}"."${_this.options.migrations_table}" WHERE name='${_this.name}';`);
sqlSteps.push(`DELETE FROM "${schema}"."${_this.options.migrations_table}" WHERE name='${_this.name}';`);
break;
case _this.up:
_this.log(`### MIGRATION ${_this.name} (UP) ###`);
sql_steps.push(`INSERT INTO "${schema}"."${_this.options.migrations_table}" (name, run_on) VALUES ('${_this.name}', NOW());`);
sqlSteps.push(`INSERT INTO "${schema}"."${_this.options.migrations_table}" (name, run_on) VALUES ('${_this.name}', NOW());`);
break;

@@ -118,4 +118,4 @@ default:

// wrap in a transaction, combine into one sql statement
sql_steps.unshift('BEGIN;');
sql_steps.push('COMMIT;');
sqlSteps.unshift('BEGIN;');
sqlSteps.push('COMMIT;');
} else {

@@ -125,5 +125,5 @@ _this.log('#> WARNING: This migration is not wrapped in a transaction! <');

_this.log(`${sql_steps.join('\n')}\n\n`);
_this.log(`${sqlSteps.join('\n')}\n\n`);
return sql_steps.reduce(function (promise, sql) {
return sqlSteps.reduce(function (promise, sql) {
return promise.then(function () {

@@ -130,0 +130,0 @@ return _this.options.dryRun || _this.db.query(sql);

@@ -10,3 +10,3 @@ 'use strict';

var drop = exports.drop = function drop(domain_name) {
var drop = exports.drop = function drop(domainName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

@@ -16,7 +16,7 @@ ifExists = _ref.ifExists,

return _utils.template`DROP DOMAIN${ifExists ? ' IF EXISTS' : ''} "${domain_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP DOMAIN${ifExists ? ' IF EXISTS' : ''} "${domainName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(domain_name, type, options) {
var create = exports.create = function create(typeShorthands) {
var _create = function _create(domainName, type, options) {
var defaultValue = options.default,

@@ -50,6 +50,6 @@ collation = options.collation,

return _utils.template`CREATE DOMAIN "${domain_name}" AS ${(0, _utils.applyType)(type, type_shorthands).type}${constraintsString};`;
return _utils.template`CREATE DOMAIN "${domainName}" AS ${(0, _utils.applyType)(type, typeShorthands).type}${constraintsString};`;
};
_create.reverse = function (domain_name, type, options) {
return drop(domain_name, options);
_create.reverse = function (domainName, type, options) {
return drop(domainName, options);
};

@@ -59,3 +59,3 @@ return _create;

var alter = exports.alter = function alter(domain_name, options) {
var alter = exports.alter = function alter(domainName, options) {
var defaultValue = options.default,

@@ -83,3 +83,3 @@ notNull = options.notNull,

return `${actions.map(function (action) {
return _utils.template`ALTER DOMAIN "${domain_name}" ${action}`;
return _utils.template`ALTER DOMAIN "${domainName}" ${action}`;
}).join(';\n')};`;

@@ -89,10 +89,10 @@ };

// RENAME
var rename = exports.rename = function rename(domain_name, new_domain_name) {
return _utils.template`ALTER DOMAIN "${domain_name}" RENAME TO "${new_domain_name}";`;
var rename = exports.rename = function rename(domainName, newDomainName) {
return _utils.template`ALTER DOMAIN "${domainName}" RENAME TO "${newDomainName}";`;
};
var undoRename = exports.undoRename = function undoRename(domain_name, new_domain_name) {
return rename(new_domain_name, domain_name);
var undoRename = exports.undoRename = function undoRename(domainName, newDomainName) {
return rename(newDomainName, domainName);
};
rename.reverse = undoRename;

@@ -10,5 +10,5 @@ 'use strict';

var drop = exports.drop = function drop(type_shorthands) {
return function (function_name) {
var function_params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var drop = exports.drop = function drop(typeShorthands) {
return function (functionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

@@ -19,21 +19,21 @@ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

return _utils.template`DROP FUNCTION${ifExists ? ' IF EXISTS' : ''} "${function_name}"${(0, _utils.formatParams)(function_params, type_shorthands)}${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP FUNCTION${ifExists ? ' IF EXISTS' : ''} "${functionName}"${(0, _utils.formatParams)(functionParams, typeShorthands)}${cascade ? ' CASCADE' : ''};`;
};
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(function_name) {
var function_params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var function_options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var create = exports.create = function create(typeShorthands) {
var _create = function _create(functionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var functionOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
var replace = function_options.replace,
_function_options$ret = function_options.returns,
returns = _function_options$ret === undefined ? 'void' : _function_options$ret,
language = function_options.language,
window = function_options.window,
_function_options$beh = function_options.behavior,
behavior = _function_options$beh === undefined ? 'VOLATILE' : _function_options$beh,
onNull = function_options.onNull,
_function_options$par = function_options.parallel,
parallel = _function_options$par === undefined ? 'UNSAFE' : _function_options$par;
var replace = functionOptions.replace,
_functionOptions$retu = functionOptions.returns,
returns = _functionOptions$retu === undefined ? 'void' : _functionOptions$retu,
language = functionOptions.language,
window = functionOptions.window,
_functionOptions$beha = functionOptions.behavior,
behavior = _functionOptions$beha === undefined ? 'VOLATILE' : _functionOptions$beha,
onNull = functionOptions.onNull,
_functionOptions$para = functionOptions.parallel,
parallel = _functionOptions$para === undefined ? 'UNSAFE' : _functionOptions$para;

@@ -47,3 +47,3 @@ var options = [];

} else {
throw new Error(`Language for function ${function_name} have to be specified`);
throw new Error(`Language for function ${functionName} have to be specified`);
}

@@ -60,3 +60,3 @@ if (window) {

return _utils.template`CREATE${replace ? ' OR REPLACE' : ''} FUNCTION "${function_name}"${(0, _utils.formatParams)(function_params, type_shorthands)}
return _utils.template`CREATE${replace ? ' OR REPLACE' : ''} FUNCTION "${functionName}"${(0, _utils.formatParams)(functionParams, typeShorthands)}
RETURNS ${returns}

@@ -67,3 +67,3 @@ AS ${(0, _utils.escapeValue)(definition)}

_create.reverse = drop(type_shorthands);
_create.reverse = drop(typeShorthands);

@@ -73,11 +73,11 @@ return _create;

var rename = exports.rename = function rename(type_shorthands) {
var _rename = function _rename(old_function_name) {
var function_params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var new_function_name = arguments[2];
return _utils.template`ALTER FUNCTION "${old_function_name}"${(0, _utils.formatParams)(function_params, type_shorthands)} RENAME TO "${new_function_name}";`;
var rename = exports.rename = function rename(typeShorthands) {
var _rename = function _rename(oldFunctionName) {
var functionParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var newFunctionName = arguments[2];
return _utils.template`ALTER FUNCTION "${oldFunctionName}"${(0, _utils.formatParams)(functionParams, typeShorthands)} RENAME TO "${newFunctionName}";`;
};
_rename.reverse = function (old_function_name, function_params, new_function_name) {
return _rename(new_function_name, function_params, old_function_name);
_rename.reverse = function (oldFunctionName, functionParams, newFunctionName) {
return _rename(newFunctionName, functionParams, oldFunctionName);
};

@@ -84,0 +84,0 @@

@@ -17,4 +17,4 @@ 'use strict';

function generateIndexName(table, columns, options) {
var table_name = typeof table === 'object' ? table.name : table;
return options.name ? options.name : _utils.template`${table_name}_${_lodash2.default.isArray(columns) ? columns.join('_') : columns}${options.unique ? '_unique' : ''}_index`;
var tableName = typeof table === 'object' ? table.name : table;
return options.name ? options.name : _utils.template`${tableName}_${_lodash2.default.isArray(columns) ? columns.join('_') : columns}${options.unique ? '_unique' : ''}_index`;
}

@@ -32,3 +32,3 @@

var create = exports.create = function create(table_name, columns) {
var create = exports.create = function create(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -45,3 +45,3 @@

*/
var indexName = generateIndexName(table_name, columns, options);
var indexName = generateIndexName(tableName, columns, options);
var columnsString = generateColumnsString(columns);

@@ -53,6 +53,6 @@ var unique = options.unique ? ' UNIQUE ' : '';

return _utils.template`CREATE ${unique} INDEX ${concurrently} "${indexName}" ON "${table_name}"${method} (${columnsString})${where};`;
return _utils.template`CREATE ${unique} INDEX ${concurrently} "${indexName}" ON "${tableName}"${method} (${columnsString})${where};`;
};
var drop = exports.drop = function drop(table_name, columns) {
var drop = exports.drop = function drop(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -63,3 +63,3 @@ var concurrently = options.concurrently,

return `DROP INDEX${concurrently ? ' CONCURRENTLY' : ''}${ifExists ? ' IF EXISTS' : ''} "${generateIndexName(table_name, columns, options)}"${cascade ? ' CASCADE' : ''};`;
return `DROP INDEX${concurrently ? ' CONCURRENTLY' : ''}${ifExists ? ' IF EXISTS' : ''} "${generateIndexName(tableName, columns, options)}"${cascade ? ' CASCADE' : ''};`;
};

@@ -66,0 +66,0 @@

@@ -10,3 +10,3 @@ 'use strict';

var createOperator = exports.createOperator = function createOperator(operator_name) {
var createOperator = exports.createOperator = function createOperator(operatorName) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -50,6 +50,6 @@ var procedure = options.procedure,

}
return `CREATE OPERATOR ${(0, _utils.opSchemalize)(operator_name)} (${defs.join(', ')});`;
return `CREATE OPERATOR ${(0, _utils.opSchemalize)(operatorName)} (${defs.join(', ')});`;
};
var dropOperator = exports.dropOperator = function dropOperator(operator_name) {
var dropOperator = exports.dropOperator = function dropOperator(operatorName) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -65,10 +65,10 @@ var ifExists = options.ifExists,

return `DROP OPERATOR${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.opSchemalize)(operator_name)}(${(0, _utils.schemalize)(leftType)}, ${(0, _utils.schemalize)(rightType)})${cascade ? ' CASCADE' : ''};`;
return `DROP OPERATOR${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.opSchemalize)(operatorName)}(${(0, _utils.schemalize)(leftType)}, ${(0, _utils.schemalize)(rightType)})${cascade ? ' CASCADE' : ''};`;
};
var createOperatorFamily = exports.createOperatorFamily = function createOperatorFamily(operator_family_name, index_method) {
return `CREATE OPERATOR FAMILY ${(0, _utils.schemalize)(operator_family_name)} USING ${index_method};`;
var createOperatorFamily = exports.createOperatorFamily = function createOperatorFamily(operatorFamilyName, indexMethod) {
return `CREATE OPERATOR FAMILY ${(0, _utils.schemalize)(operatorFamilyName)} USING ${indexMethod};`;
};
var dropOperatorFamily = exports.dropOperatorFamily = function dropOperatorFamily(operator_family_name, index_method) {
var dropOperatorFamily = exports.dropOperatorFamily = function dropOperatorFamily(operatorFamilyName, indexMethod) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

@@ -79,7 +79,7 @@ ifExists = _ref.ifExists,

return (// eslint-disable-line max-len
`DROP OPERATOR FAMILY ${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.schemalize)(operator_family_name)} USING ${index_method}${cascade ? ' CASCADE' : ''};`
`DROP OPERATOR FAMILY ${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.schemalize)(operatorFamilyName)} USING ${indexMethod}${cascade ? ' CASCADE' : ''};`
);
};
var operatorMap = function operatorMap(type_shorthands) {
var operatorMap = function operatorMap(typeShorthands) {
return function (_ref2) {

@@ -97,5 +97,5 @@ var _ref2$type = _ref2.type,

}
return `OPERATOR ${number} ${(0, _utils.opSchemalize)(name)}${params.length > 0 ? (0, _utils.formatParams)(params, type_shorthands) : ''}`;
return `OPERATOR ${number} ${(0, _utils.opSchemalize)(name)}${params.length > 0 ? (0, _utils.formatParams)(params, typeShorthands) : ''}`;
} else if (String(type).toLowerCase() === 'operator') {
return `FUNCTION ${number} ${(0, _utils.schemalize)(name)}${(0, _utils.formatParams)(params, type_shorthands)}`;
return `FUNCTION ${number} ${(0, _utils.schemalize)(name)}${(0, _utils.formatParams)(params, typeShorthands)}`;
}

@@ -106,31 +106,31 @@ throw new Error('Operator "type" must be either "function" or "operator"');

var removeFromOperatorFamily = exports.removeFromOperatorFamily = function removeFromOperatorFamily(type_shorthands) {
return function (operator_family_name, index_method, operator_list) {
return `ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(operator_family_name)} USING ${index_method} DROP
${operator_list.map(operatorMap(type_shorthands)).join(',\n ')};`;
var removeFromOperatorFamily = exports.removeFromOperatorFamily = function removeFromOperatorFamily(typeShorthands) {
return function (operatorFamilyName, indexMethod, operatorList) {
return `ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(operatorFamilyName)} USING ${indexMethod} DROP
${operatorList.map(operatorMap(typeShorthands)).join(',\n ')};`;
};
};
var addToOperatorFamily = exports.addToOperatorFamily = function addToOperatorFamily(type_shorthands) {
var _add = function _add(operator_family_name, index_method, operator_list) {
return `ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(operator_family_name)} USING ${index_method} ADD
${operator_list.map(operatorMap(type_shorthands)).join(',\n ')};`;
var addToOperatorFamily = exports.addToOperatorFamily = function addToOperatorFamily(typeShorthands) {
var _add = function _add(operatorFamilyName, indexMethod, operatorList) {
return `ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(operatorFamilyName)} USING ${indexMethod} ADD
${operatorList.map(operatorMap(typeShorthands)).join(',\n ')};`;
};
_add.reverse = removeFromOperatorFamily(type_shorthands);
_add.reverse = removeFromOperatorFamily(typeShorthands);
return _add;
};
var renameOperatorFamily = exports.renameOperatorFamily = function renameOperatorFamily(old_operator_family_name, index_method, new_operator_family_name) {
var renameOperatorFamily = exports.renameOperatorFamily = function renameOperatorFamily(oldOperatorFamilyName, indexMethod, newOperatorFamilyName) {
return (// eslint-disable-line max-len
`ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(old_operator_family_name)} USING ${index_method} RENAME TO ${(0, _utils.schemalize)(new_operator_family_name)};`
`ALTER OPERATOR FAMILY ${(0, _utils.schemalize)(oldOperatorFamilyName)} USING ${indexMethod} RENAME TO ${(0, _utils.schemalize)(newOperatorFamilyName)};`
);
};
var undoRenameOperatorFamily = function undoRenameOperatorFamily(old_operator_family_name, index_method, new_operator_family_name) {
var undoRenameOperatorFamily = function undoRenameOperatorFamily(oldOperatorFamilyName, indexMethod, newOperatorFamilyName) {
return (// eslint-disable-line max-len
renameOperatorFamily(new_operator_family_name, index_method, old_operator_family_name)
renameOperatorFamily(newOperatorFamilyName, indexMethod, oldOperatorFamilyName)
);
};
var dropOperatorClass = exports.dropOperatorClass = function dropOperatorClass(operator_class_name, index_method) {
var dropOperatorClass = exports.dropOperatorClass = function dropOperatorClass(operatorClassName, indexMethod) {
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

@@ -141,16 +141,16 @@ ifExists = _ref3.ifExists,

return (// eslint-disable-line max-len
`DROP OPERATOR CLASS ${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.schemalize)(operator_class_name)} USING ${index_method}${cascade ? ' CASCADE' : ''};`
`DROP OPERATOR CLASS ${ifExists ? ' IF EXISTS' : ''} ${(0, _utils.schemalize)(operatorClassName)} USING ${indexMethod}${cascade ? ' CASCADE' : ''};`
);
};
var createOperatorClass = exports.createOperatorClass = function createOperatorClass(type_shorthands) {
var _create = function _create(operator_class_name, type, index_method, operator_list, options) {
var createOperatorClass = exports.createOperatorClass = function createOperatorClass(typeShorthands) {
var _create = function _create(operatorClassName, type, indexMethod, operatorList, options) {
var isDefault = options.default,
family = options.family;
return `CREATE OPERATOR CLASS ${(0, _utils.schemalize)(operator_class_name)}${isDefault ? ' DEFAULT' : ''} FOR TYPE ${(0, _utils.schemalize)((0, _utils.applyType)(type).type)} USING ${(0, _utils.schemalize)(index_method)} ${family ? ` FAMILY ${family}` : ''} AS
${operator_list.map(operatorMap(type_shorthands)).join(',\n ')};`;
return `CREATE OPERATOR CLASS ${(0, _utils.schemalize)(operatorClassName)}${isDefault ? ' DEFAULT' : ''} FOR TYPE ${(0, _utils.schemalize)((0, _utils.applyType)(type).type)} USING ${(0, _utils.schemalize)(indexMethod)} ${family ? ` FAMILY ${family}` : ''} AS
${operatorList.map(operatorMap(typeShorthands)).join(',\n ')};`;
};
_create.reverse = function (operator_class_name, type, index_method, operator_list, options) {
return dropOperatorClass(operator_class_name, index_method, options);
_create.reverse = function (operatorClassName, type, indexMethod, operatorList, options) {
return dropOperatorClass(operatorClassName, indexMethod, options);
};

@@ -160,11 +160,11 @@ return _create;

var renameOperatorClass = exports.renameOperatorClass = function renameOperatorClass(old_operator_class_name, index_method, new_operator_class_name) {
var renameOperatorClass = exports.renameOperatorClass = function renameOperatorClass(oldOperatorClassName, indexMethod, newOperatorClassName) {
return (// eslint-disable-line max-len
`ALTER OPERATOR CLASS ${(0, _utils.schemalize)(old_operator_class_name)} USING ${index_method} RENAME TO ${(0, _utils.schemalize)(new_operator_class_name)};`
`ALTER OPERATOR CLASS ${(0, _utils.schemalize)(oldOperatorClassName)} USING ${indexMethod} RENAME TO ${(0, _utils.schemalize)(newOperatorClassName)};`
);
};
var undoRenameOperatorClass = function undoRenameOperatorClass(old_operator_class_name, index_method, new_operator_class_name) {
var undoRenameOperatorClass = function undoRenameOperatorClass(oldOperatorClassName, indexMethod, newOperatorClassName) {
return (// eslint-disable-line max-len
renameOperatorClass(new_operator_class_name, index_method, old_operator_class_name)
renameOperatorClass(newOperatorClassName, indexMethod, oldOperatorClassName)
);

@@ -171,0 +171,0 @@ };

@@ -13,31 +13,31 @@ 'use strict';

var formatRoleOptions = function formatRoleOptions() {
var role_options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var roleOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var options = [];
options.push(role_options.superuser ? 'SUPERUSER' : 'NOSUPERUSER');
options.push(role_options.createdb ? 'CREATEDB' : 'NOCREATEDB');
options.push(role_options.createrole ? 'CREATEROLE' : 'NOCREATEROLE');
options.push(!role_options.inherit ? 'NOINHERIT' : 'INHERIT');
options.push(role_options.login ? 'LOGIN' : 'NOLOGIN');
options.push(role_options.replication ? 'REPLICATION' : 'NOREPLICATION');
if (role_options.bypassrls !== undefined) {
options.push(role_options.bypassrls ? 'BYPASSRLS' : 'NOBYPASSRLS');
options.push(roleOptions.superuser ? 'SUPERUSER' : 'NOSUPERUSER');
options.push(roleOptions.createdb ? 'CREATEDB' : 'NOCREATEDB');
options.push(roleOptions.createrole ? 'CREATEROLE' : 'NOCREATEROLE');
options.push(!roleOptions.inherit ? 'NOINHERIT' : 'INHERIT');
options.push(roleOptions.login ? 'LOGIN' : 'NOLOGIN');
options.push(roleOptions.replication ? 'REPLICATION' : 'NOREPLICATION');
if (roleOptions.bypassrls !== undefined) {
options.push(roleOptions.bypassrls ? 'BYPASSRLS' : 'NOBYPASSRLS');
}
if (role_options.limit) {
options.push(`CONNECTION LIMIT ${Number(role_options.limit)}`);
if (roleOptions.limit) {
options.push(`CONNECTION LIMIT ${Number(roleOptions.limit)}`);
}
if (role_options.password) {
options.push(`${!role_options.encrypted ? 'UNENCRYPTED' : 'ENCRYPTED'} PASSWORD ${(0, _utils.escapeValue)(role_options.password)}`);
if (roleOptions.password) {
options.push(`${!roleOptions.encrypted ? 'UNENCRYPTED' : 'ENCRYPTED'} PASSWORD ${(0, _utils.escapeValue)(roleOptions.password)}`);
}
if (role_options.valid) {
options.push(`VALID UNTIL ${(0, _utils.escapeValue)(role_options.valid)}`);
if (roleOptions.valid) {
options.push(`VALID UNTIL ${(0, _utils.escapeValue)(roleOptions.valid)}`);
}
if (role_options.inRole) {
options.push(`IN ROLE ${(0, _lodash.isArray)(role_options.inRole) ? role_options.inRole.join(',') : role_options.inRole}`);
if (roleOptions.inRole) {
options.push(`IN ROLE ${(0, _lodash.isArray)(roleOptions.inRole) ? roleOptions.inRole.join(',') : roleOptions.inRole}`);
}
if (role_options.role) {
options.push(`ROLE ${(0, _lodash.isArray)(role_options.role) ? role_options.role.join(',') : role_options.role}`);
if (roleOptions.role) {
options.push(`ROLE ${(0, _lodash.isArray)(roleOptions.role) ? roleOptions.role.join(',') : roleOptions.role}`);
}
if (role_options.admin) {
options.push(`ADMIN ${(0, _lodash.isArray)(role_options.admin) ? role_options.admin.join(',') : role_options.admin}`);
if (roleOptions.admin) {
options.push(`ADMIN ${(0, _lodash.isArray)(roleOptions.admin) ? roleOptions.admin.join(',') : roleOptions.admin}`);
}

@@ -48,29 +48,29 @@

var create = exports.create = function create(role_name) {
var role_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var create = exports.create = function create(roleName) {
var roleOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = formatRoleOptions(role_options);
return _utils.template`CREATE ROLE "${role_name}"${options ? ` WITH ${options}` : ''};`;
var options = formatRoleOptions(roleOptions);
return _utils.template`CREATE ROLE "${roleName}"${options ? ` WITH ${options}` : ''};`;
};
var drop = exports.drop = function drop(role_name) {
var drop = exports.drop = function drop(roleName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
ifExists = _ref.ifExists;
return _utils.template`DROP ROLE${ifExists ? ' IF EXISTS' : ''} "${role_name}";`;
return _utils.template`DROP ROLE${ifExists ? ' IF EXISTS' : ''} "${roleName}";`;
};
var alter = exports.alter = function alter(role_name) {
var role_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var alter = exports.alter = function alter(roleName) {
var roleOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var options = formatRoleOptions(role_options);
return _utils.template`ALTER ROLE "${role_name}"${options ? ` WITH ${options}` : ''};`;
var options = formatRoleOptions(roleOptions);
return _utils.template`ALTER ROLE "${roleName}"${options ? ` WITH ${options}` : ''};`;
};
var rename = exports.rename = function rename(old_role_name, new_role_name) {
return _utils.template`ALTER ROLE "${old_role_name}" RENAME TO "${new_role_name}";`;
var rename = exports.rename = function rename(oldRoleName, newRoleName) {
return _utils.template`ALTER ROLE "${oldRoleName}" RENAME TO "${newRoleName}";`;
};
var undoRename = exports.undoRename = function undoRename(old_role_name, new_role_name) {
return rename(new_role_name, old_role_name);
var undoRename = exports.undoRename = function undoRename(oldRoleName, newRoleName) {
return rename(newRoleName, oldRoleName);
};

@@ -77,0 +77,0 @@

@@ -10,3 +10,3 @@ 'use strict';

var drop = exports.drop = function drop(schema_name) {
var drop = exports.drop = function drop(schemaName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

@@ -16,19 +16,19 @@ ifExists = _ref.ifExists,

return _utils.template`DROP SCHEMA${ifExists ? ' IF EXISTS' : ''} "${schema_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP SCHEMA${ifExists ? ' IF EXISTS' : ''} "${schemaName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(schema_name, options) {
var create = exports.create = function create(schemaName, options) {
var ifNotExists = options.ifNotExists,
authorization = options.authorization;
return _utils.template`CREATE SCHEMA${ifNotExists ? ' IF NOT EXISTS' : ''} "${schema_name}"${authorization ? ` AUTHORIZATION ${authorization}` : ''};`;
return _utils.template`CREATE SCHEMA${ifNotExists ? ' IF NOT EXISTS' : ''} "${schemaName}"${authorization ? ` AUTHORIZATION ${authorization}` : ''};`;
};
// RENAME
var rename = exports.rename = function rename(schema_name, new_schema_name) {
return _utils.template`ALTER SCHEMA "${schema_name}" RENAME TO "${new_schema_name}";`;
var rename = exports.rename = function rename(schemaName, newSchemaName) {
return _utils.template`ALTER SCHEMA "${schemaName}" RENAME TO "${newSchemaName}";`;
};
var undoRename = exports.undoRename = function undoRename(schema_name, new_schema_name) {
return rename(new_schema_name, schema_name);
var undoRename = exports.undoRename = function undoRename(schemaName, newSchemaName) {
return rename(newSchemaName, schemaName);
};

@@ -35,0 +35,0 @@

@@ -10,3 +10,3 @@ 'use strict';

var parseOptions = function parseOptions(type_shorthands, options) {
var parseOptions = function parseOptions(typeShorthands, options) {
var type = options.type,

@@ -23,3 +23,3 @@ increment = options.increment,

if (type) {
clauses.push(`AS ${(0, _utils.applyType)(type, type_shorthands).type}`);
clauses.push(`AS ${(0, _utils.applyType)(type, typeShorthands).type}`);
}

@@ -58,3 +58,3 @@ if (increment) {

var drop = exports.drop = function drop(sequence_name) {
var drop = exports.drop = function drop(sequenceName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

@@ -64,12 +64,12 @@ ifExists = _ref.ifExists,

return _utils.template`DROP SEQUENCE${ifExists ? ' IF EXISTS' : ''} "${sequence_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP SEQUENCE${ifExists ? ' IF EXISTS' : ''} "${sequenceName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(sequence_name, options) {
var create = exports.create = function create(typeShorthands) {
var _create = function _create(sequenceName, options) {
var temporary = options.temporary,
ifNotExists = options.ifNotExists;
var clauses = parseOptions(type_shorthands, options);
return _utils.template`CREATE${temporary ? ' TEMPORARY' : ''} SEQUENCE${ifNotExists ? ' IF NOT EXISTS' : ''} "${sequence_name}"
var clauses = parseOptions(typeShorthands, options);
return _utils.template`CREATE${temporary ? ' TEMPORARY' : ''} SEQUENCE${ifNotExists ? ' IF NOT EXISTS' : ''} "${sequenceName}"
${clauses.join('\n ')};`;

@@ -81,7 +81,7 @@ };

var alter = exports.alter = function alter(type_shorthands) {
return function (sequence_name, options) {
var alter = exports.alter = function alter(typeShorthands) {
return function (sequenceName, options) {
var restart = options.restart;
var clauses = parseOptions(type_shorthands, options);
var clauses = parseOptions(typeShorthands, options);
if (restart) {

@@ -94,3 +94,3 @@ if (restart === true) {

}
return _utils.template`ALTER SEQUENCE "${sequence_name}"
return _utils.template`ALTER SEQUENCE "${sequenceName}"
${clauses.join('\n ')};`;

@@ -101,10 +101,10 @@ };

// RENAME
var rename = exports.rename = function rename(sequence_name, new_sequence_name) {
return _utils.template`ALTER SEQUENCE "${sequence_name}" RENAME TO "${new_sequence_name}";`;
var rename = exports.rename = function rename(sequenceName, newSequenceName) {
return _utils.template`ALTER SEQUENCE "${sequenceName}" RENAME TO "${newSequenceName}";`;
};
var undoRename = exports.undoRename = function undoRename(sequence_name, new_sequence_name) {
return rename(new_sequence_name, sequence_name);
var undoRename = exports.undoRename = function undoRename(sequenceName, newSequenceName) {
return rename(newSequenceName, sequenceName);
};
rename.reverse = undoRename;

@@ -27,4 +27,3 @@ 'use strict';

var references = options.references,
_options$match = options.match,
match = _options$match === undefined ? 'SIMPLE' : _options$match,
match = options.match,
onDelete = options.onDelete,

@@ -54,10 +53,10 @@ onUpdate = options.onUpdate;

var parseColumns = function parseColumns(columns) {
var extending_type_shorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var extendingTypeShorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var columnsWithOptions = _lodash2.default.mapValues(columns, function (column) {
return (0, _utils.applyType)(column, extending_type_shorthands);
return (0, _utils.applyType)(column, extendingTypeShorthands);
});
var primaryColumns = _lodash2.default.chain(columnsWithOptions).map(function (options, column_name) {
return options.primaryKey ? column_name : null;
var primaryColumns = _lodash2.default.chain(columnsWithOptions).map(function (options, columnName) {
return options.primaryKey ? columnName : null;
}).filter().value();

@@ -73,3 +72,3 @@ var multiplePrimaryColumns = primaryColumns.length > 1;

return {
columns: _lodash2.default.map(columnsWithOptions, function (options, column_name) {
columns: _lodash2.default.map(columnsWithOptions, function (options, columnName) {
var type = options.type,

@@ -113,3 +112,3 @@ collation = options.collation,

return _utils.template`"${column_name}" ${type}${constraintsString}`;
return _utils.template`"${columnName}" ${type}${constraintsString}`;
}),

@@ -128,6 +127,6 @@ constraints: _extends({}, multiplePrimaryColumns ? { primaryKey: primaryColumns } : {})

var table_name = typeof table === 'object' ? table.name : table;
var tableName = typeof table === 'object' ? table.name : table;
var constraints = [];
if (check) {
constraints.push(`CONSTRAINT "${table_name}_chck" CHECK (${check})`);
constraints.push(`CONSTRAINT "${tableName}_chck" CHECK (${check})`);
}

@@ -141,10 +140,10 @@ if (unique) {

uniqueArray.forEach(function (uniqueSet, i) {
return constraints.push(`CONSTRAINT "${table_name}_uniq_${i + 1}" UNIQUE (${(0, _utils.quote)(_lodash2.default.isArray(uniqueSet) ? uniqueSet : [uniqueSet]).join(', ')})`);
return constraints.push(`CONSTRAINT "${tableName}_uniq_${i + 1}" UNIQUE (${(0, _utils.quote)(_lodash2.default.isArray(uniqueSet) ? uniqueSet : [uniqueSet]).join(', ')})`);
});
} else {
constraints.push(`CONSTRAINT "${table_name}_uniq" UNIQUE (${(0, _utils.quote)(uniqueArray).join(', ')})`);
constraints.push(`CONSTRAINT "${tableName}_uniq" UNIQUE (${(0, _utils.quote)(uniqueArray).join(', ')})`);
}
}
if (primaryKey) {
constraints.push(`CONSTRAINT "${table_name}_pkey" PRIMARY KEY (${(0, _utils.quote)(_lodash2.default.isArray(primaryKey) ? primaryKey : [primaryKey]).join(', ')})`);
constraints.push(`CONSTRAINT "${tableName}_pkey" PRIMARY KEY (${(0, _utils.quote)(_lodash2.default.isArray(primaryKey) ? primaryKey : [primaryKey]).join(', ')})`);
}

@@ -159,3 +158,3 @@ if (foreignKeys) {

if (exclude) {
constraints.push(`CONSTRAINT "${table_name}_excl" EXCLUDE ${exclude}`);
constraints.push(`CONSTRAINT "${tableName}_excl" EXCLUDE ${exclude}`);
}

@@ -170,3 +169,3 @@ if (deferrable) {

// TABLE
var drop = exports.drop = function drop(table_name) {
var drop = exports.drop = function drop(tableName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

@@ -176,7 +175,7 @@ ifExists = _ref.ifExists,

return _utils.template`DROP TABLE${ifExists ? ' IF EXISTS' : ''} "${table_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP TABLE${ifExists ? ' IF EXISTS' : ''} "${tableName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(table_name, columns) {
var create = exports.create = function create(typeShorthands) {
var _create = function _create(tableName, columns) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -190,3 +189,3 @@ var temporary = options.temporary,

var _parseColumns = parseColumns(columns, type_shorthands),
var _parseColumns = parseColumns(columns, typeShorthands),
columnLines = _parseColumns.columns,

@@ -201,6 +200,6 @@ columnsConstraints = _parseColumns.constraints;

var constraints = _extends({}, optionsConstraints, columnsConstraints);
var constraintLines = parseConstraints(table_name, constraints);
var constraintLines = parseConstraints(tableName, constraints);
var tableDefinition = [].concat(_toConsumableArray(columnLines), _toConsumableArray(constraintLines)).concat(like ? [_utils.template`LIKE "${like}"`] : []);
return _utils.template`CREATE TABLE${temporary ? ' TEMPORARY' : ''}${ifNotExists ? ' IF NOT EXISTS' : ''} "${table_name}" (
return _utils.template`CREATE TABLE${temporary ? ' TEMPORARY' : ''}${ifNotExists ? ' IF NOT EXISTS' : ''} "${tableName}" (
${formatLines(tableDefinition, ' ')}

@@ -214,3 +213,3 @@ )${inherits ? _utils.template` INHERITS "${inherits}"` : ''};`;

// COLUMNS
var dropColumns = exports.dropColumns = function dropColumns(table_name, columns) {
var dropColumns = exports.dropColumns = function dropColumns(tableName, columns) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

@@ -225,12 +224,12 @@ ifExists = _ref2.ifExists,

}
return _utils.template`ALTER TABLE "${table_name}"
return _utils.template`ALTER TABLE "${tableName}"
${formatLines((0, _utils.quote)(columns), ` DROP ${ifExists ? ' IF EXISTS' : ''}`, `${cascade ? ' CASCADE' : ''},\n`)};`;
};
var addColumns = exports.addColumns = function addColumns(type_shorthands) {
var _add = function _add(table_name, columns) {
var _parseColumns2 = parseColumns(columns, type_shorthands),
var addColumns = exports.addColumns = function addColumns(typeShorthands) {
var _add = function _add(tableName, columns) {
var _parseColumns2 = parseColumns(columns, typeShorthands),
columnLines = _parseColumns2.columns;
return _utils.template`ALTER TABLE "${table_name}"\n${formatLines(columnLines, ' ADD ')};`;
return _utils.template`ALTER TABLE "${tableName}"\n${formatLines(columnLines, ' ADD ')};`;
};

@@ -241,3 +240,3 @@ _add.reverse = dropColumns;

var alterColumn = exports.alterColumn = function alterColumn(table_name, column_name, options) {
var alterColumn = exports.alterColumn = function alterColumn(tableName, columnName, options) {
var defaultValue = options.default,

@@ -265,36 +264,36 @@ type = options.type,

return _utils.template`ALTER TABLE "${table_name}"\n${formatLines(actions, ` ALTER "${column_name}" `)};`;
return _utils.template`ALTER TABLE "${tableName}"\n${formatLines(actions, ` ALTER "${columnName}" `)};`;
};
// RENAME
var renameTable = exports.renameTable = function renameTable(table_name, new_name) {
return _utils.template`ALTER TABLE "${table_name}" RENAME TO "${new_name}";`;
var renameTable = exports.renameTable = function renameTable(tableName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME TO "${newName}";`;
};
var undoRenameTable = exports.undoRenameTable = function undoRenameTable(table_name, new_name) {
return renameTable(new_name, table_name);
var undoRenameTable = exports.undoRenameTable = function undoRenameTable(tableName, newName) {
return renameTable(newName, tableName);
};
var renameColumn = exports.renameColumn = function renameColumn(table_name, column_name, new_name) {
return _utils.template`ALTER TABLE "${table_name}" RENAME "${column_name}" TO "${new_name}";`;
var renameColumn = exports.renameColumn = function renameColumn(tableName, columnName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME "${columnName}" TO "${newName}";`;
};
var undoRenameColumn = exports.undoRenameColumn = function undoRenameColumn(table_name, column_name, new_name) {
return renameColumn(table_name, new_name, column_name);
var undoRenameColumn = exports.undoRenameColumn = function undoRenameColumn(tableName, columnName, newName) {
return renameColumn(tableName, newName, columnName);
};
var renameConstraint = exports.renameConstraint = function renameConstraint(table_name, constraint_name, new_name) {
return _utils.template`ALTER TABLE "${table_name}" RENAME CONSTRAINT "${constraint_name}" TO "${new_name}";`;
var renameConstraint = exports.renameConstraint = function renameConstraint(tableName, constraintName, newName) {
return _utils.template`ALTER TABLE "${tableName}" RENAME CONSTRAINT "${constraintName}" TO "${newName}";`;
};
var undoRenameConstraint = exports.undoRenameConstraint = function undoRenameConstraint(table_name, constraint_name, new_name) {
return renameConstraint(table_name, new_name, constraint_name);
var undoRenameConstraint = exports.undoRenameConstraint = function undoRenameConstraint(tableName, constraintName, newName) {
return renameConstraint(tableName, newName, constraintName);
};
// CONSTRAINTS -- only supports named check constraints
var addConstraint = exports.addConstraint = function addConstraint(table_name, constraint_name, expression) {
return _utils.template`ALTER TABLE "${table_name}" ADD${constraint_name ? ` CONSTRAINT "${constraint_name}"` : ''} ${typeof expression === 'string' ? expression : parseConstraints(table_name, expression)};`;
var addConstraint = exports.addConstraint = function addConstraint(tableName, constraintName, expression) {
return _utils.template`ALTER TABLE "${tableName}" ADD${constraintName ? ` CONSTRAINT "${constraintName}"` : ''} ${typeof expression === 'string' ? expression : parseConstraints(tableName, expression)};`;
};
var dropConstraint = exports.dropConstraint = function dropConstraint(table_name, constraint_name) {
var dropConstraint = exports.dropConstraint = function dropConstraint(tableName, constraintName) {
var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

@@ -304,3 +303,3 @@ ifExists = _ref3.ifExists,

return _utils.template`ALTER TABLE "${table_name}" DROP CONSTRAINT${ifExists ? ' IF EXISTS' : ''} "${constraint_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`ALTER TABLE "${tableName}" DROP CONSTRAINT${ifExists ? ' IF EXISTS' : ''} "${constraintName}"${cascade ? ' CASCADE' : ''};`;
};

@@ -307,0 +306,0 @@

@@ -16,3 +16,3 @@ 'use strict';

var drop = exports.drop = function drop(table_name, trigger_name) {
var drop = exports.drop = function drop(tableName, triggerName) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},

@@ -22,18 +22,18 @@ ifExists = _ref.ifExists,

return _utils.template`DROP TRIGGER${ifExists ? ' IF EXISTS' : ''} "${trigger_name}" ON "${table_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP TRIGGER${ifExists ? ' IF EXISTS' : ''} "${triggerName}" ON "${tableName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(table_name, trigger_name) {
var trigger_options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var create = exports.create = function create(typeShorthands) {
var _create = function _create(tableName, triggerName) {
var triggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
var constraint = trigger_options.constraint,
condition = trigger_options.condition,
operation = trigger_options.operation,
deferrable = trigger_options.deferrable,
deferred = trigger_options.deferred;
var when = trigger_options.when,
_trigger_options$leve = trigger_options.level,
level = _trigger_options$leve === undefined ? 'STATEMENT' : _trigger_options$leve,
functionName = trigger_options.function;
var constraint = triggerOptions.constraint,
condition = triggerOptions.condition,
operation = triggerOptions.operation,
deferrable = triggerOptions.deferrable,
deferred = triggerOptions.deferred;
var when = triggerOptions.when,
_triggerOptions$level = triggerOptions.level,
level = _triggerOptions$level === undefined ? 'STATEMENT' : _triggerOptions$level,
functionName = triggerOptions.function;

@@ -49,3 +49,3 @@ var operations = (0, _lodash.isArray)(operation) ? operation.join(' OR ') : operation;

if (definition) {
functionName = functionName || trigger_name;
functionName = functionName || triggerName;
}

@@ -65,14 +65,14 @@

var triggerSQL = _utils.template`CREATE${constraint ? ' CONSTRAINT' : ''} TRIGGER "${trigger_name}"
${when} ${operations} ON "${table_name}"
var triggerSQL = _utils.template`CREATE${constraint ? ' CONSTRAINT' : ''} TRIGGER "${triggerName}"
${when} ${operations} ON "${tableName}"
${defferClause}FOR EACH ${level}
${conditionClause}EXECUTE PROCEDURE "${functionName}"();`;
return `${definition ? `${(0, _functions.create)(type_shorthands)(functionName, [], _extends({}, trigger_options, { returns: 'trigger' }), definition)}\n` : ''}${triggerSQL}`;
return `${definition ? `${(0, _functions.create)(typeShorthands)(functionName, [], _extends({}, triggerOptions, { returns: 'trigger' }), definition)}\n` : ''}${triggerSQL}`;
};
_create.reverse = function (table_name, trigger_name) {
var trigger_options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
_create.reverse = function (tableName, triggerName) {
var triggerOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var definition = arguments[3];
return `${drop(table_name, trigger_name, trigger_options)}${definition ? `\n${(0, _functions.drop)(type_shorthands)(trigger_options.function || trigger_name, [], trigger_options)}` : ''}`;
return `${drop(tableName, triggerName, triggerOptions)}${definition ? `\n${(0, _functions.drop)(typeShorthands)(triggerOptions.function || triggerName, [], triggerOptions)}` : ''}`;
};

@@ -83,10 +83,10 @@

var rename = exports.rename = function rename(table_name, old_trigger_name, new_trigger_name) {
return _utils.template`ALTER TRIGGER "${old_trigger_name}" ON "${table_name}" RENAME TO "${new_trigger_name}";`;
var rename = exports.rename = function rename(tableName, oldTriggerName, newTriggerName) {
return _utils.template`ALTER TRIGGER "${oldTriggerName}" ON "${tableName}" RENAME TO "${newTriggerName}";`;
};
var undoRename = exports.undoRename = function undoRename(table_name, old_trigger_name, new_trigger_name) {
return rename(table_name, new_trigger_name, old_trigger_name);
var undoRename = exports.undoRename = function undoRename(tableName, oldTriggerName, newTriggerName) {
return rename(tableName, newTriggerName, oldTriggerName);
};
rename.reverse = undoRename;

@@ -16,3 +16,3 @@ 'use strict';

var drop = exports.drop = function drop(type_name) {
var drop = exports.drop = function drop(typeName) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},

@@ -22,14 +22,14 @@ ifExists = _ref.ifExists,

return _utils.template`DROP TYPE${ifExists ? ' IF EXISTS' : ''} "${type_name}"${cascade ? ' CASCADE' : ''};`;
return _utils.template`DROP TYPE${ifExists ? ' IF EXISTS' : ''} "${typeName}"${cascade ? ' CASCADE' : ''};`;
};
var create = exports.create = function create(type_shorthands) {
var _create = function _create(type_name, options) {
var create = exports.create = function create(typeShorthands) {
var _create = function _create(typeName, options) {
if (_lodash2.default.isArray(options)) {
return _utils.template`CREATE TYPE "${type_name}" AS ENUM (${options.map(_utils.escapeValue).join(', ')});`;
return _utils.template`CREATE TYPE "${typeName}" AS ENUM (${options.map(_utils.escapeValue).join(', ')});`;
}
var attributes = _lodash2.default.map(options, function (attribute, attribute_name) {
return _utils.template`"${attribute_name}" ${(0, _utils.applyType)(attribute, type_shorthands).type}`;
var attributes = _lodash2.default.map(options, function (attribute, attributeName) {
return _utils.template`"${attributeName}" ${(0, _utils.applyType)(attribute, typeShorthands).type}`;
}).join(',\n');
return _utils.template`CREATE TYPE "${type_name}" AS (\n${attributes}\n);`;
return _utils.template`CREATE TYPE "${typeName}" AS (\n${attributes}\n);`;
};

@@ -40,12 +40,12 @@ _create.reverse = drop;

var dropTypeAttribute = exports.dropTypeAttribute = function dropTypeAttribute(type_name, attribute_name) {
var dropTypeAttribute = exports.dropTypeAttribute = function dropTypeAttribute(typeName, attributeName) {
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
ifExists = _ref2.ifExists;
return _utils.template`ALTER TYPE "${type_name}" DROP ATTRIBUTE "${attribute_name}"${ifExists ? ' IF EXISTS' : ''};`;
return _utils.template`ALTER TYPE "${typeName}" DROP ATTRIBUTE "${attributeName}"${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};`;
var addTypeAttribute = exports.addTypeAttribute = function addTypeAttribute(typeShorthands) {
var _alterAttributeAdd = function _alterAttributeAdd(typeName, attributeName, attributeType) {
return _utils.template`ALTER TYPE "${typeName}" ADD ATTRIBUTE "${attributeName}" ${(0, _utils.applyType)(attributeType, typeShorthands).type};`;
};

@@ -56,9 +56,9 @@ _alterAttributeAdd.reverse = dropTypeAttribute;

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 setTypeAttribute = exports.setTypeAttribute = function setTypeAttribute(typeShorthands) {
return function (typeName, attributeName, attributeType) {
return _utils.template`ALTER TYPE "${typeName}" ALTER ATTRIBUTE "${attributeName}" SET DATA TYPE ${(0, _utils.applyType)(attributeType, typeShorthands).type};`;
};
};
var addTypeValue = exports.addTypeValue = function addTypeValue(type_name, value) {
var addTypeValue = exports.addTypeValue = function addTypeValue(typeName, value) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -76,20 +76,20 @@ var ifNotExists = options.ifNotExists,

return _utils.template`ALTER TYPE "${type_name}" ADD VALUE${ifNotExists ? ' IF NOT EXISTS' : ''} ${(0, _utils.escapeValue)(value)}${beforeClause}${afterClause};`;
return _utils.template`ALTER TYPE "${typeName}" 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 rename = exports.rename = function rename(typeName, newTypeName) {
return _utils.template`ALTER TYPE "${typeName}" RENAME TO "${newTypeName}";`;
};
var undoRename = exports.undoRename = function undoRename(type_name, new_type_name) {
return rename(new_type_name, type_name);
var undoRename = exports.undoRename = function undoRename(typeName, newTypeName) {
return rename(newTypeName, typeName);
};
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 renameTypeAttribute = exports.renameTypeAttribute = function renameTypeAttribute(typeName, attributeName, newAttributeName) {
return _utils.template`ALTER TYPE "${typeName}" RENAME ATTRIBUTE "${attributeName}" TO "${newAttributeName}";`;
};
var undoRenameTypeAttribute = exports.undoRenameTypeAttribute = function undoRenameTypeAttribute(type_name, attribute_name, new_attribute_name) {
return renameTypeAttribute(type_name, new_attribute_name, attribute_name);
var undoRenameTypeAttribute = exports.undoRenameTypeAttribute = function undoRenameTypeAttribute(typeName, attributeName, newAttributeName) {
return renameTypeAttribute(typeName, newAttributeName, attributeName);
};

@@ -96,0 +96,0 @@

@@ -71,6 +71,6 @@ 'use strict';

}).map(function (file) {
var file_path = `${options.dir}/${file}`;
var filePath = `${options.dir}/${file}`;
// eslint-disable-next-line global-require,import/no-dynamic-require
var actions = require(_path2.default.relative(__dirname, file_path));
return new _migration2.default(db, file_path, actions, options);
var actions = require(_path2.default.relative(__dirname, filePath));
return new _migration2.default(db, filePath, actions, options);
}).sort(function (m1, m2) {

@@ -124,7 +124,7 @@ return m1.name < m2.name // eslint-disable-line no-nested-ternary

}).then(function () {
return lock(db, options);
return !options.noLock ? lock(db, options) : null;
}).then(function () {
return db.addBeforeCloseListener(function () {
return !options.noLock ? db.addBeforeCloseListener(function () {
return unlock(db, options);
});
}) : null;
}).then(function () {

@@ -139,9 +139,9 @@ return db.column(`SELECT ${nameColumn} FROM "${schema}"."${options.migrations_table}" ORDER BY ${runOnColumn}`, nameColumn);

if (options.direction === 'down') {
var toRun = runNames.filter(function (migration_name) {
return !options.file || options.file === migration_name;
}).map(function (migration_name) {
var toRun = runNames.filter(function (migrationName) {
return !options.file || options.file === migrationName;
}).map(function (migrationName) {
return migrations.find(function (_ref) {
var name = _ref.name;
return name === migration_name;
}) || migration_name;
return name === migrationName;
}) || migrationName;
}).slice(-Math.abs(options.count || 1)).reverse();

@@ -148,0 +148,0 @@ var deletedMigrations = toRun.filter(function (migration) {

@@ -143,3 +143,3 @@ 'use strict';

var type_adapters = {
var typeAdapters = {
int: 'integer',

@@ -153,3 +153,3 @@ string: 'text',

var default_type_shorthands = {
var defaultTypeShorthands = {
id: { type: 'serial', primaryKey: true } // convenience type for serial primary keys

@@ -160,13 +160,13 @@ };

var applyTypeAdapters = exports.applyTypeAdapters = function applyTypeAdapters(type) {
return type_adapters[type] ? type_adapters[type] : type;
return typeAdapters[type] ? typeAdapters[type] : type;
};
var applyType = exports.applyType = function applyType(type) {
var extending_type_shorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var extendingTypeShorthands = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var type_shorthands = _extends({}, default_type_shorthands, extending_type_shorthands);
var typeShorthands = _extends({}, defaultTypeShorthands, extendingTypeShorthands);
var options = type;
if (typeof type === 'string') {
options = type_shorthands[type] // eslint-disable-line no-param-reassign
? type_shorthands[type] : { type };
options = typeShorthands[type] // eslint-disable-line no-param-reassign
? typeShorthands[type] : { type };
}

@@ -179,5 +179,5 @@

var formatParam = function formatParam(type_shorthands) {
var formatParam = function formatParam(typeShorthands) {
return function (param) {
var _applyType = applyType(param, type_shorthands),
var _applyType = applyType(param, typeShorthands),
mode = _applyType.mode,

@@ -207,4 +207,4 @@ name = _applyType.name,

var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var type_shorthands = arguments[1];
return `(${params.map(formatParam(type_shorthands)).join(', ')})`;
var typeShorthands = arguments[1];
return `(${params.map(formatParam(typeShorthands)).join(', ')})`;
};

@@ -1,2 +0,2 @@

// Type definitions for node-pg-migrate 2.3
// Type definitions for node-pg-migrate
// Project: https://github.com/salsita/node-pg-migrate

@@ -283,18 +283,18 @@ // Definitions by: Bradley Ayers <https://github.com/bradleyayers>

createTable(tableName: Name, columns: ColumnDefinitions, options?: TableOptions): void
dropTable(tableName: Name, drop_options: DropOptions): void
renameTable(tablename: Name, new_tablename: Name): void
dropTable(tableName: Name, dropOptions: DropOptions): void
renameTable(tableName: Name, newtableName: Name): void
// Columns
addColumns(tablename: Name, new_columns: ColumnDefinitions): void
addColumn(tablename: Name, new_columns: ColumnDefinitions): void
dropColumns(tablename: Name, columns: string | string[] | { [name: string]: any }, drop_options: DropOptions): void
dropColumn(tablename: Name, columns: string | string[] | { [name: string]: any }, drop_options: DropOptions): void
renameColumn(tablename: Name, old_column_name: string, new_column_name: string): void
addColumns(tableName: Name, newColumns: ColumnDefinitions): void
addColumn(tableName: Name, newColumns: ColumnDefinitions): void
dropColumns(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions: DropOptions): void
dropColumn(tableName: Name, columns: string | string[] | { [name: string]: any }, dropOptions: DropOptions): void
renameColumn(tableName: Name, oldColumnName: string, newColumnName: string): void
alterColumn(tableName: Name, columnName: string, options: ColumnOptions): void
// Constraints
addConstraint(tablename: Name, constraint_name: string | null, expression: string | ConstraintOptions): void
createConstraint(tablename: Name, constraint_name: string | null, expression: string | ConstraintOptions): void
dropConstraint(tablename: Name, constraint_name: string, options: DropOptions): void
renameConstraint(tablename: Name, old_constraint_name: string, new_constraint_name: string): void
addConstraint(tableName: Name, constraintName: string | null, expression: string | ConstraintOptions): void
createConstraint(tableName: Name, constraintName: string | null, expression: string | ConstraintOptions): void
dropConstraint(tableName: Name, constraintName: string, options: DropOptions): void
renameConstraint(tableName: Name, oldConstraintName: string, newConstraintName: string): void

@@ -309,59 +309,59 @@ // Indexes

addExtension(extension: string | string[]): void
dropExtension(extension: string | string[], drop_options: DropOptions): void
dropExtension(extension: string | string[], dropOptions: DropOptions): void
// Types
createType(type_name: Name, values: Value[] | { [name: string]: Type }): void
addType(type_name: Name, values: Value[] | { [name: string]: Type }): void
dropType(type_name: Name, drop_options: DropOptions): void
renameType(type_name: Name, new_type_name: Name): void
addTypeAttribute(type_name: Name, attribute_name: string, attribute_type: Type): void
dropTypeAttribute(type_name: Name, attribute_name: string, options: IfExistsOption): void
setTypeAttribute(type_name: Name, attribute_name: string, attribute_type: Type): void
addTypeValue(type_name: Name, value: Value, options: { ifNotExists?: boolean, before?: string, after?: string }): void
renameTypeAttribute(type_name: Name, attribute_name: string, new_attribute_name: string): void
createType(typeName: Name, values: Value[] | { [name: string]: Type }): void
addType(typeName: Name, values: Value[] | { [name: string]: Type }): void
dropType(typeName: Name, dropOptions: DropOptions): void
renameType(typeName: Name, newTypeName: Name): void
addTypeAttribute(typeName: Name, attributeName: string, attributeType: Type): void
dropTypeAttribute(typeName: Name, attributeName: string, options: IfExistsOption): void
setTypeAttribute(typeName: Name, attributeName: string, attributeType: Type): void
addTypeValue(typeName: Name, value: Value, options: { ifNotExists?: boolean, before?: string, after?: string }): void
renameTypeAttribute(typeName: Name, attributeName: string, newAttributeName: string): void
// Roles
createRole(role_name: Name, role_options: RoleOptions): void
dropRole(role_name: Name, options: IfExistsOption): void
alterRole(role_name: Name, role_options: RoleOptions): void
renameRole(old_role_name: Name, new_role_name: Name): void
createRole(roleName: Name, roleOptions: RoleOptions): void
dropRole(roleName: Name, options: IfExistsOption): void
alterRole(roleName: Name, roleOptions: RoleOptions): void
renameRole(oldRoleName: Name, newRoleName: Name): void
// Functions
createFunction(function_name: Name, function_params: FunctionParam[], function_options: FunctionOptions, definition: Value): void
dropFunction(function_name: Name, function_params: FunctionParam[], drop_options: DropOptions): void
renameFunction(old_function_name: Name, function_params: FunctionParam[], new_function_name: Name): void
createFunction(functionName: Name, functionParams: FunctionParam[], functionOptions: FunctionOptions, definition: Value): void
dropFunction(functionName: Name, functionParams: FunctionParam[], dropOptions: DropOptions): void
renameFunction(oldFunctionName: Name, functionParams: FunctionParam[], newFunctionName: Name): void
// Triggers
createTrigger(table_name: Name, trigger_name: Name, trigger_options: TriggerOptions, definition?: Value): void
dropTrigger(table_name: Name, trigger_name: Name, drop_options: DropOptions): void
renameTrigger(table_name: Name, old_trigger_name: Name, new_trigger_name: Name): void
createTrigger(tableName: Name, triggerName: Name, triggerOptions: TriggerOptions, definition?: Value): void
dropTrigger(tableName: Name, triggerName: Name, dropOptions: DropOptions): void
renameTrigger(tableName: Name, oldTriggerName: Name, newTriggerName: Name): void
// Schemas
createSchema(schema_name: string, schema_options: { ifNotExists?: boolean, authorization?: string }): void
dropSchema(schema_name: string, drop_options: DropOptions): void
renameSchema(old_schema_name: string, new_schema_name: string): void
createSchema(schemaName: string, schemaOptions: { ifNotExists?: boolean, authorization?: string }): void
dropSchema(schemaName: string, dropOptions: DropOptions): void
renameSchema(oldSchemaName: string, newSchemaName: string): void
// Domains
createDomain(domain_name: Name, type: Type, domain_options: DomainOptionsCreate): void
dropDomain(domain_name: Name, drop_options: DropOptions): void
alterDomain(domain_name: Name, domain_options: DomainOptionsAlter): void
renameDomain(old_domain_name: Name, new_domain_name: Name): void
createDomain(domainName: Name, type: Type, domainOptions: DomainOptionsCreate): void
dropDomain(domainName: Name, dropOptions: DropOptions): void
alterDomain(domainName: Name, domainOptions: DomainOptionsAlter): void
renameDomain(oldDomainName: Name, newDomainName: Name): void
// Sequences
createSequence(sequence_name: Name, sequence_options: SequenceOptionsCreate): void
dropSequence(sequence_name: Name, drop_options: DropOptions): void
alterSequence(sequence_name: Name, sequence_options: SequenceOptionsAlter): void
renameSequence(old_sequence_name: Name, new_sequence_name: Name): void
createSequence(sequenceName: Name, sequenceOptions: SequenceOptionsCreate): void
dropSequence(sequenceName: Name, dropOptions: DropOptions): void
alterSequence(sequenceName: Name, sequenceOptions: SequenceOptionsAlter): void
renameSequence(oldSequenceName: Name, newSequenceName: Name): void
// Operators
createOperator(operator_name: Name, options: CreateOperatorOptions): void
dropOperator(operator_name: Name, drop_options: DropOperatorOptions): void
createOperatorClass(operator_class_name: Name, type: Type, index_method: Name, operator_list: OperatorListDefinition, options: CreateOperatorClassOptions): void
dropOperatorClass(operator_class_name: Name, index_method: Name, drop_options: DropOptions): void
renameOperatorClass(old_operator_class_name: Name, index_method: Name, new_operator_class_name: Name): void
createOperatorFamily(operator_family_name: Name, index_method: Name): void
dropOperatorFamily(operator_family_name: Name, new_schema_name: Name, drop_options: DropOptions): void
renameOperatorFamily(old_operator_family_name: Name, index_method: Name, new_operator_family_name: Name): void
addToOperatorFamily(operator_family_name: Name, index_method: Name, operator_list: OperatorListDefinition): void
removeFromOperatorFamily(operator_family_name: Name, index_method: Name, operator_list: OperatorListDefinition): void
createOperator(operatorName: Name, options: CreateOperatorOptions): void
dropOperator(operatorName: Name, dropOptions: DropOperatorOptions): void
createOperatorClass(operatorClassName: Name, type: Type, indexMethod: Name, operatorList: OperatorListDefinition, options: CreateOperatorClassOptions): void
dropOperatorClass(operatorClassName: Name, indexMethod: Name, dropOptions: DropOptions): void
renameOperatorClass(oldOperatorClassName: Name, indexMethod: Name, newOperatorClassName: Name): void
createOperatorFamily(operatorFamilyName: Name, indexMethod: Name): void
dropOperatorFamily(operatorFamilyName: Name, newSchemaName: Name, dropOptions: DropOptions): void
renameOperatorFamily(oldOperatorFamilyName: Name, indexMethod: Name, newOperatorFamilyName: Name): void
addToOperatorFamily(operatorFamilyName: Name, indexMethod: Name, operatorList: OperatorListDefinition): void
removeFromOperatorFamily(operatorFamilyName: Name, indexMethod: Name, operatorList: OperatorListDefinition): void

@@ -407,2 +407,3 @@ sql(sql: string, args?: object): void

typeShorthands?: { [name: string]: string }
noLock?: boolean
}

@@ -409,0 +410,0 @@

@@ -33,3 +33,3 @@ {

],
"version": "2.17.0",
"version": "2.18.0",
"engines": {

@@ -36,0 +36,0 @@ "node": ">=4.0.0"

@@ -12,3 +12,4 @@ # node-pg-migrate

Node.js database migration management built exclusively for postgres. Started by [Theo Ephraim](https://github.com/theoephraim/), now maintained by [Salsita Software](https://www.salsitasoft.com/).
Node.js database migration management built exclusively for postgres. (But can also be used for other DBs conforming to SQL standard - e.g. [CockroachDB](https://github.com/cockroachdb/cockroach).)
Started by [Theo Ephraim](https://github.com/theoephraim/), now maintained by [Salsita Software](https://www.salsitasoft.com/).

@@ -92,5 +93,7 @@ ## Installation

* `ignore-pattern` - Regex pattern for file names to ignore (e.g. `ignore_file|\..*|.*\.spec\.js`)
* `migration-file-language` (`j`) - Language of the migration file to create (`js` or `ts`)
* `check-order` - Check order of migrations before running them (defaults to `true`, to switch it off supply `--no-check-order` on command line).
(There should be no migration with timestamp lesser than last run migration.)
* `no-lock` - Disables locking mechanism and checks (useful for DBs which does not support SQL commands used for [locking](#locking))

@@ -122,3 +125,3 @@ See all by running `node-pg-migrate --help`.

`node-pg-migrate` automatically checks if no other migration is running. To do so, it locks the migration table and enters comment there.
There are other options how to do it, but I choose this one (see #88).
There are other options how to do it, but I choose this one (see [#88](https://github.com/salsita/node-pg-migrate/pull/88)).
In some circumstances it is possible that lock will not be released (Error message - `Error: Unable to fetch migrations: Error: Another migration is already running`).

@@ -125,0 +128,0 @@ In that case you need to run `node-pg-migrate unlock` to release the lock again.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc