Refactoring Conference/Event media to new media object

close #420
This commit is contained in:
Chrisbr 2014-08-05 18:23:42 +02:00
parent 850beb72e1
commit 2a731e8350
31 changed files with 491 additions and 57 deletions

View file

@ -0,0 +1,10 @@
class CreateCommercials < ActiveRecord::Migration
def change
create_table :commercials do |t|
t.string :commercial_id
t.string :commercial_type
t.references :commercialable, polymorphic: true
t.timestamps
end
end
end

View file

@ -0,0 +1,28 @@
class MoveConferenceMediaToCommercial < ActiveRecord::Migration
class TempConference < ActiveRecord::Base
self.table_name = 'conferences'
end
class TempCommercial < ActiveRecord::Base
self.table_name = 'commercials'
attr_accessible :commercial_id, :commercial_type, :commercialable_id, :commercialable_type
end
def change
# Move all the settings to the new object
TempConference.all.each do |conference|
unless TempCommercial.exists?(commercialable_id: conference.id, commercialable_id: 'Conference')
unless conference.media_id.blank? || conference.media_type.blank?
TempCommercial.create(commercial_id: conference.media_id,
commercial_type: conference.media_type,
commercialable_id: conference.id,
commercialable_type: 'Conference')
end
end
end
# Then remove all the columns
remove_column :conferences, :media_id
remove_column :conferences, :media_type
end
end

View file

@ -0,0 +1,28 @@
class MoveEventMediaToCommercial < ActiveRecord::Migration
class TempEvent < ActiveRecord::Base
self.table_name = 'events'
end
class TempCommercial < ActiveRecord::Base
self.table_name = 'commercials'
attr_accessible :commercial_id, :commercial_type, :commercialable_id, :commercialable_type
end
def change
# Move all the settings to the new object
TempEvent.all.each do |event|
unless TempCommercial.exists?(commercialable_id: event.id, commercialable_id: 'Conference')
unless event.media_id.blank? || event.media_type.blank?
TempCommercial.create(commercial_id: event.media_id,
commercial_type: event.media_type,
commercialable_id: event.id,
commercialable_type: 'Event')
end
end
end
# Then remove all the columns
remove_column :events, :media_id
remove_column :events, :media_type
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: 20140731165107) do
ActiveRecord::Schema.define(version: 20140801170430) do
create_table "ahoy_events", force: true do |t|
t.uuid "visit_id"
@ -74,6 +74,15 @@ ActiveRecord::Schema.define(version: 20140731165107) do
add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type"
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
create_table "commercials", force: true do |t|
t.string "commercial_id"
t.string "commercial_type"
t.integer "commercialable_id"
t.string "commercialable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "conferences", force: true do |t|
t.string "guid", null: false
t.string "title", null: false
@ -98,8 +107,6 @@ ActiveRecord::Schema.define(version: 20140731165107) do
t.boolean "use_vdays", default: false
t.boolean "use_difficulty_levels", default: false
t.boolean "use_volunteers"
t.string "media_id"
t.string "media_type"
t.string "color"
t.text "description"
t.text "registration_description"
@ -257,8 +264,6 @@ ActiveRecord::Schema.define(version: 20140731165107) do
t.integer "room_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "media_id"
t.string "media_type"
t.boolean "require_registration"
t.integer "difficulty_level_id"
t.integer "week"