Skip to content

Conversation

@sethhorsley
Copy link

This pull request includes a small change to the restore_to_development method in lib/parity/backup.rb. The change ensures that the dropdb command is executed with the --force flag to enforce the removal of the development database even if there are active connections.

def wipe_development_database
Kernel.system(
"dropdb --if-exists #{development_db} && createdb #{development_db}",
"dropdb --if-exists #{development_db} --force && createdb #{development_db}",
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [85/80]

…ort specific backup IDs. Added logging for restoration processes and updated tests to verify new behavior.
log_restore_info
reset_remote_database
# Filter out --backup-id from additional_args as it's handled separately
filtered_args = additional_args.gsub(/--backup-id\s+\S+/, '').strip
Copy link

Choose a reason for hiding this comment

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

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

def restore_from_local_temp_backup
puts "Restoring backup to #{development_db}..."
# Filter out --backup-id from additional_args as it's not needed for pg_restore
filtered_args = additional_args.gsub(/--backup-id\s+\S+/, '').strip
Copy link

Choose a reason for hiding this comment

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

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


def restore_from_local_temp_backup
puts "Restoring backup to #{development_db}..."
# Filter out --backup-id from additional_args as it's not needed for pg_restore
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [85/80]

else
puts "Downloading latest backup from #{from}..."
Kernel.system(
"curl -o tmp/latest.backup \"$(heroku pg:backups:url --remote #{from})\"",
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [84/80]

if backup_id
puts "Downloading backup #{backup_id} from #{from}..."
Kernel.system(
"curl -o tmp/#{backup_id}.backup \"$(heroku pg:backups:url #{backup_id} --remote #{from})\"",
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [103/80]

# Filter out special flags that are handled separately
filtered_args = arguments.drop(1) - ["--force", "--parallelize"]
# Filter out --backup-id as it's handled separately by the Backup class
filtered_args = filtered_args.reject { |arg| arg.start_with?("--backup-id") }
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [83/80]

).restore
}
backup_args[:backup_id] = backup_id? if backup_id?

Copy link

Choose a reason for hiding this comment

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

Layout/TrailingWhitespace: Trailing whitespace detected.

"--dbname #{default_db_name} --jobs=#{cores} "
end

def specific_backup_id_restore_from_local_temp_backup_command(cores: number_of_processes)
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [91/80]

end

def specific_backup_id_download_command
'curl -o tmp/b001.backup "$(heroku pg:backups:url b001 --remote production)"'
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [81/80]

with(create_heroku_ext_schema_command)
expect(Kernel).
to have_received(:system).
with(specific_backup_id_restore_from_local_temp_backup_command(cores: 1))
Copy link

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [81/80]

else
puts "Downloading latest backup from #{from}..."
Kernel.system(
"curl -o tmp/latest.backup \"$(heroku pg:backups:url --remote #{from})\"",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use the same curl statement in both places since a nil backup_id would be an empty string here? This would avoid having two pieces of interpolated string arguments to maintain going forward where we could have one.


alias :parallelize? :parallelize


Copy link
Collaborator

Choose a reason for hiding this comment

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

Trim these down, please.

if backup_id_index && backup_id_index + 1 < arguments.length
arguments[backup_id_index + 1]
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

The predicate method should return a boolean result. Given that you're using the ID returned here I think the ? should be dropped from the method name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants