From: Tom Hughes Date: Wed, 17 Jul 2019 17:55:15 +0000 (+0100) Subject: Replace migrations that rely on models with rake tasks X-Git-Tag: live~3007 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/826b70fdc5f44ab2f6bde94b8ab67bf98ee43981 Replace migrations that rely on models with rake tasks Replace some migrations that rely on relationships between models to add subscriptions with rake tasks. --- diff --git a/db/migrate/20150111192335_subscribe_old_changesets.rb b/db/migrate/20150111192335_subscribe_old_changesets.rb index 94b3bb565..41d139ca4 100644 --- a/db/migrate/20150111192335_subscribe_old_changesets.rb +++ b/db/migrate/20150111192335_subscribe_old_changesets.rb @@ -1,12 +1,5 @@ class SubscribeOldChangesets < ActiveRecord::Migration[4.2] - class Changeset < ActiveRecord::Base - end - - def up - Changeset.find_each do |changeset| - changeset.subscribers << changeset.user unless changeset.subscribers.exists?(changeset.user.id) - end - end + def up; end def down; end end diff --git a/db/migrate/20161011010929_subscribe_authors_to_diary_entries.rb b/db/migrate/20161011010929_subscribe_authors_to_diary_entries.rb index 76fa1fabf..996d2c9b2 100644 --- a/db/migrate/20161011010929_subscribe_authors_to_diary_entries.rb +++ b/db/migrate/20161011010929_subscribe_authors_to_diary_entries.rb @@ -1,12 +1,5 @@ class SubscribeAuthorsToDiaryEntries < ActiveRecord::Migration[4.2] - class DiaryEntry < ActiveRecord::Base - end - - def up - DiaryEntry.find_each do |diary_entry| - diary_entry.subscriptions.create(:user => diary_entry.user) unless diary_entry.subscribers.exists?(diary_entry.user.id) - end - end + def up; end def down; end end diff --git a/lib/tasks/subscribe_diary_authors.rb b/lib/tasks/subscribe_diary_authors.rb new file mode 100644 index 000000000..107fcc53e --- /dev/null +++ b/lib/tasks/subscribe_diary_authors.rb @@ -0,0 +1,7 @@ +namespace :db do + task :subscribe_diary_authors => :environment do + DiaryEntry.find_each do |diary_entry| + diary_entry.subscriptions.create(:user => diary_entry.user) unless diary_entry.subscribers.exists?(diary_entry.user.id) + end + end +end diff --git a/lib/tasks/subscribe_old_changesets.rb b/lib/tasks/subscribe_old_changesets.rb new file mode 100644 index 000000000..6fdd4c4e6 --- /dev/null +++ b/lib/tasks/subscribe_old_changesets.rb @@ -0,0 +1,7 @@ +namespace :db do + task :subscribe_old_changesets => :environment do + Changeset.find_each do |changeset| + changeset.subscribers << changeset.user unless changeset.subscribers.exists?(changeset.user.id) + end + end +end