0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Added documentation and JSDoc to migration commands

refs https://github.com/TryGhost/Ghost/issues/12567

- Functions were missing documentation and were able to perform operations on multiple columns instead of single one after checking the knex docs (http://knexjs.org/#Schema-unique)
This commit is contained in:
Naz 2021-02-02 16:43:31 +13:00 committed by Daniel Lockyer
parent fbf0caf600
commit 23c5ca0795
No known key found for this signature in database
GPG key ID: FFBC6FA2A6F6ABC1

View file

@ -63,15 +63,31 @@ function dropColumn(tableName, column, transaction) {
});
}
function addUnique(tableName, column, transaction) {
/**
* Adds an unique index to a table over the given columns.
*
* @param {string} tableName - name of the table to add unique constraint to
* @param {string|[string]} columns - column(s) to form unique constraint with
* @param {Object} transaction - connnection object containing knex reference
* @param {Object} transaction.knex - knex instance
*/
function addUnique(tableName, columns, transaction) {
return (transaction || db.knex).schema.table(tableName, function (table) {
table.unique(column);
table.unique(columns);
});
}
function dropUnique(tableName, column, transaction) {
/**
* Drops a unique key constraint from a table.
*
* @param {string} tableName - name of the table to drop unique constraint from
* @param {string|[string]} columns - column(s) unique constraint was formed
* @param {Object} transaction - connnection object containing knex reference
* @param {Object} transaction.knex - knex instance
*/
function dropUnique(tableName, columns, transaction) {
return (transaction || db.knex).schema.table(tableName, function (table) {
table.dropUnique(column);
table.dropUnique(columns);
});
}