Permalink
Browse files

Added Sqlite Driver support

  • Loading branch information...
ajgon committed Apr 24, 2016
1 parent 197b7de commit 3ecb321b81300195c0005b661d34d586a9bcbb14
View
@@ -19,6 +19,7 @@ to do is create a layer and application with assigned RDS data source, then
* MariaDB
* MySQL
* PostgreSQL
* Sqlite3
* SCM
* git
* Framework
@@ -75,8 +76,8 @@ you don't need to use them. The chef will do all the job, and determine them
for you.
* `app['database']['adapter']`
* **Supported values:** `mariadb`, `mysql`, `postgresql`
* **Default:** `postgresql`
* **Supported values:** `mariadb`, `mysql`, `postgresql`, `sqlite3`
* **Default:** `sqlite3` (if no RDBMS is detected)
* ActiveRecord adapter which will be used for database connection.
* `app['database']['username']`
* Username used to authenticate to the DB
@@ -3,6 +3,7 @@ module Drivers
module Db
class Base < Drivers::Base
include Drivers::Dsl::Defaults
include Drivers::Dsl::Output
include Drivers::Dsl::Packages
defaults encoding: 'utf8', host: 'localhost', reconnect: true
@@ -39,7 +40,7 @@ def out
out_defaults.merge(
adapter: adapter, username: options[:rds]['db_user'], password: options[:rds]['db_password'],
host: options[:rds]['address'], database: app['data_sources'].first['database_name']
host: options[:rds]['address'], database: app['data_sources'].first.try(:[], 'database_name')
)
end
# rubocop:enable Metrics/AbcSize
@@ -0,0 +1,17 @@
# frozen_string_literal: true
module Drivers
module Db
class Sqlite < Base
adapter :sqlite3
allowed_engines :sqlite, :sqlite3
packages debian: 'libsqlite3-dev', rhel: 'sqlite-devel'
output filter: [:adapter, :database, :pool, :timeout]
def out
output = super
output[:database] ||= 'db/data.sqlite3'
handle_output(output)
end
end
end
end
View
@@ -44,8 +44,12 @@ def every_enabled_application
end
def every_enabled_rds
rdses.each do |rds|
yield rds
if rdses.blank?
yield('engine' => 'sqlite')
else
rdses.each do |rds|
yield rds
end
end
end
@@ -233,6 +233,34 @@
end
end
context 'Sqlite3' do
let(:dummy_node) do
node(deploy: { dummy_project: { database: { adapter: 'sqlite3' } } })
end
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['deploy'] = dummy_node['deploy']
end.converge(described_recipe)
end
before do
stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app(data_sources: [])])
stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([])
end
it 'creates proper database.yml template' do
db_config = Drivers::Db::Sqlite.new(
aws_opsworks_app(data_sources: []), dummy_node, rds: aws_opsworks_rds_db_instance(engine: 'sqlite3')
).out
expect(db_config[:adapter]).to eq 'sqlite3'
expect(db_config[:database]).to eq 'db/data.sqlite3'
expect(chef_run)
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/database.yml").with_content(
JSON.parse({ development: db_config, production: db_config }.to_json).to_yaml
)
end
end
it 'empty node[\'deploy\']' do
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
@@ -163,6 +163,20 @@
end
end
context 'Sqlite' do
before do
stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([])
end
it 'installs required packages for debian' do
expect(chef_run).to install_package('libsqlite3-dev')
end
it 'installs required packages for rhel' do
expect(chef_run_rhel).to install_package('sqlite-devel')
end
end
it 'empty node[\'deploy\']' do
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']

0 comments on commit 3ecb321

Please sign in to comment.