Skip to content

Commit

Permalink
Cleanup the dummy app database configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Dec 11, 2023
1 parent 4e3862c commit d9a7553
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 139 deletions.
134 changes: 41 additions & 93 deletions core/lib/generators/spree/dummy/templates/rails/database.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,61 @@
<% db = case ENV['DB']
when 'mysql'
'mysql'
when 'postgres', 'postgresql'
'postgres'
when 'sqlite', '', nil
'sqlite'
else
raise "Invalid DB specified: #{ENV['DB']}"
end %>
<% db_host = case db
when 'mysql'
ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgres'
ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
else
ENV['DB_HOST']
end %>
<% db_username = ENV['DB_USERNAME'] %>
<% db_password = ENV['DB_PASSWORD'] %>
<%
adapter =
case ENV['DB']
when 'mysql2', 'mysql' then 'mysql2'
when 'postgresql', 'postgres' then 'postgresql'
when 'sqlite3', 'sqlite', '', nil then 'sqlite3'
else raise "Invalid DB specified " + ENV['DB'].inspect
end
<% case ENV['DB']
when 'mysql' %>
db_host =
case adapter
when 'mysql2' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgres' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
else ENV['DB_HOST']
end
db_username = ENV['DB_USERNAME']
db_password = ENV['DB_PASSWORD'] %>

default:
adapter: <%= adapter %>
<% unless db_username.blank? %>username: <%= db_username %><% end %>
<% unless db_password.blank? %>password: <%= db_password %><% end %>
<% unless db_host.blank? %>host: <%= db_host %><% end %>
<% if adapter == 'mysql2' %>encoding: utf8<% end %>
<% if adapter == 'postgresql' %>min_messages: warning<% end %>

<% if adapter == 'mysql2' %>
development:
adapter: mysql2
<<: *default
database: <%= options[:lib_name] %>_solidus_development
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
encoding: utf8
test:
adapter: mysql2
<<: *default
database: <%= options[:lib_name] %>_solidus_test
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
encoding: utf8
production:
adapter: mysql2
<<: *default
database: <%= options[:lib_name] %>_solidus_production
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
encoding: utf8
<% when 'postgres', 'postgresql' %>

<% elsif adapter == 'postgresql' %>
development:
adapter: postgresql
<<: *default
database: <%= options[:lib_name] %>_solidus_development
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
min_messages: warning
test:
adapter: postgresql
<<: *default
database: <%= options[:lib_name] %>_solidus_test
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
min_messages: warning
production:
adapter: postgresql
<<: *default
database: <%= options[:lib_name] %>_solidus_production
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
min_messages: warning
<% when 'sqlite', '', nil %>

<% elsif adapter == 'sqlite3' %>
development:
adapter: sqlite3
<<: *default
database: db/solidus_development.sqlite3
test:
adapter: sqlite3
<<: *default
database: db/solidus_test.sqlite3
production:
adapter: sqlite3
<<: *default
database: db/solidus_production.sqlite3

<% end %>
83 changes: 37 additions & 46 deletions core/lib/spree/testing_support/dummy_app/database.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
<% db = case ENV['DB']
when 'mysql'
'mysql'
when 'postgres', 'postgresql'
'postgres'
when 'sqlite', '', nil
'sqlite'
else
raise "Invalid DB specified: #{ENV['DB']}"
end %>
<% db_host = case db
when 'mysql'
ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgres'
ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
else
ENV['DB_HOST']
end %>
<% db_prefix = ENV['LIB_NAME'].presence || "solidus" %>
<% db_username = ENV['DB_USERNAME'] %>
<% db_password = ENV['DB_PASSWORD'] %>
<% case db
when 'mysql' %>
<%
adapter =
case ENV['DB']
when 'mysql2', 'mysql' then 'mysql2'
when 'postgresql', 'postgres' then 'postgresql'
when 'sqlite3', 'sqlite', '', nil then 'sqlite3'
else raise "Invalid DB specified " + ENV['DB'].inspect
end
db_host =
case adapter
when 'mysql' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgres' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
else ENV['DB_HOST']
end
db_prefix = ENV['LIB_NAME'].presence || "solidus"
db_username = ENV['DB_USERNAME']
db_password = ENV['DB_PASSWORD'] %>

default: &default
adapter: <%= adapter %>
<% unless db_username.blank? %>username: <%= db_username %><% end %>
<% unless db_password.blank? %>password: <%= db_password %><% end %>
<% unless db_host.blank? %>host: <%= db_host %><% end %>
<% if adapter == 'mysql2' %>encoding: utf8<% end %>
<% if adapter == 'postgresql' %>min_messages: warning<% end %>

<% if adapter == 'mysql2' %>
test:
adapter: mysql2
<<: *default
database: <%= db_prefix %>_test
<% unless db_username.blank? %>
username: <%= db_username %>
<% end %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
encoding: utf8
<% when 'postgres' %>

<% elsif adapter == 'postgresql' %>
test:
adapter: postgresql
<<: *default
database: <%= db_prefix %>_test
username: <%= db_username.presence || "postgres" %>
<% unless db_password.blank? %>
password: <%= db_password %>
<% end %>
<% unless db_host.blank? %>
host: <%= db_host %>
<% end %>
min_messages: warning
<% when 'sqlite' %>

<% elsif adapter == 'sqlite3' %>
test:
adapter: sqlite3
<<: *default
database: db/<%= db_prefix %>_test.sqlite3
timeout: 10000

<% end %>

0 comments on commit d9a7553

Please sign in to comment.