ソースを参照

Merge branch 'master' into fix/7430-7431-fix-keyword-highlightning-problem

Yuki Takei 4 年 前
コミット
f81536d3b9

+ 21 - 8
packages/app/src/migrations/20210913153942-migrate-slack-app-integration-schema.js

@@ -29,14 +29,26 @@ module.exports = {
 
     // create operations
     const operations = slackAppIntegrations.map((doc) => {
-      const copyForBroadcastUse = defaultDataForBroadcastUse;
-      const copyForSingleUse = defaultDataForSingleUse;
-      doc._doc.supportedCommandsForBroadcastUse.forEach((commandName) => {
-        copyForBroadcastUse[commandName] = true;
-      });
-      doc._doc.supportedCommandsForSingleUse.forEach((commandName) => {
-        copyForSingleUse[commandName] = true;
-      });
+      const copyForBroadcastUse = { ...defaultDataForBroadcastUse };
+      const copyForSingleUse = { ...defaultDataForSingleUse };
+      // when the document does NOT have supportedCommandsFor... columns
+      if (doc._doc.supportedCommandsForBroadcastUse == null) {
+        defaultSupportedCommandsNameForBroadcastUse.forEach((commandName) => {
+          copyForBroadcastUse[commandName] = true;
+        });
+        defaultSupportedCommandsNameForSingleUse.forEach((commandName) => {
+          copyForSingleUse[commandName] = true;
+        });
+      }
+      // // when the document has supportedCommandsFor... columns
+      else {
+        doc._doc.supportedCommandsForBroadcastUse.forEach((commandName) => {
+          copyForBroadcastUse[commandName] = true;
+        });
+        doc._doc.supportedCommandsForSingleUse.forEach((commandName) => {
+          copyForSingleUse[commandName] = true;
+        });
+      }
 
       return {
         updateOne: {
@@ -63,6 +75,7 @@ module.exports = {
 
   async down(db, next) {
     logger.info('Rollback migration');
+    // return next();
     mongoose.connect(config.mongoUri, config.mongodb.options);
 
     const SlackAppIntegration = getModelSafely('SlackAppIntegration') || require('~/server/models/slack-app-integration')();