Skip to content

Commit

Permalink
Revert "Changes to rails, PHP and Java to support RDS. Currently only…
Browse files Browse the repository at this point in the history
… rails"

This reverts commit 976dda7.
  • Loading branch information
githuesch committed May 14, 2014
1 parent dcce7c6 commit a363c36
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 112 deletions.
3 changes: 1 addition & 2 deletions deploy/specs/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
skip unless deploy[:database][:host].present?
cfg = YAML.load_file("#{deploy[:deploy_to]}/shared/config/database.yml")
["development", "production", deploy[:rails_env]].uniq.each do |env|
expected_adapter = deploy[:database][:adapter].to_s == 'postgres' ? 'postgresql' : deploy[:database][:adapter].to_s
cfg[env]['adapter'].must_equal expected_adapter
cfg[env]['adapter'].must_equal deploy[:database][:adapter].to_s
cfg[env]['database'].must_equal deploy[:database][:database].to_s
cfg[env]['host'].must_equal((deploy[:database][:host] || 'localhost').to_s)
cfg[env]['username'].must_equal deploy[:database][:username].to_s
Expand Down
4 changes: 0 additions & 4 deletions opsworks_java/templates/default/webapp_context.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
maxActive="20" maxIdle="5" maxWait="10000"
username="<%= node['deploy'][@application]['database']['username'] %>" password="<%= node['deploy'][@application]['database']['password'] %>"
driverClassName="com.mysql.jdbc.Driver"
<% if node['deploy'][@application]['database']['port'] %>
url="jdbc:mysql://<%= node['deploy'][@application]['database']['host'] %>:<%= if node['deploy'][@application]['database']['port'] %>/<%= node['deploy'][@application]['database']['database'] %>"
<% else %>
url="jdbc:mysql://<%= node['deploy'][@application]['database']['host'] %>:3306/<%= node['deploy'][@application]['database']['database'] %>"
<% end %>
factory="org.apache.commons.dbcp.BasicDataSourceFactory" />
</Context>
4 changes: 0 additions & 4 deletions php/templates/default/opsworks.php.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ class OpsWorksDb {
$this->database = '<%= @database[:database] %>';
$this->encoding = 'utf8';
$this->host = '<%= @database[:host] %>';
<% if @database[:port] %>
$this->host = '<%= @database[:port] %>';
<% end %>
$this->host = '<%= @database[:host] %>';
$this->username = '<%= @database[:username] %>';
$this->password = '<%= @database[:password] %>';
$this->reconnect = '<%= @database[:reconnect] ? 'true' : 'false' %>';
Expand Down
53 changes: 24 additions & 29 deletions rails/libraries/rails_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
module OpsWorks
module RailsConfiguration


def self.determine_database_adapter(app_name, app_config, app_root_path, options = {})
options = {
:consult_gemfile => true,
:force => false
}.update(options)
if options[:force] || app_config[:database][:adapter].blank?
Chef::Log.info("No database adapter specified for #{app_name}, guessing")
adapter = ''

adapter = app_config["database"]["adapter"]
data_source_provider = app_config["database"]["data_source_provider"]

return adapter if data_source_provider == 'rds'
return adapter unless options[:force]

Chef::Log.info("No database adapter specified for #{app_name}, guessing")
adapter = ''

if options[:consult_gemfile] and File.exists?("#{app_root_path}/Gemfile")
bundle_list = `cd #{app_root_path}; /usr/local/bin/bundle list`
adapter = if bundle_list.include?('mysql2')
Chef::Log.info("Looks like #{app_name} uses mysql2 in its Gemfile")
'mysql2'
else
Chef::Log.info("Gem mysql2 not found in the Gemfile of #{app_name}, defaulting to mysql")
'mysql'
if options[:consult_gemfile] and File.exists?("#{app_root_path}/Gemfile")
bundle_list = `cd #{app_root_path}; /usr/local/bin/bundle list`
adapter = if bundle_list.include?('mysql2')
Chef::Log.info("Looks like #{app_name} uses mysql2 in its Gemfile")
'mysql2'
else
Chef::Log.info("Gem mysql2 not found in the Gemfile of #{app_name}, defaulting to mysql")
'mysql'
end
else # no Gemfile - guess adapter by Rails version
adapter = if File.exists?("#{app_root_path}/config/application.rb")
Chef::Log.info("Looks like #{app_name} is a Rails 3 application, defaulting to mysql2")
'mysql2'
else
Chef::Log.info("No config/application.rb found, assuming #{app_name} is a Rails 2 application, defaulting to mysql")
'mysql'
end
end
else # no Gemfile - guess adapter by Rails version
adapter = if File.exists?("#{app_root_path}/config/application.rb")
Chef::Log.info("Looks like #{app_name} is a Rails 3 application, defaulting to mysql2")
'mysql2'
else
Chef::Log.info("No config/application.rb found, assuming #{app_name} is a Rails 2 application, defaulting to mysql")
'mysql'
end
end

adapter
adapter
else
app_config[:database][:adapter]
end
end

def self.bundle(app_name, app_config, app_root_path)
Expand Down
69 changes: 0 additions & 69 deletions rails/specs/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,4 @@
include MiniTest::Chef::Resources
include MiniTest::Chef::Assertions

context 'Opsworks::RailsConfiguration.determine_database_adapter' do
context 'when the provider is rds' do
it 'returns the adapter from the app config' do
check_apps = node[:deploy].select do |name, application|
application[:database][:data_source_provider] == 'rds'
end

skip unless check_apps.length > 0

check_apps.each do |name, application|
adapter = node[:deploy][name]["database"]["adapter"]

expected_adapter = adapter == 'postgres' ? 'postgresql' : adapter

assert_equal expected_adapter, OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end
end
end

context 'when the provider is stack' do
it 'returns the adapter from the app config if the force flag is not set' do
check_apps = node[:deploy].select do |name, application|
application[:database][:data_source_provider] == 'stack'
end

skip unless check_apps.length > 0
skip if node[:force_database_adapter_detection]

check_apps.each do |name, application|
assert_equal node[:deploy][name]["database"]["adapter"], OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end
end
end

context 'when the force flag is set' do
setup do
skip unless node[:force_database_adapter_detection]
end

context 'with a Gemfile' do
setup do
skip unless File.exists?("#{node[:deploy][application][:deploy_to]}/current/Gemfile")
bundle_list = `cd #{node[:deploy][application][:deploy_to]}/current/Gemfile; /usr/local/bin/bundle list`
end

it 'defaults to mysql' do
skip if bundle_list.include?('mysql2')
assert_equal 'mysql', OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end

it 'returns mysql2 if in the gemfile' do
skip unless bundle_list.include?('mysql2')
assert_equal 'mysql2', OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end
end

context 'without a Gemfile' do
it 'returns mysql2 for a rails 3 application' do
skip unless File.exists?("#{node[:deploy][application][:deploy_to]}/current/application.rb")
assert_equal 'mysql2', OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end

it 'returns mysql for a rails to application' do
skip if File.exists?("#{node[:deploy][application][:deploy_to]}/current/application.rb")
assert_equal 'mysql2', OpsWorks::RailsConfiguration.determine_database_adapter(name, node[:deploy][name], "#{node[:deploy][application][:deploy_to]}/current", :force => node[:force_database_adapter_detection])
end
end
end
end
end
4 changes: 0 additions & 4 deletions rails/templates/default/database.yml.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<% (['development', 'production'] + [@environment]).uniq.each do |env| -%>
<%= env %>:
<% if @database[:adapter].to_s == "postgres" %>
adapter: "postgresql"
<% else %>
adapter: <%= @database[:adapter].to_s.inspect %>
<% end %>
database: <%= @database[:database].to_s.inspect %>
encoding: <%= (@database[:encoding] || 'utf8').to_s.inspect %>
host: <%= (@database[:host] || 'localhost').to_s.inspect %>
Expand Down

0 comments on commit a363c36

Please sign in to comment.