From 130eb9dcd8512d4e840b923aef55bd328565c55f Mon Sep 17 00:00:00 2001 From: el que m'est <14348482+elquimista@users.noreply.github.com> Date: Tue, 22 Oct 2019 23:56:45 -0700 Subject: [PATCH] Allow additional psql argument --- lib/parity/backup.rb | 10 ++++++---- lib/parity/environment.rb | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/parity/backup.rb b/lib/parity/backup.rb index c4cf45a..d7f9e6f 100644 --- a/lib/parity/backup.rb +++ b/lib/parity/backup.rb @@ -10,6 +10,7 @@ class Backup def initialize(args) @from, @to = args.values_at(:from, :to) @additional_args = args[:additional_args] || BLANK_ARGUMENTS + @psql_args = args[:psql_args] || BLANK_ARGUMENTS end def restore @@ -24,7 +25,7 @@ def restore private - attr_reader :additional_args, :from, :to + attr_reader :additional_args, :psql_args, :from, :to def restore_from_development reset_remote_database @@ -45,7 +46,8 @@ def restore_to_development def wipe_development_database Kernel.system( - "dropdb --if-exists #{development_db} && createdb #{development_db}", + "dropdb #{psql_args} --if-exists #{development_db} && "\ + "createdb #{psql_args} #{development_db}", ) end @@ -74,7 +76,7 @@ def restore_from_local_temp_backup Kernel.system( "pg_restore tmp/latest.backup --verbose --clean --no-acl --no-owner "\ "--dbname #{development_db} --jobs=#{processor_cores} "\ - "#{additional_args}", + "#{additional_args} #{psql_args}", ) end @@ -84,7 +86,7 @@ def delete_local_temp_backup def delete_rails_production_environment_settings Kernel.system(<<-SHELL) - psql #{development_db} -c "CREATE TABLE IF NOT EXISTS public.ar_internal_metadata (key character varying NOT NULL, value character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key)); UPDATE ar_internal_metadata SET value = 'development' WHERE key = 'environment'" + psql #{psql_args} #{development_db} -c "CREATE TABLE IF NOT EXISTS public.ar_internal_metadata (key character varying NOT NULL, value character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key)); UPDATE ar_internal_metadata SET value = 'development' WHERE key = 'environment'" SHELL end diff --git a/lib/parity/environment.rb b/lib/parity/environment.rb index 237bdf2..d07d6d7 100644 --- a/lib/parity/environment.rb +++ b/lib/parity/environment.rb @@ -2,11 +2,17 @@ module Parity class Environment - def initialize(environment, subcommands, app_argument: "--remote") + def initialize( + environment, + subcommands, + app_argument: "--remote", + psql_argument: "" + ) self.environment = environment self.subcommand = subcommands[0] self.arguments = subcommands[1..-1] self.app_argument = app_argument + self.psql_argument = psql_argument end def run @@ -18,6 +24,7 @@ def run PROTECTED_ENVIRONMENTS = %w(development production) attr_accessor :app_argument, :environment, :subcommand, :arguments + attr_accessor :psql_argument def run_command if self.class.private_method_defined?(methodized_subcommand) @@ -58,6 +65,7 @@ def restore from: arguments.first, to: environment, additional_args: additional_restore_arguments, + psql_args: psql_argument, ).restore end end