Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Remove obsolete community_id columns #1

Open
wants to merge 3 commits into
base: 2361-make_community_polymorphic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/models/community.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ def communitable_key
communitable_type.split("::").last.underscore
end

# @deprecated Please use {#communitable} instead
def proposal
warn "[DEPRECATION] `Community#proposal` is deprecated. " +
"Please use `Community#communitable` instead."
communitable
end

# @deprecated Please use {#communitable} instead
def investment
warn "[DEPRECATION] `Community#investment` is deprecated. " +
"Please use `Community#communitable` instead."
communitable
end

private

def users_who_commented
Expand Down
3 changes: 0 additions & 3 deletions app/models/concerns/communitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module Communitable
def associate_community
community = Community.create
self.community = community

# TODO: remove once databases migrate to communitable columns.
self.community_id = community.id
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveObsoleteCommunityIdColumns < ActiveRecord::Migration
def change
remove_column :proposals, :community_id
remove_column :budget_investments, :community_id
end
end
6 changes: 1 addition & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180723093127) do
ActiveRecord::Schema.define(version: 20180807113601) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -195,14 +195,12 @@
t.integer "previous_heading_id"
t.boolean "winner", default: false
t.boolean "incompatible", default: false
t.integer "community_id"
t.boolean "visible_to_valuators", default: false
t.integer "valuator_group_assignments_count", default: 0
end

add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
add_index "budget_investments", ["author_id"], name: "index_budget_investments_on_author_id", using: :btree
add_index "budget_investments", ["community_id"], name: "index_budget_investments_on_community_id", using: :btree
add_index "budget_investments", ["heading_id"], name: "index_budget_investments_on_heading_id", using: :btree
add_index "budget_investments", ["tsv"], name: "index_budget_investments_on_tsv", using: :gin

Expand Down Expand Up @@ -917,13 +915,11 @@
t.datetime "retired_at"
t.string "retired_reason"
t.text "retired_explanation"
t.integer "community_id"
end

add_index "proposals", ["author_id", "hidden_at"], name: "index_proposals_on_author_id_and_hidden_at", using: :btree
add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree
add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree
add_index "proposals", ["community_id"], name: "index_proposals_on_community_id", using: :btree
add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree
add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree
add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree
Expand Down
24 changes: 0 additions & 24 deletions lib/tasks/communities.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,4 @@ namespace :communities do
end
end
end

desc "Migrate communitable data to communitable columns"
task migrate_communitable: :environment do
(Proposal.all + Budget::Investment.all).each do |communitable|
if communitable.community_id.present?
community = Community.where(id: communitable.community_id).first

if community
community.update(
communitable_id: communitable.id,
communitable_type: communitable.class.name
)
else
warn "WARNING: The community associated to #{communitable.class.name} "\
"with ID #{communitable.id} no longer exists. "\
"Consider running `rake communities: associate_community`"
end
else
warn "WARNING: #{communitable.class.name} with ID #{communitable.id} "\
"should have an associated community. "\
"Consider running `rake communities: associate_community`"
end
end
end
end
76 changes: 0 additions & 76 deletions spec/lib/tasks/communities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,80 +44,4 @@
end

end

describe "#migrate_communitable" do
let :run_rake_task do
Rake::Task["communities:migrate_communitable"].reenable
Rake.application.invoke_task "communities:migrate_communitable"
end

context "Associate community to Proposal" do
let(:proposal) { create(:proposal) }
let(:community) { proposal.community }

context "Community has no communitable_id" do
before { community.update(communitable_id: nil, communitable_type: nil) }

it "assigns the communitable_id" do
run_rake_task
community.reload
expect(community.communitable_id).to eq proposal.id
expect(community.communitable_type).to eq "Proposal"
end
end

context "Proposal has no community_id" do
before { proposal.update_column(:community_id, nil) }

it "writes a warning with the proposal id" do
warning = /Proposal(.+)#{proposal.id}(.+)should have an associated/
expect { run_rake_task }.to output(warning).to_stderr
end
end

context "The proposal community doesn't exist anymore" do
before { community.destroy }

it "writes a warning with the proposal id" do
warning = /community(.+)Proposal(.+)#{proposal.id}(.+)no longer exists/
expect { run_rake_task }.to output(warning).to_stderr
end
end
end

context "Associate community to Budget Investment" do
let(:investment) { create(:budget_investment) }
let(:community) { investment.community }

context "Community has no communitable_id" do
before { community.update(communitable_id: nil, communitable_type: nil) }

it "assigns the communitable_id" do
run_rake_task
community.reload
expect(community.communitable_id).to eq investment.id
expect(community.communitable_type).to eq "Budget::Investment"
end
end

context "Investment has no community_id" do
before { investment.update_column(:community_id, nil) }

it "writes a warning with the investment id" do
warning = /Investment(.+)#{investment.id}(.+)should have an associated/
expect { run_rake_task }.to output(warning).to_stderr
end
end

context "The investment community doesn't exist anymore" do
before { community.destroy }

it "writes a warning with the investment id" do
warning = /community(.+)Investment(.+)#{investment.id}(.+)no longer exists/
expect { run_rake_task }.to output(warning).to_stderr
end
end
end

end
end
4 changes: 0 additions & 4 deletions spec/shared/models/communitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
expect(community.communitable).to eq communitable
end

it "assigns the community id to the communitable object" do
expect(communitable.community_id).to eq community.id
end

it "assigns the communitable id to the community" do
expect(community.communitable_id).to eq communitable.id
end
Expand Down