From ee89dedd0fd971351959a41acceabc997cf6df7f Mon Sep 17 00:00:00 2001 From: Chaptergy Date: Mon, 8 Nov 2021 23:11:56 +0100 Subject: [PATCH] Adds migration to regenerate default host --- .../20211108145214_regenerate_default_host.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 backend/migrations/20211108145214_regenerate_default_host.js diff --git a/backend/migrations/20211108145214_regenerate_default_host.js b/backend/migrations/20211108145214_regenerate_default_host.js new file mode 100644 index 00000000..41feee5d --- /dev/null +++ b/backend/migrations/20211108145214_regenerate_default_host.js @@ -0,0 +1,46 @@ +const migrate_name = 'stream_domain'; +const logger = require('../logger').migrate; +const internalNginx = require('../internal/nginx'); + +async function regenerateDefaultHost(knex) { + const row = await knex('setting').select('*').where('id', 'default-site').first(); + + return internalNginx.deleteConfig('default') + .then(() => { + return internalNginx.generateConfig('default', row); + }) + .then(() => { + return internalNginx.test(); + }) + .then(() => { + return internalNginx.reload(); + }); +} + +/** + * Migrate + * + * @see http://knexjs.org/#Schema + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.up = function (knex) { + logger.info('[' + migrate_name + '] Migrating Up...'); + + return regenerateDefaultHost(knex); +}; + +/** + * Undo Migrate + * + * @param {Object} knex + * @param {Promise} Promise + * @returns {Promise} + */ +exports.down = function (knex) { + logger.info('[' + migrate_name + '] Migrating Down...'); + + return regenerateDefaultHost(knex); +}; \ No newline at end of file