<commit_before>Migrations = new Meteor.Collection('migrations');

Meteor.startup(function () {

  // change default schema to include notification preferences for users
  if (!Migrations.findOne({name: "addDefaultNotificationPreferences"})) {
    Meteor.users.find().forEach(function (user) {
      Meteor.users.update(user._id, {$set: {notify: {updates: false, response: true}}});
    });
    Migrations.insert({name: "addDefaultNotificationPreferences"});
  }

  // only necessary if upgrading from <=v1.1.1 to a newer release
  // ensures that all required user profile attributes are defined
  if (!Migrations.findOne({name: "ensureProfilePropertyExistsForUsers"})) {
    Meteor.users.find().forEach(function (user) {
      if (!user.profile) {
        Meteor.users.update(user._id, {$set: { profile: {
          displayName: null,
          givenName: null,
          initials: null,
          sn: null,
          name: null
        }}});
      }
    });
    Migrations.insert({name: "ensureProfilePropertyExistsForUsers"});
  }

  if(!Migrations.findOne({name: "renamePostToPetition"})){
    Posts = new Meteor.Collection('posts');
    Posts.find().forEach(function (post){
      Petitions.insert(post);
      Posts.remove(post);
    });
    Migrations.insert({name: "renamePostToPetition"});
  }

  // auto-subscribe users to status update e-mails *if* they have official responses enabled
  if (!Migrations.findOne({name: "enableStatusUpdateEmailsIfOfficialResponsesEnabled"})) {
    Meteor.users.update({'notify.response': true}, {$set: {'notify.updates': true}}, {multi: true});
    Migrations.insert({name: "enableStatusUpdateEmailsIfOfficialResponsesEnabled"});
  }

  // mark all existing petitions as published by default
  if (!Migrations.findOne({name: "markAllPreviousPetitionsAsPublished"})) {
    Petitions.update({}, {$set: {published: true}}, {multi: true});
    Migrations.insert({name: "markAllPreviousPetitionsAsPublished"});
  }

});<commit_msg>first attempt at fixing petition count migration issue<commit_after>Migrations = new Meteor.Collection('migrations');

Meteor.startup(function () {

  // change default schema to include notification preferences for users
  if (!Migrations.findOne({name: "addDefaultNotificationPreferences"})) {
    Meteor.users.find().forEach(function (user) {
      Meteor.users.update(user._id, {$set: {notify: {updates: false, response: true}}});
    });
    Migrations.insert({name: "addDefaultNotificationPreferences"});
  }

  // only necessary if upgrading from <=v1.1.1 to a newer release
  // ensures that all required user profile attributes are defined
  if (!Migrations.findOne({name: "ensureProfilePropertyExistsForUsers"})) {
    Meteor.users.find().forEach(function (user) {
      if (!user.profile) {
        Meteor.users.update(user._id, {$set: { profile: {
          displayName: null,
          givenName: null,
          initials: null,
          sn: null,
          name: null
        }}});
      }
    });
    Migrations.insert({name: "ensureProfilePropertyExistsForUsers"});
  }

  if(!Migrations.findOne({name: "renamePostToPetition"})){
    Posts = new Meteor.Collection('posts');
    Posts.find().forEach(function (post){
      Petitions.insert(post);
      Posts.remove(post);
    });
    Migrations.insert({name: "renamePostToPetition"});
  }

  if(!Migrations.findOne({name: "fixSingletonPetitionCount"})){
    single = Singleton.findOne();
    single.petitionsCount += single.postsCount;
    Migrations.insert({name: "fixSingletonPetitionCount"});
  }

  // auto-subscribe users to status update e-mails *if* they have official responses enabled
  if (!Migrations.findOne({name: "enableStatusUpdateEmailsIfOfficialResponsesEnabled"})) {
    Meteor.users.update({'notify.response': true}, {$set: {'notify.updates': true}}, {multi: true});
    Migrations.insert({name: "enableStatusUpdateEmailsIfOfficialResponsesEnabled"});
  }

  // mark all existing petitions as published by default
  if (!Migrations.findOne({name: "markAllPreviousPetitionsAsPublished"})) {
    Petitions.update({}, {$set: {published: true}}, {multi: true});
    Migrations.insert({name: "markAllPreviousPetitionsAsPublished"});
  }

});
{'fraction_non_alphanumeric': 0.14599236641221375, 'fraction_numerical': 0.0014312977099236641, 'mean_word_length': 4.1321909424724605, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7420745', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1209, 'n_words': 259}