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

Ensure "sqlite3" is supported in addition to "sqlite" for testing #4718

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ executors:
working_directory: *workdir
environment:
<<: *environment
DB: sqlite
DB: sqlite3
docker:
- image: *image

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
# and https://github.com/rails/sprockets-rails/issues/369
gem 'sprockets', '~> 3'

dbs = ENV['DB_ALL'] ? 'all' : ENV.fetch('DB', 'sqlite')
dbs = ENV['DB_ALL'] ? 'all' : ENV.fetch('DB', 'sqlite3')
gem 'mysql2', '~> 0.5.0', require: false if dbs.match?(/all|mysql/)
gem 'pg', '~> 1.0', require: false if dbs.match?(/all|postgres/)
gem 'fast_sqlite', require: false if dbs.match?(/all|sqlite/)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ createuser --superuser --echo postgres # only the first time
bin/build
```

The `bin/build` script runs using PostgreSQL by default, but it can be overridden by setting the DB environment variable to `DB=sqlite` or `DB=mysql`. For example:
The `bin/build` script runs using PostgreSQL by default, but it can be overridden by setting the DB environment variable to `DB=sqlite3` or `DB=mysql`. For example:

```bash
env DB=mysql bin/build
Expand Down
2 changes: 1 addition & 1 deletion bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# Target postgresql. Override with: `env DB=sqlite bin/build`
# Target postgresql. Override with: `env DB=sqlite3 bin/build`
export DB=${DB:-postgresql}

if [ -n "$COVERAGE" ]; then
Expand Down
2 changes: 1 addition & 1 deletion bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mysql)
USERNAME=$DB_USERNAME
PASSWORD=$DB_PASSWORD
;;
sqlite|'')
sqlite3|sqlite|'')
RAILSDB="sqlite3"
;;
*)
Expand Down
159 changes: 47 additions & 112 deletions core/lib/generators/spree/dummy/templates/rails/database.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,48 @@
<% 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'] %>
<%=
require 'yaml'

<% case ENV['DB']
when 'mysql' %>
development:
adapter: mysql2
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
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
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' %>
development:
adapter: postgresql
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
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
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 %>
development:
adapter: sqlite3
database: db/solidus_development.sqlite3
test:
adapter: sqlite3
database: db/solidus_test.sqlite3
production:
adapter: sqlite3
database: db/solidus_production.sqlite3
<% end %>
lib = "#{options[:lib_name]}_solidus"

case ENV['DB'].presence
when /mysql/
default = {
adapter: 'mysql2',
encoding: 'utf8',
host: (ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']).presence,
username: ENV['DB_PASSWORD'].presence,
password: ENV['DB_USERNAME'].presence,
}.compact

config = {
development: default.merge(database: "#{lib}_development"),
production: default.merge(database: "#{lib}_production"),
test: default.merge(database: "#{lib}_test"),
}
when /postgres/
default = {
adapter: 'postgresql',
encoding: 'utf8',
host: ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST'],
username: ENV['DB_PASSWORD'].presence,
password: ENV['DB_USERNAME'].presence,
}.compact

config = {
development: default.merge(database: "#{lib}_development"),
production: default.merge(database: "#{lib}_production"),
test: default.merge(database: "#{lib}_test"),
}
when /sqlite/, nil
default = {
adapter: sqlite3
}
config = {
development: default.merge(database: "db/#{lib}_development.sqlite3"),
production: default.merge(database: "db/#{lib}_production.sqlite3"),
test: default.merge(database: "db/#{lib}_test.sqlite3"),
}
else raise "Invalid DB specified: #{ENV['DB'].inspect}"
end

config.deep_stringify_keys.to_yaml
%>
102 changes: 48 additions & 54 deletions core/lib/spree/testing_support/dummy_app/database.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,48 @@
<% 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' %>
test:
adapter: mysql2
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' %>
test:
adapter: postgresql
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' %>
test:
adapter: sqlite3
database: db/<%= db_prefix %>_test.sqlite3
timeout: 10000
<% end %>
<%=
require 'yaml'

lib = "#{ENV['LIB_NAME']}_solidus"

case ENV['DB'].presence
when /mysql/
default = {
adapter: 'mysql2',
encoding: 'utf8',
host: (ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']).presence,
username: ENV['DB_PASSWORD'].presence,
password: ENV['DB_USERNAME'].presence,
}.compact

config = {
development: default.merge(database: "#{lib}_development"),
production: default.merge(database: "#{lib}_production"),
test: default.merge(database: "#{lib}_test"),
}
when /postgres/
default = {
adapter: 'postgresql',
encoding: 'utf8',
host: ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST'],
username: ENV['DB_PASSWORD'].presence,
password: ENV['DB_USERNAME'].presence,
}.compact

config = {
development: default.merge(database: "#{lib}_development"),
production: default.merge(database: "#{lib}_production"),
test: default.merge(database: "#{lib}_test"),
}
when /sqlite/, nil
default = {
adapter: sqlite3
}
config = {
development: default.merge(database: "db/#{lib}_development.sqlite3"),
production: default.merge(database: "db/#{lib}_production.sqlite3"),
test: default.merge(database: "db/#{lib}_test.sqlite3"),
}
else raise "Invalid DB specified: #{ENV['DB'].inspect}"
end

config.deep_stringify_keys.to_yaml
%>