Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix: Set the default DB adapter to sqlite3
Browse files Browse the repository at this point in the history
Currently, if no DB adapter is set, both in stack JSON file, and application (no RDS resource
attached), the application crashes with `"There is no supported Db driver for given configuration."`
exception. This is not wanted behavior, as the main goal of this cookbook is to work in
zero-configuration environment. The fix resolves that problem, by simply setting the default DB
adapter to `sqlite3`.
  • Loading branch information
Igor Rzegocki committed Aug 29, 2016
1 parent 8a5223f commit b4b1ee4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -78,8 +78,7 @@ for you.

* `app['database']['adapter']`
* **Supported values:** `mariadb`, `mysql`, `postgresql`, `sqlite3`
* **Note:** There is no default database adapter if a RDS resource is not
defined in your stack.
* **Default:** `sqlite3`
* ActiveRecord adapter which will be used for database connection.
* `app['database']['username']`
* Username used to authenticate to the DB
Expand Down
5 changes: 5 additions & 0 deletions attributes/default.rb
Expand Up @@ -21,6 +21,11 @@
nginx::http_stub_status_module
)

# database
## common

default['defaults']['database']['adapter'] = 'sqlite3'

# scm
## common

Expand Down
3 changes: 2 additions & 1 deletion libraries/drivers_db_base.rb
Expand Up @@ -58,7 +58,8 @@ def app_engine
end

def node_engine
node['deploy'][app['shortname']]['database'].try(:[], 'adapter')
node['deploy'][app['shortname']]['database'].try(:[], 'adapter') ||
node['defaults'].try(:[], 'database').try(:[], 'adapter')
end

private
Expand Down
3 changes: 2 additions & 1 deletion libraries/drivers_db_factory.rb
Expand Up @@ -13,7 +13,8 @@ def self.detect_engine(app, node, options)
Drivers::Db::Base.descendants.detect do |db_driver|
db_driver.allowed_engines.include?(
options.try(:[], :rds).try(:[], 'engine') ||
node.try(:[], 'deploy').try(:[], app['shortname']).try(:[], 'database').try(:[], 'adapter')
node.try(:[], 'deploy').try(:[], app['shortname']).try(:[], 'database').try(:[], 'adapter') ||
node.try(:[], 'defaults').try(:[], 'database').try(:[], 'adapter')
)
end
end
Expand Down

0 comments on commit b4b1ee4

Please sign in to comment.