Replace migrations that rely on models with rake tasks
Replace some migrations that rely on relationships between models to add subscriptions with rake tasks.
This commit is contained in:
parent
227c402ad1
commit
826b70fdc5
4 changed files with 16 additions and 16 deletions
|
@ -1,12 +1,5 @@
|
||||||
class SubscribeOldChangesets < ActiveRecord::Migration[4.2]
|
class SubscribeOldChangesets < ActiveRecord::Migration[4.2]
|
||||||
class Changeset < ActiveRecord::Base
|
def up; end
|
||||||
end
|
|
||||||
|
|
||||||
def up
|
|
||||||
Changeset.find_each do |changeset|
|
|
||||||
changeset.subscribers << changeset.user unless changeset.subscribers.exists?(changeset.user.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def down; end
|
def down; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
class SubscribeAuthorsToDiaryEntries < ActiveRecord::Migration[4.2]
|
class SubscribeAuthorsToDiaryEntries < ActiveRecord::Migration[4.2]
|
||||||
class DiaryEntry < ActiveRecord::Base
|
def up; end
|
||||||
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 down; end
|
def down; end
|
||||||
end
|
end
|
||||||
|
|
7
lib/tasks/subscribe_diary_authors.rb
Normal file
7
lib/tasks/subscribe_diary_authors.rb
Normal file
|
@ -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
|
7
lib/tasks/subscribe_old_changesets.rb
Normal file
7
lib/tasks/subscribe_old_changesets.rb
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue