Merge pull request #3590 from consul/add_upgrade_task

Add task to upgrade to a new release
This commit is contained in:
Javier Martín
2019-06-06 13:07:41 +02:00
committed by GitHub
9 changed files with 59 additions and 9 deletions

11
lib/application_logger.rb Normal file
View File

@@ -0,0 +1,11 @@
class ApplicationLogger
def info(message)
logger.info(message)
end
def logger
@logger ||= Logger.new(STDOUT).tap do |logger|
logger.formatter = proc { |severity, _datetime, _progname, msg| "#{severity} #{msg}\n" }
end
end
end

View File

@@ -1,4 +1,14 @@
namespace :budgets do
desc "Regenerate ballot_lines_count cache"
task calculate_ballot_lines: :environment do
ApplicationLogger.new.info "Calculating ballot lines"
Budget::Ballot.find_each.with_index do |ballot, index|
Budget::Ballot.reset_counters ballot.id, :lines
print "." if (index % 10_000).zero?
end
end
namespace :email do
desc "Sends emails to authors of selected investments"

13
lib/tasks/consul.rake Normal file
View File

@@ -0,0 +1,13 @@
namespace :consul do
desc "Runs tasks needed to upgrade to the latest version"
task execute_release_tasks: "execute_release_1.0.0_tasks"
desc "Runs tasks needed to upgrade from 1.0.0-beta to 1.0.0"
task "execute_release_1.0.0_tasks": [
"poll:generate_slugs",
"stats_and_results:migrate_to_reports",
"budgets:calculate_ballot_lines",
"settings:remove_deprecated_settings",
"stats:generate"
]
end

View File

@@ -1,6 +1,8 @@
namespace :poll do
desc "Generate slugs polls"
task generate_slugs: :environment do
ApplicationLogger.new.info "Generating poll slugs"
Poll.find_each do |poll|
poll.update_columns(slug: poll.generate_slug, updated_at: Time.current) if poll.generate_slug?
end

View File

@@ -1,8 +0,0 @@
namespace :budgets do
desc "Regenerate ballot_lines_count cache"
task calculate_ballot_lines: :environment do
Budget::Ballot.find_each do |ballot|
Budget::Ballot.reset_counters ballot.id, :lines
end
end
end

View File

@@ -2,6 +2,8 @@ namespace :settings do
desc "Remove deprecated settings"
task remove_deprecated_settings: :environment do
ApplicationLogger.new.info "Removing deprecated settings"
deprecated_keys = [
"place_name",
"banner-style.banner-style-one",

View File

@@ -1,6 +1,8 @@
namespace :stats do
desc "Generates stats which are not cached yet"
task generate: :environment do
ApplicationLogger.new.info "Updating budget and poll stats"
Budget.find_each do |budget|
Budget::Stats.new(budget).generate
print "."

View File

@@ -1,6 +1,7 @@
namespace :stats_and_results do
desc "Migrates stats_enabled and results_enabled data to enabled reports"
task migrate_to_reports: :environment do
ApplicationLogger.new.info "Migrating stats and results"
Migrations::Reports.new.migrate
end
end