1 class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
3 create_table :diary_entry_subscriptions, :id => false do |t|
4 t.column :user_id, :bigint, :null => false
5 t.column :diary_entry_id, :bigint, :null => false
8 add_index :diary_entry_subscriptions, [:user_id, :diary_entry_id], :unique => true, :name => "index_diary_subscriptions_on_user_id_and_diary_entry_id"
9 add_index :diary_entry_subscriptions, [:diary_entry_id]
13 DiaryEntry.find_each do |diary_entry|
14 diary_entry.subscriptions.create(user: diary_entry.user) unless diary_entry.subscribers.exists?(@user)