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

Restore support for ERB database.yml #187

Merged
merged 1 commit into from
Oct 7, 2020
Merged
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
1 change: 1 addition & 0 deletions lib/parity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "parity/version"
require "parity/environment"
require "parity/usage"
require "erb"
require "open3"
require "pathname"
require "uri"
Expand Down
2 changes: 1 addition & 1 deletion lib/parity/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def development_db
end

def database_yaml_file
IO.read(DATABASE_YML_RELATIVE_PATH)
ERB.new(IO.read(DATABASE_YML_RELATIVE_PATH)).result
end

def processor_cores
Expand Down
4 changes: 3 additions & 1 deletion spec/fixtures/database_with_erb.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
default: &default
reconnect: true

<% if true %>
development: &development
<<: *default
database: <%= ENV["DEVELOPMENT_DATABASE_NAME"] %>
database: <%= ['parity', 'development'].join('_') %>
<% end %>
30 changes: 30 additions & 0 deletions spec/parity/backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@
with(delete_local_temp_backup_command)
expect(Kernel).to have_received(:system).with(set_db_metadata_sql)
end

it "is able to load a database.yml file containing top-level ERB" do
allow(IO).to receive(:read).and_return(database_fixture_with_erb)
allow(Kernel).to receive(:system)

Parity::Backup.new(
from: "production",
to: "development",
).restore

expect(Kernel).
to have_received(:system).
with(make_temp_directory_command)
expect(Kernel).
to have_received(:system).
with(download_remote_database_command)
expect(Kernel).
to have_received(:system).
with(drop_development_database_drop_command)
expect(Kernel).
to have_received(:system).
with(restore_from_local_temp_backup_command(cores: 1))
expect(Kernel).
to have_received(:system).
with(delete_local_temp_backup_command)
end
end

it "restores backups to staging from production" do
Expand Down Expand Up @@ -201,6 +227,10 @@ def database_fixture
IO.read(fixture_path("database.yml"))
end

def database_fixture_with_erb
IO.read(fixture_path("database_with_erb.yml"))
end

def fixture_path(filename)
File.join(File.dirname(__FILE__), "..", "fixtures", filename)
end
Expand Down