From 1f122e9145ab24ec15c7da7baf82e9f96b13bc54 Mon Sep 17 00:00:00 2001 From: baruffaldi Date: Wed, 10 Feb 2021 15:57:28 +0100 Subject: [PATCH] Database migrations created --- .../20210210154702_redirection_scheme.js | 49 +++++++++++++++++++ .../20210210154703_redirection_status_code.js | 49 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 backend/migrations/20210210154702_redirection_scheme.js create mode 100644 backend/migrations/20210210154703_redirection_status_code.js diff --git a/backend/migrations/20210210154702_redirection_scheme.js b/backend/migrations/20210210154702_redirection_scheme.js new file mode 100644 index 00000000..a7fcca97 --- /dev/null +++ b/backend/migrations/20210210154702_redirection_scheme.js @@ -0,0 +1,49 @@ +const migrate_name = 'redirection_scheme'; +const logger = require('../logger').migrate; + +/** + * Migrate + * + * @see http://knexjs.org/#Schema + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.up = function (knex, Promise) { + + logger.info('[' + migrate_name + '] Migrating Up...'); + + return knex.schema.table('redirection_host', (table) => { + table.string('forward_scheme').notNull().defaultTo("$scheme"); + }) + .then(function () { + logger.info('[' + migrate_name + '] redirection_host Table altered'); + }); + + logger.info('[' + migrate_name + '] Migrating Up Complete'); + + return Promise.resolve(true); +}; + +/** + * Undo Migrate + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.down = function (knex, Promise) { + logger.info('[' + migrate_name + '] Migrating Down...'); + + return knex.schema.table('redirection_host', (table) => { + table.dropColumn('forward_scheme'); + }) + .then(function () { + logger.info('[' + migrate_name + '] redirection_host Table altered'); + }); + + logger.info('[' + migrate_name + '] Migrating Down Complete'); + + return Promise.resolve(true); +}; diff --git a/backend/migrations/20210210154703_redirection_status_code.js b/backend/migrations/20210210154703_redirection_status_code.js new file mode 100644 index 00000000..c5888dd5 --- /dev/null +++ b/backend/migrations/20210210154703_redirection_status_code.js @@ -0,0 +1,49 @@ +const migrate_name = 'redirection_status_code'; +const logger = require('../logger').migrate; + +/** + * Migrate + * + * @see http://knexjs.org/#Schema + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.up = function (knex, Promise) { + + logger.info('[' + migrate_name + '] Migrating Up...'); + + return knex.schema.table('redirection_host', (table) => { + table.integer('forward_http_code').notNull().unsigned().defaultTo(302); + }) + .then(function () { + logger.info('[' + migrate_name + '] redirection_host Table altered'); + }); + + logger.info('[' + migrate_name + '] Migrating Up Complete'); + + return Promise.resolve(true); +}; + +/** + * Undo Migrate + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.down = function (knex, Promise) { + logger.info('[' + migrate_name + '] Migrating Down...'); + + return knex.schema.table('redirection_host', (table) => { + table.dropColumn('forward_http_code'); + }) + .then(function () { + logger.info('[' + migrate_name + '] redirection_host Table altered'); + }); + + logger.info('[' + migrate_name + '] Migrating Down Complete'); + + return Promise.resolve(true); +};