Prechádzať zdrojové kódy

Migrate customFields

Andrés Manelli 6 rokov pred
rodič
commit
4cd0d1c397

+ 3 - 2
client/components/sidebar/sidebarCustomFields.js

@@ -2,7 +2,7 @@ BlazeComponent.extendComponent({
 
   customFields() {
     return CustomFields.find({
-      boardId: Session.get('currentBoard'),
+      boardIds: {$in: [Session.get('currentBoard')]},
     });
   },
 
@@ -103,7 +103,6 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
         evt.preventDefault();
 
         const data = {
-          boardId: Session.get('currentBoard'),
           name: this.find('.js-field-name').value.trim(),
           type: this.type.get(),
           settings: this.getSettings(),
@@ -114,8 +113,10 @@ const CreateCustomFieldPopup = BlazeComponent.extendComponent({
 
         // insert or update
         if (!this.data()._id) {
+          data.boardIds = [Session.get('currentBoard')];
           CustomFields.insert(data);
         } else {
+          data.boardIds = {$in: [Session.get('currentBoard')]};
           CustomFields.update(this.data()._id, {$set: data});
         }
 

+ 1 - 1
models/cards.js

@@ -476,7 +476,7 @@ Cards.helpers({
 
     // get all definitions
     const definitions = CustomFields.find({
-      boardId: this.boardId,
+      boardIds: {$in: [this.boardId]},
     }).fetch();
 
     // match right definition to each field

+ 5 - 5
models/customFields.js

@@ -4,11 +4,11 @@ CustomFields = new Mongo.Collection('customFields');
  * A custom field on a card in the board
  */
 CustomFields.attachSchema(new SimpleSchema({
-  boardId: {
+  boardIds: {
     /**
      * the ID of the board
      */
-    type: String,
+    type: [String],
   },
   name: {
     /**
@@ -135,7 +135,7 @@ if (Meteor.isServer) {
     const paramBoardId = req.params.boardId;
     JsonRoutes.sendResult(res, {
       code: 200,
-      data: CustomFields.find({ boardId: paramBoardId }).map(function (cf) {
+      data: CustomFields.find({ boardIds: {$in: [paramBoardId]} }).map(function (cf) {
         return {
           _id: cf._id,
           name: cf.name,
@@ -159,7 +159,7 @@ if (Meteor.isServer) {
     const paramCustomFieldId = req.params.customFieldId;
     JsonRoutes.sendResult(res, {
       code: 200,
-      data: CustomFields.findOne({ _id: paramCustomFieldId, boardId: paramBoardId }),
+      data: CustomFields.findOne({ _id: paramCustomFieldId, boardIds: {$in: [paramBoardId]} }),
     });
   });
 
@@ -189,7 +189,7 @@ if (Meteor.isServer) {
       boardId: paramBoardId,
     });
 
-    const customField = CustomFields.findOne({_id: id, boardId: paramBoardId });
+    const customField = CustomFields.findOne({_id: id, boardIds: {$in: [paramBoardId]} });
     customFieldCreation(req.body.authorId, customField);
 
     JsonRoutes.sendResult(res, {

+ 1 - 1
models/export.js

@@ -75,7 +75,7 @@ class Exporter {
     result.lists = Lists.find(byBoard, noBoardId).fetch();
     result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
-    result.customFields = CustomFields.find(byBoard, noBoardId).fetch();
+    result.customFields = CustomFields.find({boardIds: {$in: [this.boardId]}}, {fields: {boardId: 0}}).fetch();
     result.comments = CardComments.find(byBoard, noBoardId).fetch();
     result.activities = Activities.find(byBoard, noBoardId).fetch();
     result.rules = Rules.find(byBoard, noBoardId).fetch();

+ 13 - 0
server/migrations.js

@@ -525,3 +525,16 @@ Migrations.add('fix-circular-reference_', () => {
     }
   });
 });
+
+Migrations.add('mutate-boardIds-in-customfields', () => {
+  CustomFields.find().forEach((cf) => {
+    CustomFields.update(cf, {
+      $set: {
+        boardIds: [cf.boardId],
+      },
+      $unset: {
+        boardId: "",
+      },
+    }, noValidateMulti);
+  });
+});

+ 1 - 1
server/publications/boards.js

@@ -78,7 +78,7 @@ Meteor.publishRelations('board', function(boardId) {
     this.cursor(Lists.find({ boardId }));
     this.cursor(Swimlanes.find({ boardId }));
     this.cursor(Integrations.find({ boardId }));
-    this.cursor(CustomFields.find({ boardId }, { sort: { name: 1 } }));
+    this.cursor(CustomFields.find({ boardIds: {$in: [boardId]} }, { sort: { name: 1 } }));
 
     // Cards and cards comments
     // XXX Originally we were publishing the card documents as a child of the