Add migration to set all the mod#author from mod#authors

master
Zequez 2015-08-07 11:09:48 -03:00
parent acd153add3
commit 84d4a3fadc
3 changed files with 16 additions and 3 deletions

View File

@ -36,8 +36,8 @@ class Mod < ActiveRecord::Base
has_many :game_versions, -> { uniq.sort_by_older_to_newer }, through: :mod_game_versions
has_many :categories, through: :categories_mods
has_many :categories_mods, dependent: :destroy
# has_many :authors, ->{ includes(:authors_mods).order('authors_mods.sort_order') }, through: :authors_mods
# has_many :authors_mods, dependent: :destroy
has_many :authors, ->{ includes(:authors_mods).order('authors_mods.sort_order') }, through: :authors_mods
has_many :authors_mods, dependent: :destroy
# has_one :latest_version, -> { sort_by_newer_to_older.limit(1) }, class_name: 'ModVersion'
# has_one :second_latest_version, -> { sort_by_newer_to_older.limit(1).offset(1) }, class_name: 'ModVersion'

View File

@ -0,0 +1,13 @@
class SetModAuthorsToModAuthor < ActiveRecord::Migration
def change
Mod.all.each do |mod|
# Not really related, but this was pending from another previous migration
mod.info_json_name = mod.slug if mod.info_json_name.blank?
# We don't really have more than 1 author for each mod on production
# Well, I think we have 1, but it's not worth it to make something more complex
mod.author = mod.authors.first
mod.save!
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150807104820) do
ActiveRecord::Schema.define(version: 20150807140522) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"