Skip to content

Commit 5704201

Browse files
committed
Breaking change: Remove dependencies on external gems
v0.9.3 introduced two new features that required reliance on external libraries. Installing these libraries through our Traveling Ruby-packaged executable has introduced issues for users. Some users reported permissions issues related to now-deprecated Bundler behavior that is still in use on the version of Bundler used by Traveling Ruby (Ruby 2.2.2 is still locked to Bundler 1.9.x). After spending considerable time attempting to work through packaging problems I now think that the potential benefits from these dependencies are not worth the trouble. We can accomplish most of the needed functionality without help from external gems. This commit makes the following changes to Parity: - **BREAKING CHANGE** Remove the `dotenv` gem and stop loading `ERB`. We were previously using `dotenv` and `erb` to allow users to define their database name in development dynamically in a `database.yml.erb` file that included environment variables. This configuration is an edge case that doesn't warrant adding non-trivial complexity to accommodate. - Remove the `git` gem. This gem parsed Git remotes, allowing parity to determine the application name and pass the confirmation argument for applications named differently than the local development directory. This functionality has been retained by leveraging Heroku CLI's `info` command to get the application name. - Remove packaging changes previously made to convey gems along with parity for Traveling Ruby packaging. While I suspect I may have been the only user to make use of environment variables to specify the name of the development database, these changes will require a major version update as they break backwards compatibility. Fix #91, #93, #96.
1 parent e2d965e commit 5704201

File tree

6 files changed

+29
-98
lines changed

6 files changed

+29
-98
lines changed

Gemfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
source 'https://rubygems.org'
22

3-
gem "dotenv"
4-
gem "git"
5-
gem "rake"
6-
73
group :development do
8-
gem "climate_control"
4+
gem "rake"
95
gem "rspec"
106
end

lib/parity.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
require "parity/version"
44
require "parity/environment"
55
require "parity/usage"
6-
require "erb"
7-
require "git"
8-
require "dotenv"
96
require "open3"
107
require "pathname"
118
require "uri"

lib/parity/backup.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ def remote_db_backup_url
6565
end
6666

6767
def development_db
68-
YAML.load(parsed_database_yml).
68+
YAML.load(database_yaml_file).
6969
fetch(DEVELOPMENT_ENVIRONMENT_KEY_NAME).
7070
fetch(DATABASE_KEY_NAME)
7171
end
7272

73-
def parsed_database_yml
74-
Dotenv.load
75-
yaml_file = IO.read(DATABASE_YML_RELATIVE_PATH)
76-
ERB.new(yaml_file).result
73+
def database_yaml_file
74+
IO.read(DATABASE_YML_RELATIVE_PATH)
7775
end
7876
end
7977
end

lib/parity/environment.rb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def run
1414

1515
private
1616

17-
GIT_REMOTE_SEGMENT_DELIMITER_REGEX = /[\/:]/
18-
GIT_REMOTE_FILE_EXTENSION_REGEX = /\.git$/
1917
PROTECTED_ENVIRONMENTS = %w(development production)
2018

2119
attr_accessor :environment, :subcommand, :arguments
@@ -94,19 +92,19 @@ def restore_confirmation_argument
9492
end
9593

9694
def console
97-
Kernel.system("heroku run rails console --remote #{environment}")
95+
Kernel.system(command_for_remote("run rails console"))
9896
end
9997

10098
def migrate
10199
Kernel.system(%{
102-
heroku run rake db:migrate --remote #{environment} &&
103-
heroku restart --remote #{environment}
100+
#{command_for_remote('run rake db:migrate')} &&
101+
#{command_for_remote('restart')}
104102
})
105103
end
106104

107105
def tail
108106
Kernel.system(
109-
"heroku logs --tail #{arguments.join(" ")} --remote #{environment}"
107+
command_for_remote("logs --tail #{arguments.join(' ')}"),
110108
)
111109
end
112110

@@ -125,20 +123,20 @@ def redis_cli
125123
end
126124

127125
def raw_redis_url
128-
@redis_to_go_url ||= Open3.capture3(
129-
"heroku config:get REDIS_URL "\
130-
"--remote #{environment}"
131-
)[0].strip
126+
@redis_to_go_url ||= Open3.
127+
capture3(command_for_remote("config:get REDIS_URL"))[0].
128+
strip
132129
end
133130

134-
def git_remote
135-
Git.init.remote(environment).url
131+
def heroku_app_name
132+
@heroku_app_name ||= Open3.
133+
capture3(command_for_remote("info"))[0].
134+
split("\n")[0].
135+
gsub(/(\s|=)+/, "")
136136
end
137137

138-
def heroku_app_name
139-
git_remote.
140-
split(GIT_REMOTE_SEGMENT_DELIMITER_REGEX).
141-
last.sub(GIT_REMOTE_FILE_EXTENSION_REGEX, "")
138+
def command_for_remote(command)
139+
"heroku #{command} --remote #{environment}"
142140
end
143141

144142
def run_migrations?

spec/parity/backup_spec.rb

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require "climate_control"
2-
31
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'parity')
42

53
describe Parity::Backup do
@@ -17,35 +15,6 @@
1715
with(heroku_production_to_development_passthrough)
1816
end
1917

20-
context "with a database.yml that uses ERB and environment variables" do
21-
around do |example|
22-
ClimateControl.modify DEVELOPMENT_DATABASE_NAME: "erb_database_name" do
23-
example.run
24-
end
25-
end
26-
27-
it "correctly parses database.yml" do
28-
development_db = ENV["DEVELOPMENT_DATABASE_NAME"]
29-
allow(IO).to receive(:read).and_return(database_with_erb_fixture)
30-
allow(Kernel).to receive(:system)
31-
32-
Parity::Backup.new(from: "production", to: "development").restore
33-
34-
expect(Kernel).
35-
to have_received(:system).
36-
with(
37-
drop_development_database_drop_command(db_name: development_db),
38-
)
39-
expect(Kernel).
40-
to have_received(:system).
41-
with(
42-
heroku_production_to_development_passthrough(
43-
db_name: development_db,
44-
),
45-
)
46-
end
47-
end
48-
4918
it "restores backups to staging from production" do
5019
allow(Kernel).to receive(:system)
5120

spec/parity/environment_spec.rb

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
expect(Kernel).to have_received(:system).with(heroku_backup)
3333
end
3434

35-
it "correctly connects to the Heroku app when the $PWD's name does not match the app's name (remote uses git:// protocol)" do
35+
it "connects to the Heroku app when $PWD does not match the app name" do
3636
backup = stub_parity_backup
3737
stub_git_remote(base_name: "parity-integration", environment: "staging")
3838
allow(Parity::Backup).to receive(:new).and_return(backup)
@@ -49,26 +49,6 @@
4949
expect(backup).to have_received(:restore)
5050
end
5151

52-
it "correctly connects to the Heroku app when the $PWD's name does not match the app's name (remote uses https:// protocol)" do
53-
backup = stub_parity_backup
54-
stub_git_remote_for_https(
55-
base_name: "parity-integration",
56-
environment: "staging",
57-
)
58-
allow(Parity::Backup).to receive(:new).and_return(backup)
59-
60-
Parity::Environment.new("staging", ["restore", "production"]).run
61-
62-
expect(Parity::Backup).
63-
to have_received(:new).
64-
with(
65-
from: "production",
66-
to: "staging",
67-
additional_args: "--confirm parity-integration-staging",
68-
)
69-
expect(backup).to have_received(:restore)
70-
end
71-
7252
it "restores backups from production to staging" do
7353
backup = stub_parity_backup
7454
stub_git_remote(environment: "staging")
@@ -379,23 +359,16 @@ def stub_migration_path_check(result)
379359
end
380360

381361
def stub_git_remote(base_name: "parity", environment: "staging")
382-
git_remote = instance_double(
383-
"Git::Remote",
384-
url: "[email protected]:#{base_name}-#{environment}.git",
385-
)
386-
git = instance_double("Git::Base")
387-
allow(git).to receive(:remote).with("staging").and_return(git_remote)
388-
allow(Git).to receive(:init).and_return(git)
389-
end
390-
391-
def stub_git_remote_for_https(base_name: "parity", environment: "staging")
392-
git_remote = instance_double(
393-
"Git::Remote",
394-
url: "https://git.heroku.com/#{base_name}-#{environment}.git",
395-
)
396-
git = instance_double("Git::Base")
397-
allow(git).to receive(:remote).with("staging").and_return(git_remote)
398-
allow(Git).to receive(:init).and_return(git)
362+
allow(Open3).
363+
to receive(:capture3).
364+
with("heroku info --remote #{environment}").
365+
and_return(
366+
[
367+
"=== #{base_name}-#{environment}\nAddOns: blahblahblah",
368+
"",
369+
{},
370+
],
371+
)
399372
end
400373

401374
def stub_parity_backup

0 commit comments

Comments
 (0)