diff --git a/Gemfile.lock b/Gemfile.lock index a0fba80..db9d655 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,103 +2,142 @@ PATH remote: . specs: pg_tasks (2.2.0.pre.0) - rails (~> 5.0) + rails (~> 6.1.0) GEM remote: https://rubygems.org/ specs: - actioncable (5.1.3) - actionpack (= 5.1.3) + actioncable (6.1.7) + actionpack (= 6.1.7) + activesupport (= 6.1.7) nio4r (~> 2.0) - websocket-driver (~> 0.6.1) - actionmailer (5.1.3) - actionpack (= 5.1.3) - actionview (= 5.1.3) - activejob (= 5.1.3) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.7) + actionpack (= 6.1.7) + activejob (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + mail (>= 2.7.1) + actionmailer (6.1.7) + actionpack (= 6.1.7) + actionview (= 6.1.7) + activejob (= 6.1.7) + activesupport (= 6.1.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.3) - actionview (= 5.1.3) - activesupport (= 5.1.3) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (6.1.7) + actionview (= 6.1.7) + activesupport (= 6.1.7) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.3) - activesupport (= 5.1.3) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7) + actionpack (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + nokogiri (>= 1.8.5) + actionview (6.1.7) + activesupport (= 6.1.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.3) - activesupport (= 5.1.3) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7) + activesupport (= 6.1.7) globalid (>= 0.3.6) - activemodel (5.1.3) - activesupport (= 5.1.3) - activerecord (5.1.3) - activemodel (= 5.1.3) - activesupport (= 5.1.3) - arel (~> 8.0) - activesupport (5.1.3) + activemodel (6.1.7) + activesupport (= 6.1.7) + activerecord (6.1.7) + activemodel (= 6.1.7) + activesupport (= 6.1.7) + activestorage (6.1.7) + actionpack (= 6.1.7) + activejob (= 6.1.7) + activerecord (= 6.1.7) + activesupport (= 6.1.7) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (8.0.0) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) ast (2.1.0) astrolabe (1.3.1) parser (~> 2.2) - builder (3.2.3) - concurrent-ruby (1.0.5) - erubi (1.6.1) - globalid (0.4.0) - activesupport (>= 4.2.0) - i18n (0.8.6) - loofah (2.0.3) + builder (3.2.4) + concurrent-ruby (1.1.10) + crass (1.0.6) + erubi (1.11.0) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + loofah (2.19.0) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.6) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.2.0) - minitest (5.10.3) - nio4r (2.1.0) - nokogiri (1.8.0) - mini_portile2 (~> 2.2.0) + mail (2.8.0) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_portile2 (2.8.0) + minitest (5.16.3) + net-imap (0.3.1) + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.0) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) + racc (~> 1.4) parser (2.2.2.6) ast (>= 1.1, < 3.0) pg (0.18.2) powerpack (0.1.1) - rack (2.0.3) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.1.3) - actioncable (= 5.1.3) - actionmailer (= 5.1.3) - actionpack (= 5.1.3) - actionview (= 5.1.3) - activejob (= 5.1.3) - activemodel (= 5.1.3) - activerecord (= 5.1.3) - activesupport (= 5.1.3) - bundler (>= 1.3.0) - railties (= 5.1.3) + racc (1.6.1) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (6.1.7) + actioncable (= 6.1.7) + actionmailbox (= 6.1.7) + actionmailer (= 6.1.7) + actionpack (= 6.1.7) + actiontext (= 6.1.7) + actionview (= 6.1.7) + activejob (= 6.1.7) + activemodel (= 6.1.7) + activerecord (= 6.1.7) + activestorage (= 6.1.7) + activesupport (= 6.1.7) + bundler (>= 1.15.0) + railties (= 6.1.7) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.1.3) - actionpack (= 5.1.3) - activesupport (= 5.1.3) + rails-html-sanitizer (1.4.3) + loofah (~> 2.3) + railties (6.1.7) + actionpack (= 6.1.7) + activesupport (= 6.1.7) method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + rake (>= 12.2) + thor (~> 1.0) rainbow (2.0.0) - rake (12.0.0) + rake (13.0.6) rubocop (0.33.0) astrolabe (~> 1.3) parser (>= 2.2.2.5, < 3.0) @@ -106,20 +145,21 @@ GEM rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) ruby-progressbar (1.7.5) - sprockets (3.7.1) + sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - thor (0.19.4) - thread_safe (0.3.6) - tzinfo (1.2.3) - thread_safe (~> 0.1) - websocket-driver (0.6.5) + thor (1.2.1) + timeout (0.3.1) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.5) + zeitwerk (2.6.6) PLATFORMS ruby @@ -130,4 +170,4 @@ DEPENDENCIES rubocop BUNDLED WITH - 1.14.6 + 1.17.3 diff --git a/lib/pg_tasks.rb b/lib/pg_tasks.rb index 09cd58d..3e62e48 100644 --- a/lib/pg_tasks.rb +++ b/lib/pg_tasks.rb @@ -93,14 +93,14 @@ def data_restore(filename) set_psql_env command = 'pg_restore --data-only --exit-on-error ' \ ' --disable-triggers --single-transaction --no-privileges --no-owner ' \ - " -d #{Shellwords.escape(configuration['database'])} " \ + " -d #{Shellwords.escape(configuration_hash[:database])} " \ " --use-list=#{restore_list_file.path} " \ " #{shell_filename}" unless Kernel.system(command) raise 'Error during data_restore ' else $stdout.puts "Data from '#{filename}' has been restored to \ - '#{configuration['database']}'" + '#{configuration_hash[:database]}'" end ensure restore_list_file.close @@ -113,12 +113,12 @@ def structure_and_data_dump(filename, plain_text = false) command = "pg_dump -x -O \ -F #{plain_text ? 'p' : 'c'} \ -f #{Shellwords.escape(filename)} \ - #{Shellwords.escape(configuration['database'])}" + #{Shellwords.escape(configuration_hash[:database])}" unless Kernel.system(command) raise 'Error during structure_and_data_dump' else $stdout.puts 'Structure and data of ' \ - "'#{configuration['database']}' has been dumped to '#{filename}'" + "'#{configuration_hash[:database]}' has been dumped to '#{filename}'" end end @@ -130,19 +130,19 @@ def structure_and_data_restore(filename) set_psql_env command = 'pg_restore --disable-triggers --exit-on-error ' \ '--single-transaction -x -O -d ' \ - "#{Shellwords.escape(configuration['database'])} " \ + "#{Shellwords.escape(configuration_hash[:database])} " \ "#{Shellwords.escape(filename.to_s)}" unless Kernel.system(command) raise 'Error during structure_and_data_restore ' else - $stdout.puts "Structure and data of '#{configuration['database']}' " \ + $stdout.puts "Structure and data of '#{configuration_hash[:database]}' " \ "has been restored to '#{filename}'" end end def terminate_connections set_psql_env - database = configuration['database'] + database = configuration_hash[:database] command = "psql -c \"SELECT pg_terminate_backend(pg_stat_activity.pid) " \ ' FROM pg_stat_activity ' \ "WHERE pg_stat_activity.datname = '#{database}' " \ @@ -162,11 +162,14 @@ module Tasks module DatabaseTasks def perform_pg_db_task_for_config_and_filename(task_name, *arguments) configuration = arguments.first - filename = arguments.delete_at 1 - class_for_adapter(configuration['adapter']) \ - .new(*arguments).send task_name, filename + filename = arguments.delete_at(1) + hash_config = + ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", configuration) + class_for_adapter(hash_config.configuration_hash[:adapter]) + .new(hash_config) + .send(task_name, filename) rescue ActiveRecord::NoDatabaseError - $stderr.puts "Database '#{configuration['database']}' does not exist" + $stderr.puts "Database '#{hash_config.configuration_hash[:database]}' does not exist" rescue Exception => error $stderr.puts error, *(error.backtrace) raise error @@ -174,8 +177,9 @@ def perform_pg_db_task_for_config_and_filename(task_name, *arguments) def terminate_connections(*arguments) configuration = arguments.first - class_for_adapter(configuration['adapter']) \ - .new(*arguments).send :terminate_connections + hash_config = + ActiveRecord::DatabaseConfigurations::HashConfig.new("test", "primary", configuration) + class_for_adapter(hash_config.configuration_hash[:adapter]).new(hash_config).send :terminate_connections end end end diff --git a/pg_tasks.gemspec b/pg_tasks.gemspec index 13440ef..095af9c 100644 --- a/pg_tasks.gemspec +++ b/pg_tasks.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.rdoc'] s.test_files = Dir['test/**/*'] - s.add_dependency 'rails', '~> 5.0' + s.add_dependency 'rails', '~> 6.1.0' s.add_development_dependency 'pg' s.add_development_dependency 'rubocop'