diff --git a/CHANGELOG.md b/CHANGELOG.md index 1efaefd..471ea5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ + * Update choices to act_as_versioned + ## Pairwise 3.0.1 (Apr 16, 2012) ### * Added votes_per_uploaded_choice call to API diff --git a/app/models/choice.rb b/app/models/choice.rb index 09b975a..c42f81a 100644 --- a/app/models/choice.rb +++ b/app/models/choice.rb @@ -1,4 +1,5 @@ class Choice < ActiveRecord::Base + acts_as_versioned belongs_to :question, :counter_cache => true belongs_to :creator, :class_name => "Visitor", :foreign_key => "creator_id" diff --git a/db/migrate/20120426144214_add_version_to_choice.rb b/db/migrate/20120426144214_add_version_to_choice.rb new file mode 100644 index 0000000..2be181c --- /dev/null +++ b/db/migrate/20120426144214_add_version_to_choice.rb @@ -0,0 +1,28 @@ +class AddVersionToChoice < ActiveRecord::Migration + def self.up + # if you want to manually run the query to create + # all the initial versions in choice_versions table set this to true + run_query_manually = true + # default of 1 so all existing rows have a version of 1 + add_column :choices, :version, :integer, :default => 1 + # make version nil by default + change_column :choices, :version, :integer, :default => nil + Choice.create_versioned_table + query = "INSERT INTO choice_versions (SELECT null, id, version, item_id, question_id, position, ratings, created_at, updated_at, request_id, prompt_id, active, tracking, score, local_identifier, prompts_on_the_left_count, prompts_on_the_right_count, wins, losses, prompts_count, data, creator_id FROM choices)" + if run_query_manually + puts "!!!!!!!!!!!!!!!" + puts "RUN THIS QUERY:" + puts "!!!!!!!!!!!!!!!" + puts "" + puts query + puts "" + else + Choice.connection.execute(query) + end + end + + def self.down + remove_column :choices, :version + Choice.drop_versioned_table + end +end diff --git a/db/schema.rb b/db/schema.rb index b603a7f..da0ad6b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111017171903) do +ActiveRecord::Schema.define(:version => 20120426144214) do create_table "appearances", :force => true do |t| t.integer "voter_id" @@ -30,6 +30,32 @@ ActiveRecord::Schema.define(:version => 20111017171903) do add_index "appearances", ["prompt_id"], :name => "index_appearances_on_prompt_id" add_index "appearances", ["question_id", "voter_id"], :name => "index_appearances_on_question_id_voter_id" + create_table "choice_versions", :force => true do |t| + t.integer "choice_id" + t.integer "version" + t.integer "item_id" + t.integer "question_id" + t.integer "position" + t.integer "ratings" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "request_id" + t.integer "prompt_id" + t.boolean "active", :default => false + t.text "tracking" + t.float "score" + t.string "local_identifier" + t.integer "prompts_on_the_left_count", :default => 0 + t.integer "prompts_on_the_right_count", :default => 0 + t.integer "wins", :default => 0 + t.integer "losses", :default => 0 + t.integer "prompts_count", :default => 0 + t.string "data" + t.integer "creator_id" + end + + add_index "choice_versions", ["choice_id"], :name => "index_choice_versions_on_choice_id" + create_table "choices", :force => true do |t| t.integer "item_id" t.integer "question_id" @@ -50,6 +76,7 @@ ActiveRecord::Schema.define(:version => 20111017171903) do t.integer "prompts_count", :default => 0 t.string "data" t.integer "creator_id" + t.integer "version" end add_index "choices", ["creator_id"], :name => "index_choices_on_creator_id" -- libgit2 0.21.2