|
@@ -6,31 +6,30 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:migrate:update-configs-for-slackbot');
|
|
const logger = loggerFactory('growi:migrate:update-configs-for-slackbot');
|
|
|
|
|
|
|
|
|
|
+// key: oldKey, value: newKey
|
|
|
|
|
+const keyMap = {
|
|
|
|
|
+ 'slackbot:proxyServerUri': 'slackbot:proxyUri',
|
|
|
|
|
+ 'slackbot:token': 'slackbot:withoutProxy:botToken',
|
|
|
|
|
+ 'slackbot:signingSecret': 'slackbot:withoutProxy:signingSecret',
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
module.exports = {
|
|
module.exports = {
|
|
|
async up(db) {
|
|
async up(db) {
|
|
|
logger.info('Apply migration');
|
|
logger.info('Apply migration');
|
|
|
mongoose.connect(config.mongoUri, config.mongodb.options);
|
|
mongoose.connect(config.mongoUri, config.mongodb.options);
|
|
|
|
|
|
|
|
- await Config.bulkWrite([
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:proxyServerUri' },
|
|
|
|
|
- update: { key: 'slackbot:proxyUri' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:token' },
|
|
|
|
|
- update: { key: 'slackbot:withoutProxy:botToken' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:signingSecret' },
|
|
|
|
|
- update: { key: 'slackbot:withoutProxy:signingSecret' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ for await (const [oldKey, newKey] of Object.entries(keyMap)) {
|
|
|
|
|
+ const isExist = (await Config.count({ key: newKey })) > 0;
|
|
|
|
|
+
|
|
|
|
|
+ // remove old key
|
|
|
|
|
+ if (isExist) {
|
|
|
|
|
+ await Config.findOneAndRemove({ key: oldKey });
|
|
|
|
|
+ }
|
|
|
|
|
+ // update with new key
|
|
|
|
|
+ else {
|
|
|
|
|
+ await Config.findOneAndUpdate({ key: oldKey }, { key: newKey });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
logger.info('Migration has successfully applied');
|
|
logger.info('Migration has successfully applied');
|
|
|
},
|
|
},
|
|
@@ -39,26 +38,18 @@ module.exports = {
|
|
|
logger.info('Rollback migration');
|
|
logger.info('Rollback migration');
|
|
|
mongoose.connect(config.mongoUri, config.mongodb.options);
|
|
mongoose.connect(config.mongoUri, config.mongodb.options);
|
|
|
|
|
|
|
|
- await Config.bulkWrite([
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:proxyUri' },
|
|
|
|
|
- update: { key: 'slackbot:proxyServerUri' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:withoutProxy:botToken' },
|
|
|
|
|
- update: { key: 'slackbot:token' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- updateOne: {
|
|
|
|
|
- filter: { key: 'slackbot:withoutProxy:signingSecret' },
|
|
|
|
|
- update: { key: 'slackbot:signingSecret' },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ for await (const [oldKey, newKey] of Object.entries(keyMap)) {
|
|
|
|
|
+ const isExist = (await Config.count({ key: oldKey })) > 0;
|
|
|
|
|
+
|
|
|
|
|
+ // remove new key
|
|
|
|
|
+ if (isExist) {
|
|
|
|
|
+ await Config.findOneAndRemove({ key: newKey });
|
|
|
|
|
+ }
|
|
|
|
|
+ // update with old key
|
|
|
|
|
+ else {
|
|
|
|
|
+ await Config.findOneAndUpdate({ key: newKey }, { key: oldKey });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
logger.info('Migration has successfully applied');
|
|
logger.info('Migration has successfully applied');
|
|
|
},
|
|
},
|