From c1bf0ca048f72741e271b38b990e9e2638d84043 Mon Sep 17 00:00:00 2001 From: "E. Sambo" Date: Sun, 19 Mar 2017 20:29:55 -0500 Subject: [PATCH 1/3] Fix LocalJumpError See: http://stackoverflow.com/questions/17800629/unexpected-return-localjumperror Fixes: https://github.com/enova/prodder/issues/20 --- lib/prodder/prodder.rake | 100 +++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/lib/prodder/prodder.rake b/lib/prodder/prodder.rake index 90e84bf..709e669 100644 --- a/lib/prodder/prodder.rake +++ b/lib/prodder/prodder.rake @@ -214,78 +214,74 @@ namespace :db do desc "Load initial seeds from db/seeds.sql" task :seed => dependencies do - unless File.exist?('db/seeds.sql') + if File.exist?('db/seeds.sql') + config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') + set_psql_env config + puts "Loading db/seeds.sql into database '#{config['database']}'" + `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}` + raise 'Error loading db/seeds.sql' if $?.exitstatus != 0 + else puts 'db/seeds.sql not found: no seeds to load.' - return end - - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] - config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') - set_psql_env config - puts "Loading db/seeds.sql into database '#{config['database']}'" - `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}` - raise 'Error loading db/seeds.sql' if $?.exitstatus != 0 end desc "Load quality_checks (indexes, triggers, foreign keys) from db/quality_checks.sql" task :quality_check => dependencies do - unless File.exist?('db/quality_checks.sql') + if File.exist?('db/quality_checks.sql') + config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') + set_psql_env config + puts "Loading db/quality_checks.sql into database '#{config['database']}'" + `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}` + raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0 + else puts 'db/quality_checks.sql not found: no quality_checks to load.' - return end - - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] - config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') - set_psql_env config - puts "Loading db/quality_checks.sql into database '#{config['database']}'" - `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}` - raise 'Error loading db/quality_checks.sql' if $?.exitstatus != 0 end desc "Load permissions (DB object level access control, group role memberships) from db/permissions.sql" task :permission => dependencies do - unless File.exist?('db/permissions.sql') - puts 'db/permissions.sql not found: no permissions to load.' - return - end - - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] - config["username"] = config["superuser"] if config["superuser"] - set_psql_env config - puts "Loading db/permissions.sql into database '#{config['database']}'" - disconnect - ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern) - result = ActiveRecord::Base.connection.execute(<<-SQL).first + if File.exist?('db/permissions.sql') + config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config["username"] = config["superuser"] if config["superuser"] + set_psql_env config + puts "Loading db/permissions.sql into database '#{config['database']}'" + disconnect + ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern) + result = ActiveRecord::Base.connection.execute(<<-SQL).first select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper - SQL - unless result && result['is_super'] - puts "Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + SQL + unless result && result['is_super'] + puts "Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + end + `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}` + raise 'Error loading db/permissions.sql' if $?.exitstatus != 0 + else + puts 'db/permissions.sql not found: no permissions to load.' end - `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}` - raise 'Error loading db/permissions.sql' if $?.exitstatus != 0 end desc "Load database settings" task :settings => dependencies do - unless File.exist?('db/settings.sql') - puts 'db/settings.sql not found: no settings to load.' - return - end - - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] - config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') - set_psql_env config - puts "Loading db/settings.sql into database '#{config['database']}'" - disconnect - ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern) - result = ActiveRecord::Base.connection.execute(<<-SQL).first + if File.exist?('db/settings.sql') + config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config["username"] = config["superuser"] if config["superuser"] && File.exist?('db/permissions.sql') + set_psql_env config + puts "Loading db/settings.sql into database '#{config['database']}'" + disconnect + ActiveRecord::Base.establish_connection((ENV['RAILS_ENV'] || Rails.env).intern) + result = ActiveRecord::Base.connection.execute(<<-SQL).first select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper - SQL - unless result && result['is_super'] - puts "Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + SQL + unless result && result['is_super'] + puts "Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + end + `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}` + raise 'Error loading db/settings.sql' if $?.exitstatus != 0 + else + puts 'db/settings.sql not found: no settings to load.' end - `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}` - raise 'Error loading db/settings.sql' if $?.exitstatus != 0 end # Empty this, we don't want db:migrate writing structure.sql any more. From 014899e269c0de7996ccf62b16aa6c2191ac41ba Mon Sep 17 00:00:00 2001 From: "E. Sambo" Date: Sun, 19 Mar 2017 20:34:40 -0500 Subject: [PATCH 2/3] Categorize log messages with error severity levels Fixes: https://github.com/enova/prodder/issues/12 --- lib/prodder/prodder.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/prodder/prodder.rake b/lib/prodder/prodder.rake index 709e669..4989361 100644 --- a/lib/prodder/prodder.rake +++ b/lib/prodder/prodder.rake @@ -98,7 +98,7 @@ namespace :db do begin puts ActiveRecord::Tasks::DatabaseTasks.collation_current rescue NoMethodError - $stderr.puts 'Sorry, your database adapter is not supported yet. Feel free to submit a patch.' + $stderr.puts 'error: Sorry, your database adapter is not supported yet. Feel free to submit a patch.' end end end @@ -253,7 +253,7 @@ namespace :db do select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper SQL unless result && result['is_super'] - puts "Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + puts "warning: Restoring permissions as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" end `psql --no-psqlrc -f db/permissions.sql #{Shellwords.escape(config['database'])}` raise 'Error loading db/permissions.sql' if $?.exitstatus != 0 @@ -275,7 +275,7 @@ namespace :db do select 1 as is_super from pg_roles where rolname = '#{config['username']}' and rolsuper SQL unless result && result['is_super'] - puts "Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" + puts "warning: Restoring settings as config/database.yml non-superuser: '#{config['username']}', expect errors, or rerun after granting superuser" end `psql --no-psqlrc -f db/settings.sql #{Shellwords.escape(config['database'])}` raise 'Error loading db/settings.sql' if $?.exitstatus != 0 From 5b02ba034c3cd15c8fcd85e691b8b73c78d3bca6 Mon Sep 17 00:00:00 2001 From: "E. Sambo" Date: Sun, 19 Mar 2017 20:34:58 -0500 Subject: [PATCH 3/3] Tick version --- lib/prodder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/prodder/version.rb b/lib/prodder/version.rb index 87dbbba..408f22e 100644 --- a/lib/prodder/version.rb +++ b/lib/prodder/version.rb @@ -1,3 +1,3 @@ module Prodder - VERSION = "1.7.3" + VERSION = "1.7.4" end