Migrate customFields

This commit is contained in:
Andrés Manelli 2019-03-08 23:39:33 +01:00
parent ff19d6744e
commit 4cd0d1c397
6 changed files with 24 additions and 10 deletions

View file

@ -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});
}

View file

@ -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

View file

@ -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, {

View file

@ -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();

View file

@ -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);
});
});

View file

@ -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