From 6e3d23e740f2162f89e56d581c91c5be5cd306bd Mon Sep 17 00:00:00 2001 From: vjrj Date: Wed, 14 Mar 2018 09:01:19 +0100 Subject: [PATCH] Add bot id to subscriptions --- imports/api/Subscriptions/Subscriptions.js | 1 + imports/api/Users/Users.js | 1 - imports/startup/server/migrations.js | 26 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/imports/api/Subscriptions/Subscriptions.js b/imports/api/Subscriptions/Subscriptions.js index 69b7ff5..eb4be16 100644 --- a/imports/api/Subscriptions/Subscriptions.js +++ b/imports/api/Subscriptions/Subscriptions.js @@ -48,6 +48,7 @@ Subscriptions.schema = new SimpleSchema({ geo: LocationSchema, distance: Number, chatId: { type: Number, optional: true }, // only in 'telegram' type + telegramBot: { type: String, optional: true }, // only in 'telegram' type owner: String, type: String, createdAt: defaultCreatedAt, diff --git a/imports/api/Users/Users.js b/imports/api/Users/Users.js index aebdc4c..34ade38 100644 --- a/imports/api/Users/Users.js +++ b/imports/api/Users/Users.js @@ -106,7 +106,6 @@ const schemaUser = new SimpleSchema({ 'name.first': String, 'name.last': String, */ lang: { type: String, optional: true }, - telegramBot: { type: String, optional: true }, telegramChatId: { type: SimpleSchema.Integer, optional: true }, telegramUsername: { type: String, optional: true }, telegramFirstName: { type: String, optional: true }, diff --git a/imports/startup/server/migrations.js b/imports/startup/server/migrations.js index f4124d3..072cb67 100644 --- a/imports/startup/server/migrations.js +++ b/imports/startup/server/migrations.js @@ -171,12 +171,34 @@ Meteor.startup(() => { $set: { telegramBot: 'es' } - }); + }, { multi: true }); + } + }); + + Migrations.add({ + version: 13, + up: function removeTelegramBotFromUsersId() { + Meteor.users.update({}, { + $unset: { + telegramBot: '' + } + }, { multi: true }); + } + }); + + Migrations.add({ + version: 14, + up: function setTelegramUsersBotId() { + UserSubsToFiresCollection.update({ chatId: { $ne: null }, telegramBot: null }, { + $set: { + telegramBot: 'es' + } + }, { multi: true }); } }); // Set createdAt in users & subs Migrations.migrateTo('latest'); - // Migrations.migrateTo('12,rerun'); + // Migrations.migrateTo('14,rerun'); });