Merge pull request #480 from hennevogel/blah

Drop and fix wrong migration 20140801080705
This commit is contained in:
Henne Vogelsang 2014-08-20 22:09:38 +02:00
commit 6579b3220f
4 changed files with 233 additions and 153 deletions

View file

@ -1,48 +0,0 @@
class AddUsersToEvents < ActiveRecord::Migration
class TempEvent < ActiveRecord::Base
self.table_name = 'events'
end
class TempUser < ActiveRecord::Base
self.table_name = 'users'
end
class TempEventUser < ActiveRecord::Base
self.table_name = 'event_users'
belongs_to :temp_event
belongs_to :temp_user
attr_accessible :event_id, :user_id, :event_role
end
def up
TempEvent.all.each do |event|
# Create dummy user, if user doesn't exist
unless (user = User.find_by(email: 'deleted@localhost.osem'))
user = User.new(email: 'deleted@localhost.osem', name: 'User deleted',
biography: 'Data is no longer available for deleted user.',
password: Devise.friendly_token[0, 20])
user.skip_confirmation!
user.save!
end
event_users = TempEventUser.where(event_id: event)
if event_users.blank?
# Non existing users for event
TempEventUser.create!(event_id: event.id, user_id: user.id, event_role: 'submitter')
TempEventUser.create!(event_id: event.id, user_id: user.id, event_role: 'speaker')
else
# Wrong records in event_users
event_users.each do |eu|
unless eu.temp_user.present?
eu.user_id = user.id
eu.save!
end
end
end
end
end
def down
raise ActiveRecord::IrreversibleMigration.new('Cannot reverse migration.')
end
end

View file

@ -0,0 +1,44 @@
class AssignUsersToEvents < ActiveRecord::Migration
class TempEvent < ActiveRecord::Base
self.table_name = 'events'
end
class TempUser < ActiveRecord::Base
self.table_name = 'users'
attr_accessible :email, :name, :biography, :password
end
class TempEventUser < ActiveRecord::Base
self.table_name = 'event_users'
belongs_to :temp_event
belongs_to :temp_user
attr_accessible :event_id, :user_id, :event_role
end
def up
user_deleted = TempUser.find_or_create_by(email: 'deleted@localhost.osem', name: 'User deleted',
biography: 'Data is no longer available for deleted user.')
TempEvent.all.each do |event|
event_users = TempEventUser.where(event_id: event)
if event_users.blank?
# No users for event
TempEventUser.create!(event_id: event.id, user_id: user_deleted.id, event_role: 'submitter')
TempEventUser.create!(event_id: event.id, user_id: user_deleted.id, event_role: 'speaker')
else
# Wrong records in event_users
event_users.each do |eu|
event_user = TempUser.where(id: eu.user_id)
if event_user.blank?
eu.user_id = user_deleted.id
eu.save!
end
end
end
end
end
def down
raise ActiveRecord::IrreversibleMigration.new('Cannot reverse migration.')
end
end

View file

@ -0,0 +1,51 @@
class UndoWrongMigration20140801080705AddUsersToEvents < ActiveRecord::Migration
class TempEvent < ActiveRecord::Base
self.table_name = 'events'
end
class TempUser < ActiveRecord::Base
self.table_name = 'users'
end
class TempEventUser < ActiveRecord::Base
self.table_name = 'event_users'
belongs_to :temp_event
belongs_to :temp_user
attr_accessible :event_id, :user_id, :event_role
end
class Version < ActiveRecord::Base
self.table_name = 'versions'
end
def up
if ActiveRecord::Migrator.get_all_versions.include? 20140801080705
user_deleted = TempUser.find_by(email: 'deleted@localhost.osem')
TempEvent.all.each do |event|
whodunnit = Version.find_by(item_type: 'Event', item_id: event.id, event: 'create').whodunnit
original_user = TempUser.find_by(id: whodunnit)
if original_user.blank?
original_submitter = user_deleted
else
original_submitter = original_user
end
# Substitute submitter record
submitter = TempEventUser.find_by(event_id: event.id, event_role: 'submitter')
submitter.user_id = original_submitter.id
submitter.save!
# Substitute speaker record
speaker = TempEventUser.find_by(event_id: event.id, event_role: 'speaker')
speaker.user_id = original_submitter.id
speaker.save!
end
end
end
def down
raise ActiveRecord::IrreversibleMigration.new('Cannot reverse migration.')
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: 20140812065531) do
ActiveRecord::Schema.define(version: 20140820124117) do
create_table "ahoy_events", force: true do |t|
t.uuid "visit_id"
@ -21,27 +21,27 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.datetime "time"
end
add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time"
add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id"
add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id"
add_index "ahoy_events", ["time"], name: "index_ahoy_events_on_time", using: :btree
add_index "ahoy_events", ["user_id"], name: "index_ahoy_events_on_user_id", using: :btree
add_index "ahoy_events", ["visit_id"], name: "index_ahoy_events_on_visit_id", using: :btree
create_table "answers", force: true do |t|
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "call_for_papers", force: true do |t|
t.date "start_date", null: false
t.date "end_date", null: false
t.text "description", null: false
t.date "start_date", null: false
t.date "end_date", null: false
t.text "description", limit: 16777215, null: false
t.integer "conference_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "schedule_changes", default: false
t.integer "rating", default: 3
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "schedule_changes", default: false
t.integer "rating", default: 3
t.boolean "schedule_public"
t.boolean "include_cfp_in_splash", default: false
t.boolean "include_cfp_in_splash", default: false
end
create_table "campaigns", force: true do |t|
@ -57,22 +57,22 @@ ActiveRecord::Schema.define(version: 20140812065531) do
end
create_table "comments", force: true do |t|
t.string "title", limit: 50, default: ""
t.text "body"
t.string "title", limit: 50, default: ""
t.text "body", limit: 16777215
t.integer "commentable_id"
t.string "commentable_type"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "subject"
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
end
add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id"
add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type"
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
add_index "comments", ["commentable_id"], name: "index_comments_on_commentable_id", using: :btree
add_index "comments", ["commentable_type"], name: "index_comments_on_commentable_type", using: :btree
add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree
create_table "commercials", force: true do |t|
t.string "commercial_id"
@ -92,8 +92,8 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.date "start_date", null: false
t.date "end_date", null: false
t.integer "venue_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "logo_file_name"
t.string "logo_content_type"
t.integer "logo_file_size"
@ -111,12 +111,12 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.text "sponsor_description"
t.string "sponsor_email"
t.text "lodging_description"
t.boolean "make_conference_public", default: false
t.boolean "include_registrations_in_splash", default: false
t.boolean "include_sponsors_in_splash", default: false
t.boolean "include_tracks_in_splash", default: false
t.boolean "include_tickets_in_splash", default: false
t.boolean "include_program_in_splash", default: false
t.boolean "make_conference_public", default: false
t.string "banner_photo_file_name"
t.string "banner_photo_content_type"
t.integer "banner_photo_file_size"
@ -157,13 +157,13 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.datetime "updated_at"
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority"
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
create_table "dietary_choices", force: true do |t|
t.integer "conference_id"
t.string "title", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "difficulty_levels", force: true do |t|
@ -171,37 +171,37 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.string "title"
t.text "description"
t.string "color"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "email_settings", force: true do |t|
t.integer "conference_id"
t.boolean "send_on_registration", default: false
t.boolean "send_on_accepted", default: false
t.boolean "send_on_rejected", default: false
t.boolean "send_on_confirmed_without_registration", default: false
t.text "registration_email_template"
t.text "accepted_email_template"
t.text "rejected_email_template"
t.text "confirmed_email_template"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "send_on_registration", default: false
t.boolean "send_on_accepted", default: false
t.boolean "send_on_rejected", default: false
t.boolean "send_on_confirmed_without_registration", default: false
t.text "registration_email_template", limit: 16777215
t.text "accepted_email_template", limit: 16777215
t.text "rejected_email_template", limit: 16777215
t.text "confirmed_email_template", limit: 16777215
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "registration_subject"
t.string "accepted_subject"
t.string "rejected_subject"
t.string "confirmed_without_registration_subject"
t.boolean "send_on_updated_conference_dates", default: false
t.boolean "send_on_updated_conference_dates", default: false
t.string "updated_conference_dates_subject"
t.text "updated_conference_dates_template"
t.boolean "send_on_updated_conference_registration_dates", default: false
t.boolean "send_on_updated_conference_registration_dates", default: false
t.string "updated_conference_registration_dates_subject"
t.text "updated_conference_registration_dates_template"
t.boolean "send_on_venue_update", default: false
t.boolean "send_on_venue_update", default: false
t.string "venue_update_subject"
t.text "venue_update_template"
t.boolean "send_on_call_for_papers_dates_updates", default: false
t.boolean "send_on_call_for_papers_schedule_public", default: false
t.boolean "send_on_call_for_papers_dates_updates", default: false
t.boolean "send_on_call_for_papers_schedule_public", default: false
t.string "call_for_papers_schedule_public_subject"
t.string "call_for_papers_dates_updates_subject"
t.text "call_for_papers_schedule_public_template"
@ -210,14 +210,24 @@ ActiveRecord::Schema.define(version: 20140812065531) do
create_table "event_attachments", force: true do |t|
t.integer "event_id"
t.string "title", null: false
t.string "title", null: false
t.string "attachment_file_name"
t.string "attachment_content_type"
t.integer "attachment_file_size"
t.datetime "attachment_updated_at"
t.boolean "public", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "public", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "event_people", force: true do |t|
t.integer "proposal_id"
t.integer "person_id"
t.integer "event_id"
t.string "event_role", default: "participant", null: false
t.string "comment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "event_types", force: true do |t|
@ -239,28 +249,28 @@ ActiveRecord::Schema.define(version: 20140812065531) do
end
create_table "events", force: true do |t|
t.string "guid", null: false
t.string "guid", null: false
t.integer "conference_id"
t.integer "event_type_id"
t.string "title", null: false
t.string "title", null: false
t.string "subtitle"
t.integer "time_slots"
t.string "state", default: "new", null: false
t.string "progress", default: "new", null: false
t.string "state", default: "new", null: false
t.string "progress", default: "new", null: false
t.string "language"
t.datetime "start_time"
t.text "abstract"
t.text "description"
t.boolean "public", default: true
t.text "abstract", limit: 16777215
t.text "description", limit: 16777215
t.boolean "public", default: true
t.string "logo_file_name"
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
t.text "proposal_additional_speakers"
t.text "proposal_additional_speakers", limit: 16777215
t.integer "track_id"
t.integer "room_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "require_registration"
t.integer "difficulty_level_id"
t.integer "week"
@ -293,6 +303,29 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.datetime "updated_at"
end
create_table "people", force: true do |t|
t.string "guid", null: false
t.text "first_name"
t.text "last_name"
t.text "public_name"
t.text "company"
t.string "email", null: false
t.boolean "email_public"
t.string "avatar_file_name"
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.text "biography"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "irc_nickname"
t.text "volunteer_experience"
t.string "tshirt"
t.string "mobile"
t.string "languages"
end
create_table "photos", force: true do |t|
t.text "description"
t.string "picture_file_name"
@ -316,8 +349,8 @@ ActiveRecord::Schema.define(version: 20140812065531) do
create_table "question_types", force: true do |t|
t.string "title"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "questions", force: true do |t|
@ -325,8 +358,8 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.integer "question_type_id"
t.integer "conference_id"
t.boolean "global"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "registration_periods", force: true do |t|
@ -340,18 +373,18 @@ ActiveRecord::Schema.define(version: 20140812065531) do
create_table "registrations", force: true do |t|
t.integer "conference_id"
t.boolean "attending_social_events", default: true
t.boolean "attending_with_partner", default: false
t.boolean "using_affiliated_lodging", default: false
t.boolean "attending_social_events", default: true
t.boolean "attending_with_partner", default: false
t.boolean "using_affiliated_lodging", default: false
t.datetime "arrival"
t.datetime "departure"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "dietary_choice_id"
t.text "other_dietary_choice"
t.boolean "handicapped_access_required", default: false
t.text "other_special_needs"
t.boolean "attended", default: false
t.text "other_dietary_choice", limit: 16777215
t.boolean "handicapped_access_required", default: false
t.text "other_special_needs", limit: 16777215
t.boolean "attended", default: false
t.boolean "volunteer"
t.integer "user_id"
t.integer "week"
@ -369,22 +402,22 @@ ActiveRecord::Schema.define(version: 20140812065531) do
create_table "roles", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "description"
t.integer "resource_id"
t.string "resource_type"
end
add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
add_index "roles", ["name"], name: "index_roles_on_name"
add_index "roles", ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree
add_index "roles", ["name"], name: "index_roles_on_name", using: :btree
create_table "roles_users", id: false, force: true do |t|
t.integer "role_id"
t.integer "user_id"
end
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id"
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id", using: :btree
create_table "rooms", force: true do |t|
t.string "guid", null: false
@ -459,13 +492,13 @@ ActiveRecord::Schema.define(version: 20140812065531) do
end
create_table "tracks", force: true do |t|
t.string "guid", null: false
t.string "guid", null: false
t.integer "conference_id"
t.string "name", null: false
t.text "description"
t.string "name", null: false
t.text "description", limit: 16777215
t.string "color"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "users", force: true do |t|
@ -483,8 +516,8 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.boolean "email_public"
t.text "biography"
@ -501,9 +534,9 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.boolean "is_admin", default: false
end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "vchoices", force: true do |t|
t.integer "vday_id"
@ -514,39 +547,39 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.integer "conference_id"
t.date "day"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "venues", force: true do |t|
t.string "guid"
t.text "name", limit: 255
t.text "address", limit: 255
t.text "name"
t.text "address"
t.string "website"
t.text "description"
t.string "offline_map_url"
t.string "offline_map_bounds"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
t.boolean "include_venue_in_splash", default: false
t.boolean "include_lodgings_in_splash", default: false
t.boolean "include_venue_in_splash", default: false
t.boolean "include_lodgings_in_splash", default: false
end
create_table "versions", force: true do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.text "object_changes"
t.text "object", limit: 16777215
t.text "object_changes", limit: 16777215
t.datetime "created_at"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
create_table "visits", force: true do |t|
t.uuid "visitor_id"
@ -571,13 +604,13 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.datetime "started_at"
end
add_index "visits", ["user_id"], name: "index_visits_on_user_id"
add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree
create_table "votes", force: true do |t|
t.integer "event_id"
t.integer "rating"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
@ -585,8 +618,8 @@ ActiveRecord::Schema.define(version: 20140812065531) do
t.integer "conference_id"
t.string "title", null: false
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end