diff --git a/config/deploy.rb b/config/deploy.rb index f73c21832..8c53126e2 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -48,11 +48,9 @@ namespace :deploy do after :updating, "rvm1:install:rvm" after :updating, "rvm1:install:ruby" after :updating, "install_bundler_gem" - before "deploy:migrate", "remove_local_census_records_duplicates" after "deploy:migrate", "add_new_settings" - before :publishing, "smtp_ssl_and_delay_jobs_secrets" after :publishing, "setup_puma" after :published, "deploy:restart" @@ -76,16 +74,6 @@ task :install_bundler_gem do end end -task :remove_local_census_records_duplicates do - on roles(:db) do - within release_path do - with rails_env: fetch(:rails_env) do - execute :rake, "local_census_records:remove_duplicates" - end - end - end -end - task :refresh_sitemap do on roles(:app) do within release_path do @@ -116,49 +104,12 @@ task :execute_release_tasks do end end -desc "Create pid and socket folders needed by puma and convert unicorn sockets into symbolic links \ - to the puma socket, so legacy nginx configurations pointing to the unicorn socket keep working" +desc "Create pid and socket folders needed by puma" task :setup_puma do on roles(:app) do with rails_env: fetch(:rails_env) do execute "mkdir -p #{shared_path}/tmp/sockets; true" execute "mkdir -p #{shared_path}/tmp/pids; true" - - if test("[ -e #{shared_path}/tmp/sockets/unicorn.sock ]") - execute "ln -sf #{shared_path}/tmp/sockets/puma.sock #{shared_path}/tmp/sockets/unicorn.sock; true" - end - - if test("[ -e #{shared_path}/sockets/unicorn.sock ]") - execute "ln -sf #{shared_path}/tmp/sockets/puma.sock #{shared_path}/sockets/unicorn.sock; true" - end - end - end -end - -task :smtp_ssl_and_delay_jobs_secrets do - on roles(:app) do - if test("[ -d #{current_path} ]") - within current_path do - with rails_env: fetch(:rails_env) do - tasks_file_path = "lib/tasks/secrets.rake" - shared_secrets_path = "#{shared_path}/config/secrets.yml" - - unless test("[ -e #{current_path}/#{tasks_file_path} ]") - begin - unless test("[ -w #{shared_secrets_path} ]") - execute "sudo chown `whoami` #{shared_secrets_path}" - execute "chmod u+w #{shared_secrets_path}" - end - - execute "cp #{release_path}/#{tasks_file_path} #{current_path}/#{tasks_file_path}" - - execute :rake, "secrets:smtp_ssl_and_delay_jobs" - ensure - execute "rm #{current_path}/#{tasks_file_path}" - end - end - end - end end end end diff --git a/lib/tasks/budgets.rake b/lib/tasks/budgets.rake index 4efe30ee5..172944420 100644 --- a/lib/tasks/budgets.rake +++ b/lib/tasks/budgets.rake @@ -10,15 +10,4 @@ namespace :budgets do Budget.last.email_unselected end end - - desc "Update investments original_heading_id with current heading_id" - task set_original_heading_id: :environment do - ApplicationLogger.new.info "Setting original_heading_id to investments" - Budget::Investment.find_each do |investment| - unless investment.original_heading_id.present? - investment.update_column(:original_heading_id, investment.heading_id) - end - print "." - end - end end diff --git a/lib/tasks/consul.rake b/lib/tasks/consul.rake index 4116a8fd0..b831c59f4 100644 --- a/lib/tasks/consul.rake +++ b/lib/tasks/consul.rake @@ -1,13 +1,5 @@ namespace :consul do desc "Runs tasks needed to upgrade to the latest version" task execute_release_tasks: ["settings:rename_setting_keys", - "settings:add_new_settings", - "execute_release_1.1.0_tasks"] - - desc "Runs tasks needed to upgrade from 1.0.0 to 1.1.0" - task "execute_release_1.1.0_tasks": [ - "budgets:set_original_heading_id", - "migrations:valuation_taggings", - "migrations:budget_admins_and_valuators" - ] + "settings:add_new_settings"] end diff --git a/lib/tasks/local_census_records.rake b/lib/tasks/local_census_records.rake deleted file mode 100644 index 64ad7d383..000000000 --- a/lib/tasks/local_census_records.rake +++ /dev/null @@ -1,13 +0,0 @@ -namespace :local_census_records do - desc "Remove duplicated records from database" - task remove_duplicates: :environment do - ids = LocalCensusRecord.group(:document_type, :document_number).pluck("MIN(id) as id") - duplicates = LocalCensusRecord.count - ids.size - - if duplicates > 0 - ApplicationLogger.new.info "Removing local census records duplicates" - LocalCensusRecord.where("id NOT IN (?)", ids).destroy_all - ApplicationLogger.new.info "Removed #{duplicates} records." - end - end -end diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake deleted file mode 100644 index f545b620e..000000000 --- a/lib/tasks/migrations.rake +++ /dev/null @@ -1,20 +0,0 @@ -namespace :migrations do - desc "Migrates context of valuation taggings" - task valuation_taggings: :environment do - ApplicationLogger.new.info "Updating valuation taggings context" - Tagging.where(context: "valuation").update_all(context: "valuation_tags") - end - - desc "Migrates budget staff" - task budget_admins_and_valuators: :environment do - ApplicationLogger.new.info "Updating budget administrators and valuators" - Budget.find_each do |budget| - investments = budget.investments.with_hidden - - budget.update!( - administrator_ids: investments.where.not(administrator: nil).distinct.pluck(:administrator_id), - valuator_ids: Budget::ValuatorAssignment.where(investment: investments).distinct.pluck(:valuator_id) - ) - end - end -end diff --git a/lib/tasks/secrets.rake b/lib/tasks/secrets.rake deleted file mode 100644 index 77c1d7344..000000000 --- a/lib/tasks/secrets.rake +++ /dev/null @@ -1,29 +0,0 @@ -namespace :secrets do - desc "Add SMTP, SSL and delay jobs settings to secrets.yml" - task smtp_ssl_and_delay_jobs: :environment do - current_settings = { - "mailer_delivery_method" => ActionMailer::Base.delivery_method, - "smtp_settings" => ActionMailer::Base.smtp_settings, - "force_ssl" => Rails.application.config.force_ssl, - "delay_jobs" => Delayed::Worker.delay_jobs - } - - settings_to_add = current_settings.select do |name, _| - Rails.application.secrets[name].nil? - end - - exit if settings_to_add.empty? - - secrets = Rails.application.config.paths["config/secrets"].first - stream = Psych.parse_stream(File.read(secrets)) - nodes = stream.children.first.children.first - - environment_index = nodes.children.index do |child| - child.is_a?(Psych::Nodes::Scalar) && child.value == Rails.env - end - - nodes.children[environment_index + 1].children.push(*Psych.parse(settings_to_add.to_yaml).children.first.children) - - File.open(secrets, "w") { |file| file.write stream.to_yaml } - end -end diff --git a/spec/lib/tasks/budgets_spec.rb b/spec/lib/tasks/budgets_spec.rb deleted file mode 100644 index f1cd161a6..000000000 --- a/spec/lib/tasks/budgets_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "rails_helper" - -describe Budget do - let(:run_rake_task) do - Rake::Task["budgets:set_original_heading_id"].reenable - Rake.application.invoke_task("budgets:set_original_heading_id") - end - - it "sets attribute original_heading_id for existing investments" do - heading = create(:budget_heading) - investment = create(:budget_investment, heading: heading) - investment.update!(original_heading_id: nil) - - expect(investment.original_heading_id).to equal(nil) - - run_rake_task - investment.reload - - expect(investment.original_heading_id).to equal(heading.id) - end - - it "does not overwrite original_heading_id when already present" do - original_heading = create(:budget_heading) - new_heading = create(:budget_heading) - investment = create(:budget_investment, heading: original_heading) - investment.update!(heading: new_heading) - - expect(investment.original_heading_id).to eq original_heading.id - - run_rake_task - investment.reload - - expect(investment.original_heading_id).to eq original_heading.id - end -end diff --git a/spec/lib/tasks/local_census_records_spec.rb b/spec/lib/tasks/local_census_records_spec.rb deleted file mode 100644 index cb0e3c00c..000000000 --- a/spec/lib/tasks/local_census_records_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require "rails_helper" -require Rails.root.join("db", "migrate", "20190530082138_add_unique_index_to_local_census_records") - -describe "LocalCensusRecord tasks" do - let(:run_rake_task) do - Rake::Task["local_census_records:remove_duplicates"].reenable - Rake.application.invoke_task("local_census_records:remove_duplicates") - end - - describe "#remove_duplicates" do - around do |example| - ActiveRecord::Migration.suppress_messages do - example.run - end - end - - before { AddUniqueIndexToLocalCensusRecords.new.down } - after { AddUniqueIndexToLocalCensusRecords.new.up } - - it "Remove all duplicates keeping older records" do - record1 = create(:local_census_record, document_type: "1", document_number: "#DOCUMENT_NUMBER") - record2 = create(:local_census_record, document_type: "2", document_number: "#DOCUMENT_NUMBER") - dup_record1 = build(:local_census_record, document_type: "1", document_number: "#DOCUMENT_NUMBER") - dup_record1.save!(validate: false) - dup_record2 = build(:local_census_record, document_type: "2", document_number: "#DOCUMENT_NUMBER") - dup_record2.save!(validate: false) - record3 = create(:local_census_record, document_type: "3", document_number: "#DOCUMENT_NUMBER") - - expect(LocalCensusRecord.count).to eq(5) - - run_rake_task - - expect(LocalCensusRecord.all).to match_array([record1, record2, record3]) - end - end -end diff --git a/spec/lib/tasks/migrations_spec.rb b/spec/lib/tasks/migrations_spec.rb deleted file mode 100644 index 6e375e50e..000000000 --- a/spec/lib/tasks/migrations_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require "rails_helper" - -describe "Migration tasks" do - describe "valuation_taggins" do - let(:run_rake_task) do - Rake::Task["migrations:valuation_taggings"].reenable - Rake.application.invoke_task("migrations:valuation_taggings") - end - - it "updates taggings" do - valuation_tagging = create(:tagging, context: "valuation") - another_valuation_tagging = create(:tagging, context: "valuation") - valuation_tags_tagging = create(:tagging, context: "valuation_tags") - tags_tagging = create(:tagging) - - run_rake_task - - expect(valuation_tagging.reload.context).to eq "valuation_tags" - expect(another_valuation_tagging.reload.context).to eq "valuation_tags" - expect(valuation_tags_tagging.reload.context).to eq "valuation_tags" - expect(tags_tagging.reload.context).to eq "tags" - end - end - - describe "budget_admins_and_valuators" do - let(:run_rake_task) do - Rake::Task["migrations:budget_admins_and_valuators"].reenable - Rake.application.invoke_task("migrations:budget_admins_and_valuators") - end - - let(:old_budget) { create(:budget) } - let(:current_budget) { create(:budget) } - - it "assigns administrators from existing investments" do - harold = create(:administrator) - john = create(:administrator) - root = create(:administrator) - - create(:budget_investment, budget: old_budget, administrator: john) - create(:budget_investment, budget: old_budget, administrator: harold) - create(:budget_investment, budget: old_budget, administrator: nil) - - create(:budget_investment, budget: current_budget, administrator: root) - - run_rake_task - - expect(old_budget.administrators).to match_array [john, harold] - expect(current_budget.administrators).to match_array [root] - end - - it "assigns valuators from existing investments" do - tyrion = create(:valuator) - cersei = create(:valuator) - jaime = create(:valuator) - - create(:budget_investment, budget: old_budget, valuators: [cersei]) - create(:budget_investment, budget: old_budget, valuators: [jaime, cersei]) - create(:budget_investment, budget: old_budget, valuators: []) - - create(:budget_investment, budget: current_budget, valuators: [tyrion, jaime]) - - run_rake_task - - expect(old_budget.valuators).to match_array [cersei, jaime] - expect(current_budget.valuators).to match_array [tyrion, jaime] - end - end -end