itizawa 6 tahun lalu
induk
melakukan
95536f4bf1
1 mengubah file dengan 27 tambahan dan 8 penghapusan
  1. 27 8
      src/migrations/20190619055421-adjust-page-grant.js

+ 27 - 8
src/migrations/20190619055421-adjust-page-grant.js

@@ -1,14 +1,33 @@
+require('module-alias/register');
+const logger = require('@alias/logger')('growi:migrate:adjust-page-grant');
+
+const mongoose = require('mongoose');
+const config = require('@root/config/migrate');
+
 module.exports = {
 module.exports = {
-  up(db) {
-    // TODO write your migration here. Return a Promise (and/or use async & await).
-    // See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script
-    // Example:
-    // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});
+
+  async up(db) {
+    logger.info('Apply migration');
+    mongoose.connect(config.mongoUri, config.mongodb.options);
+
+    const Page = require('@server/models/page')();
+
+    await Page.bulkWrite([
+      {
+        updateMany:
+         {
+           filter: { grant: null },
+           update: { $set: { grant: Page.GRANT_PUBLIC } },
+           upsert: true,
+         },
+      },
+    ]);
+
+    logger.info('Migration has successfully applied');
+
   },
   },
 
 
   down(db) {
   down(db) {
-    // TODO write the statements to rollback your migration (if possible)
-    // Example:
-    // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});
+    // do not rollback
   },
   },
 };
 };