Refactoring Tickets

- Tickets now independent from registration
- Implemented money gem
#419
This commit is contained in:
Chrisbr 2014-08-28 15:21:05 +02:00
parent 5485fe0e7f
commit 5f8a8ac6d9
63 changed files with 1581 additions and 573 deletions

View file

@ -0,0 +1,9 @@
class RenameSupporterLevelToTicket < ActiveRecord::Migration
def up
rename_table :supporter_levels, :tickets
end
def down
rename_table :tickets, :supporter_levels
end
end

View file

@ -0,0 +1,69 @@
class MigratingSupporterRegistrationsToTicketUsers < ActiveRecord::Migration
class TempSupporterRegistrations < ActiveRecord::Base
self.table_name = 'supporter_registrations'
attr_accessible :conference_id, :supporter_level_id, :registration_id, :user_id
end
class TempUser < ActiveRecord::Base
self.table_name = 'users'
attr_accessible :user_id
end
class TempRegistration < ActiveRecord::Base
self.table_name = 'registrations'
attr_accessible :user_id
end
def change
rename_column :supporter_registrations, :supporter_level_id, :ticket_id
rename_column :supporter_registrations, :code_is_valid, :paid
add_column :supporter_registrations, :quantity, :integer, default: 1
add_column :supporter_registrations, :user_id, :integer
deleted_user = TempUser.find_by(email: 'deleted@localhost.osem')
TempSupporterRegistrations.all.each do |s|
# Change relation from registration to user
registration = TempRegistration.find_by(id: s.registration_id)
if registration
user = TempUser.find_by(id: registration.user_id)
if user
s.user_id = user.id
s.save
end
end
if !s.user_id
s.user_id = deleted_user.id
s.save
end
end
# Sum up if a user has bought more than one ticket
TempSupporterRegistrations.all.each do |s|
sup_reg = TempSupporterRegistrations.where(
ticket_id: s.ticket_id,
user_id: s.user_id,
conference_id: s.conference_id)
quantity = sup_reg.count
if quantity > 1
# Save the amount in the first one
s.quantity = quantity
s.save
# Delete the other
sup_reg = sup_reg.where('id not in (?)', [s.id])
sup_reg.destroy_all
end
end
remove_column :supporter_registrations, :registration_id
remove_column :supporter_registrations, :code
remove_column :supporter_registrations, :name
remove_column :supporter_registrations, :email
remove_column :conferences, :use_supporter_levels
rename_table :supporter_registrations, :ticket_purchases
end
end

View file

@ -0,0 +1,27 @@
class SplitTicketPriceInPriceAndCurrency < ActiveRecord::Migration
class TempTicket < ActiveRecord::Base
self.table_name = 'tickets'
attr_accessible :ticket_price, :price_cents, :price_currency
end
def change
add_money :tickets, :price
TempTicket.all.each do |ticket|
# Replace currency symbol with ISO Code
ticket.ticket_price.gsub!('€', 'EUR')
ticket.ticket_price.gsub!('$', 'USD')
ticket.ticket_price.gsub!('£', 'GBP')
ticket.ticket_price.gsub!('¥', 'CNY')
ticket.ticket_price.gsub!('₹', 'INR')
money = ticket.ticket_price.to_money
ticket.price_cents = money.cents
ticket.price_currency = money.currency_as_string
ticket.save
end
remove_column :tickets, :ticket_price
remove_column :tickets, :url
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: 20140820124117) do
ActiveRecord::Schema.define(version: 20140821103643) do
create_table "ahoy_events", force: true do |t|
t.uuid "visit_id"
@ -21,27 +21,27 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "time"
end
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
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"
create_table "answers", force: true do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
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", limit: 16777215, null: false
t.date "start_date", null: false
t.date "end_date", null: false
t.text "description", null: false
t.integer "conference_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "schedule_changes", default: false
t.integer "rating", default: 3
t.datetime "created_at"
t.datetime "updated_at"
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: 20140820124117) do
end
create_table "comments", force: true do |t|
t.string "title", limit: 50, default: ""
t.text "body", limit: 16777215
t.string "title", limit: 50, default: ""
t.text "body"
t.integer "commentable_id"
t.string "commentable_type"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
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", 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
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"
create_table "commercials", force: true do |t|
t.string "commercial_id"
@ -92,14 +92,13 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.date "start_date", null: false
t.date "end_date", null: false
t.integer "venue_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "logo_file_name"
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
t.boolean "use_dietary_choices", default: false
t.boolean "use_supporter_levels", default: false
t.integer "revision"
t.boolean "use_vpositions", default: false
t.boolean "use_vdays", default: false
@ -111,12 +110,12 @@ ActiveRecord::Schema.define(version: 20140820124117) 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 +156,13 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "updated_at"
end
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority"
create_table "dietary_choices", force: true do |t|
t.integer "conference_id"
t.string "title", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "difficulty_levels", force: true do |t|
@ -171,37 +170,37 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.string "title"
t.text "description"
t.string "color"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
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", 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.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.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,24 +209,14 @@ ActiveRecord::Schema.define(version: 20140820124117) 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: 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
t.boolean "public", default: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "event_types", force: true do |t|
@ -249,28 +238,28 @@ ActiveRecord::Schema.define(version: 20140820124117) 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", limit: 16777215
t.text "description", limit: 16777215
t.boolean "public", default: true
t.text "abstract"
t.text "description"
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", limit: 16777215
t.text "proposal_additional_speakers"
t.integer "track_id"
t.integer "room_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "require_registration"
t.integer "difficulty_level_id"
t.integer "week"
@ -303,29 +292,6 @@ ActiveRecord::Schema.define(version: 20140820124117) 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"
@ -349,8 +315,8 @@ ActiveRecord::Schema.define(version: 20140820124117) do
create_table "question_types", force: true do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "questions", force: true do |t|
@ -358,8 +324,8 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.integer "question_type_id"
t.integer "conference_id"
t.boolean "global"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "registration_periods", force: true do |t|
@ -373,18 +339,18 @@ ActiveRecord::Schema.define(version: 20140820124117) 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", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "dietary_choice_id"
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.text "other_dietary_choice"
t.boolean "handicapped_access_required", default: false
t.text "other_special_needs"
t.boolean "attended", default: false
t.boolean "volunteer"
t.integer "user_id"
t.integer "week"
@ -402,22 +368,22 @@ ActiveRecord::Schema.define(version: 20140820124117) do
create_table "roles", force: true do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
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", using: :btree
add_index "roles", ["name"], name: "index_roles_on_name", using: :btree
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"
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", using: :btree
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id"
create_table "rooms", force: true do |t|
t.string "guid", null: false
@ -462,25 +428,6 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "updated_at"
end
create_table "supporter_levels", force: true do |t|
t.integer "conference_id"
t.string "title", null: false
t.string "url"
t.text "description"
t.string "ticket_price"
end
create_table "supporter_registrations", force: true do |t|
t.integer "registration_id"
t.integer "supporter_level_id"
t.integer "conference_id"
t.string "name"
t.string "email"
t.string "code"
t.boolean "code_is_valid", default: false
t.datetime "created_at"
end
create_table "targets", force: true do |t|
t.integer "conference_id"
t.integer "campaign_id"
@ -491,14 +438,31 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "updated_at"
end
create_table "tracks", force: true do |t|
t.string "guid", null: false
create_table "ticket_purchases", force: true do |t|
t.integer "ticket_id"
t.integer "conference_id"
t.string "name", null: false
t.text "description", limit: 16777215
t.boolean "paid", default: false
t.datetime "created_at"
t.integer "quantity", default: 1
t.integer "user_id"
end
create_table "tickets", force: true do |t|
t.integer "conference_id"
t.string "title", null: false
t.text "description"
t.integer "price_cents", default: 0, null: false
t.string "price_currency", default: "USD", null: false
end
create_table "tracks", force: true do |t|
t.string "guid", null: false
t.integer "conference_id"
t.string "name", null: false
t.text "description"
t.string "color"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", force: true do |t|
@ -516,8 +480,8 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
t.boolean "email_public"
t.text "biography"
@ -534,9 +498,9 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.boolean "is_admin", default: false
end
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
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
create_table "vchoices", force: true do |t|
t.integer "vday_id"
@ -547,39 +511,39 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.integer "conference_id"
t.date "day"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "venues", force: true do |t|
t.string "guid"
t.text "name"
t.text "address"
t.text "name", limit: 255
t.text "address", limit: 255
t.string "website"
t.text "description"
t.string "offline_map_url"
t.string "offline_map_bounds"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
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", limit: 16777215
t.text "object_changes", limit: 16777215
t.text "object"
t.text "object_changes"
t.datetime "created_at"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
create_table "visits", force: true do |t|
t.uuid "visitor_id"
@ -604,13 +568,13 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.datetime "started_at"
end
add_index "visits", ["user_id"], name: "index_visits_on_user_id", using: :btree
add_index "visits", ["user_id"], name: "index_visits_on_user_id"
create_table "votes", force: true do |t|
t.integer "event_id"
t.integer "rating"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end
@ -618,8 +582,8 @@ ActiveRecord::Schema.define(version: 20140820124117) do
t.integer "conference_id"
t.string "title", null: false
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at"
t.datetime "updated_at"
end
end