From c84b2f0704ddafdbbcee3b96ee3a903801c96a24 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 29 Jan 2018 21:47:01 +0100 Subject: [PATCH] Add valuation boolean flag to Comment model Why: Budget Investment's valuators need to be able to comment on investments without making those comments public. We need a way to clearly make a distinction to avoid "leaking" internal valuation comments. How: Adding a boolean `valuation` attribute defaulted to false to the Comments table, and index on it with concurrent algorithm as explained at https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in The name `valuation` was chosen instead of `internal` because of the more specific meaning as well as avoiding a collision with existing internal_comments attribute on Budget::Investment model (soon to be deprecated & removed) --- .../20180129190931_add_valuation_flag_to_comments.rb | 5 +++++ .../20180129190950_add_index_to_valuation_comments.rb | 7 +++++++ db/schema.rb | 8 +++++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180129190931_add_valuation_flag_to_comments.rb create mode 100644 db/migrate/20180129190950_add_index_to_valuation_comments.rb diff --git a/db/migrate/20180129190931_add_valuation_flag_to_comments.rb b/db/migrate/20180129190931_add_valuation_flag_to_comments.rb new file mode 100644 index 000000000..cf31a92e7 --- /dev/null +++ b/db/migrate/20180129190931_add_valuation_flag_to_comments.rb @@ -0,0 +1,5 @@ +class AddValuationFlagToComments < ActiveRecord::Migration + def change + add_column :comments, :valuation, :boolean, default: false + end +end diff --git a/db/migrate/20180129190950_add_index_to_valuation_comments.rb b/db/migrate/20180129190950_add_index_to_valuation_comments.rb new file mode 100644 index 000000000..2816d15b0 --- /dev/null +++ b/db/migrate/20180129190950_add_index_to_valuation_comments.rb @@ -0,0 +1,7 @@ +class AddIndexToValuationComments < ActiveRecord::Migration + disable_ddl_transaction! + + def change + add_index :comments, :valuation, algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 219707f69..a6fc6ef88 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: 20180119073228) do +ActiveRecord::Schema.define(version: 20180129190950) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -234,7 +234,7 @@ ActiveRecord::Schema.define(version: 20180119073228) do t.string "commentable_type" t.text "body" t.string "subject" - t.integer "user_id", null: false + t.integer "user_id", null: false t.datetime "created_at" t.datetime "updated_at" t.datetime "hidden_at" @@ -247,7 +247,8 @@ ActiveRecord::Schema.define(version: 20180119073228) do t.integer "cached_votes_down", default: 0 t.datetime "confirmed_hide_at" t.string "ancestry" - t.integer "confidence_score", default: 0, null: false + t.integer "confidence_score", default: 0, null: false + t.boolean "valuation", default: false end add_index "comments", ["ancestry"], name: "index_comments_on_ancestry", using: :btree @@ -257,6 +258,7 @@ ActiveRecord::Schema.define(version: 20180119073228) do add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type", using: :btree add_index "comments", ["hidden_at"], name: "index_comments_on_hidden_at", using: :btree add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree + add_index "comments", ["valuation"], name: "index_comments_on_valuation", using: :btree create_table "communities", force: :cascade do |t| t.datetime "created_at", null: false