From 84d4a3fadcbd75995e105693e81b8808457f722e Mon Sep 17 00:00:00 2001 From: Zequez Date: Fri, 7 Aug 2015 11:09:48 -0300 Subject: [PATCH] Add migration to set all the mod#author from mod#authors --- app/models/mod.rb | 4 ++-- .../20150807140522_set_mod_authors_to_mod_author.rb | 13 +++++++++++++ db/schema.rb | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20150807140522_set_mod_authors_to_mod_author.rb diff --git a/app/models/mod.rb b/app/models/mod.rb index 3f99c3b..323fec3 100644 --- a/app/models/mod.rb +++ b/app/models/mod.rb @@ -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' diff --git a/db/migrate/20150807140522_set_mod_authors_to_mod_author.rb b/db/migrate/20150807140522_set_mod_authors_to_mod_author.rb new file mode 100644 index 0000000..3c02f66 --- /dev/null +++ b/db/migrate/20150807140522_set_mod_authors_to_mod_author.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 96dc226..f749bab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"