2021-11-08 22:11:56 +00:00
|
|
|
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();
|
|
|
|
|
2021-11-09 13:03:39 +00:00
|
|
|
if (!row) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-11-08 22:11:56 +00:00
|
|
|
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);
|
|
|
|
};
|