Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional psql argument #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/parity/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
10 changes: 9 additions & 1 deletion lib/parity/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +24,7 @@ def run
PROTECTED_ENVIRONMENTS = %w(development production)

attr_accessor :app_argument, :environment, :subcommand, :arguments
attr_accessor :psql_argument
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this join the above attr_accessors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure


def run_command
if self.class.private_method_defined?(methodized_subcommand)
Expand Down Expand Up @@ -58,6 +65,7 @@ def restore
from: arguments.first,
to: environment,
additional_args: additional_restore_arguments,
psql_args: psql_argument,
).restore
end
end
Expand Down