You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
977 B
JavaScript
43 lines
977 B
JavaScript
'use strict';
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
let tables = [
|
|
require("./unique-constraint-violation"),
|
|
require("./composite-unique-constraint-violation"),
|
|
require("./check-constraint-violation"),
|
|
require("./foreign-key-constraint-violation"),
|
|
require("./enum"),
|
|
require("./invalid-type"),
|
|
require("./not-null-constraint-violation")
|
|
];
|
|
|
|
let noop = function noop(err) {
|
|
// Do nothing.
|
|
}
|
|
|
|
let rethrow = function rethrowError(err) {
|
|
throw err;
|
|
}
|
|
|
|
module.exports = {
|
|
up: function createTables(knex) {
|
|
return Promise.map(tables, (table) => {
|
|
return table.up(knex, rethrow);
|
|
});
|
|
},
|
|
down: function dropTables(knex, ignoreErrors) {
|
|
let errorHandler;
|
|
|
|
if (ignoreErrors) {
|
|
errorHandler = noop;
|
|
} else {
|
|
errorHandler = rethrow;
|
|
}
|
|
|
|
return Promise.map(tables, (table) => {
|
|
return table.down(knex, errorHandler);
|
|
});
|
|
}
|
|
}
|