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

Cleanup the database configuration #5545

Merged
merged 1 commit into from
Dec 11, 2023
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 .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ executors:
<<: *environment
DB: postgresql
DB_HOST: localhost
DB_USERNAME: root
docker:
- image: *image
- image: jhawthorn/circleci-postgres-fast
Expand Down
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 %>