From 74145f16ade4aefff767ec0748075d9b7765b3e0 Mon Sep 17 00:00:00 2001 From: Cal Heldenbrand Date: Fri, 21 Jun 2019 15:38:35 -0500 Subject: [PATCH 1/4] Setup a docker development environment --- .dockerignore | 12 +++++++++ Dockerfile | 28 ++++++++++++++++++++ README.mkdn | 41 +++++++++++++++++++++++++++++ Rakefile | 7 +++-- docker-compose.yml | 41 +++++++++++++++++++++++++++++ docker/startup.sh | 27 +++++++++++++++++++ spec/config/shards.yml | 9 ++++--- spec/octopus/octopus_spec.rb | 2 +- spec/support/database_connection.rb | 9 ++++++- spec/support/database_models.rb | 2 +- 10 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 docker/startup.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e64ea9d9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +*.gem +*.sqlite3 +.bundle +.rvmrc +.ruby-version +Gemfile.lock +gemfiles/*.lock +pkg/* +*.rbc +tmp/* +.*.sw[a-z] +database.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9b6afc7e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM ruby:2.5 + +RUN apt-get update && apt-get install -y \ + mysql-client \ + postgresql + +WORKDIR /usr/src/app + +# Pull in a full profile for gem/bundler +SHELL ["/bin/bash", "-l", "-c"] + +RUN gem install --no-document bundler -v 1.16.6 + +# Copy only what's needed for bundler +COPY Gemfile ar-octopus.gemspec /usr/src/app/ +COPY lib/octopus/version.rb /usr/src/app/lib/octopus/version.rb + +RUN bundle install + +# Uncomment if you want to copy the octopus repo +# into the Docker image itself. docker-compose is +# set up to use a bind mount of your local directory +# from the host +#COPY . /usr/src/app + +# This just keeps the container running. Replace +# this with a rails server if you want +CMD ["/bin/sleep", "infinity"] diff --git a/README.mkdn b/README.mkdn index 99d57a65..fa132b37 100644 --- a/README.mkdn +++ b/README.mkdn @@ -229,6 +229,47 @@ bundle install cucumber ``` +### Using Docker Compose + +For a more consistent build/test/development environment, use [Docker Compose](https://docs.docker.com/compose/install/). + +```bash +[me@host octopus]$ docker-compose -f docker-compose.yml up +Creating network "octopus_default" with the default driver +Creating octopus_postgres_1 ... +Creating octopus_mysql_1 ... +Creating octopus_postgres_1 +. . . +octopus_1 | mysqld is alive +octopus_1 | MySQL is ready +octopus_1 | + bundle exec rake db:prepare +. . . +octopus_1 | + bundle exec rake spec +. . . +octopus_1 | Finished in 7 minutes 44 seconds (files took 0.71416 seconds to load) +octopus_1 | 359 examples, 0 failures, 2 pending + +(Ctrl+C to shut down the stack) +``` + +Your workstation's octopus clone is mounted inside the docker container, so +you may still use your favorite development tools. The `octopus_1` container +is available for re-running the test suite. To start a new shell in another +terminal, run: + +```bash +[me@host octopus]$ docker-compose exec octopus /bin/bash +root@f6ae68df6fc8:/usr/src/app# + # run bundle exec rake spec again +``` + +To completely destory the stack and start over: + +```bash +[me@host octopus]$ docker-compose -f docker-compose.yml down +[me@host octopus]$ docker-compose -f docker-compose.yml up +``` + If you are having issues running the octopus spec suite, verify your database users and passwords match those inside the config files and your permissions are correct. ## Contributors: diff --git a/Rakefile b/Rakefile index e3d5f728..0aa741ac 100644 --- a/Rakefile +++ b/Rakefile @@ -13,15 +13,17 @@ namespace :db do task :build_databases do pg_spec = { :adapter => 'postgresql', - :host => 'localhost', + :host => (ENV['POSTGRES_HOST'] || ''), :username => (ENV['POSTGRES_USER'] || 'postgres'), + :password => (ENV['POSTGRES_PASSWORD'] || ''), :encoding => 'utf8', } mysql_spec = { :adapter => 'mysql2', - :host => 'localhost', + :host => (ENV['MYSQL_HOST'] || ''), :username => (ENV['MYSQL_USER'] || 'root'), + :password => (ENV['MYSQL_PASSWORD'] || ''), :encoding => 'utf8', } @@ -64,6 +66,7 @@ namespace :db do # the model be a descendent of ActiveRecord::Base. class BlankModel < ActiveRecord::Base; end + puts "Preparing shard #{shard_symbol}" BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table BlankModel.using(shard_symbol).connection.initialize_metadata_table if Octopus.atleast_rails50? diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..b74c4a00 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +version: '3' + +services: + octopus: + build: . + # Your local clone binds to /usr/src/app + volumes: + - .:/usr/src/app + environment: + POSTGRES_HOST: postgres # image name below + POSTGRES_USER: postgres + POSTGRES_PASSWORD: testpassword # password below + MYSQL_HOST: mysql + MYSQL_USER: root + MYSQL_PASSWORD: testpassword + depends_on: + - mysql + - postgres + # Wait for databases to start up, run test suite + command: ./docker/startup.sh + mysql: + image: mysql:8 + command: --default-authentication-plugin=mysql_native_password + restart: always + environment: + MYSQL_ROOT_PASSWORD: testpassword + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + interval: 10s + timeout: 20s + retries: 5 + postgres: + image: postgres:11 + restart: always + environment: + POSTGRES_PASSWORD: testpassword + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 diff --git a/docker/startup.sh b/docker/startup.sh new file mode 100755 index 00000000..de7810d1 --- /dev/null +++ b/docker/startup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +# Wait for our two databases to startup +# (docker-compose v3 removes the health check stuff) +until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c '\q'; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 10 +done + +>&2 echo "Postgres is ready" + +until mysqladmin -u$MYSQL_USER -h $MYSQL_HOST -p$MYSQL_PASSWORD ping; do + >&2 echo "MySQL is unavailable - sleeping" + sleep 10 +done + +>&2 echo "MySQL is ready" + +set -x +bundle exec rake db:prepare +bundle exec rake appraisal:install +bundle exec rake spec +set +x +echo Octopus is ready for you. Run "docker exec octopus /bin/bash" +/bin/sleep infinity diff --git a/spec/config/shards.yml b/spec/config/shards.yml index c4bc2831..ca3c2a16 100644 --- a/spec/config/shards.yml +++ b/spec/config/shards.yml @@ -1,7 +1,8 @@ mysql: &mysql adapter: mysql2 username: <%= ENV['MYSQL_USER'] || 'root' %> - host: localhost + password: <%= ENV['MYSQL_PASSWORD'] || '' %> + host: <%= ENV['MYSQL_HOST'] || 'localhost' %> mysql_unavailable: &mysql_unavailable adapter: mysql2 @@ -18,10 +19,10 @@ octopus: &octopus postgresql_shard: adapter: postgresql username: <%= ENV['POSTGRES_USER'] || 'postgres' %> - password: + password: <%= ENV['POSTGRES_PASSWORD'] || '' %> database: octopus_shard_1 encoding: unicode - host: localhost + host: <%= ENV['POSTGRES_HOST'] || 'localhost' %> sqlite_shard: adapter: sqlite3 @@ -49,7 +50,7 @@ octopus: &octopus database: octopus_shard_4 <<: *mysql - protocol_shard: postgres://<%= ENV['POSTGRES_USER'] || 'postgres' %>@localhost:5432/octopus_shard_2 + protocol_shard: postgres://<%= ENV['POSTGRES_USER'] || 'postgres' %>:<%= ENV['POSTGRES_PASSWORD'] || '' %>@<%= ENV['POSTGRES_HOST'] || 'localhost' %>:5432/octopus_shard_2 octopus_with_default_migration_group: <<: *octopus diff --git a/spec/octopus/octopus_spec.rb b/spec/octopus/octopus_spec.rb index db2077bf..6c6d8cce 100644 --- a/spec/octopus/octopus_spec.rb +++ b/spec/octopus/octopus_spec.rb @@ -40,7 +40,7 @@ expect { User.using(:crazy_shard).create!(:name => 'Joaquim') }.to raise_error(RuntimeError) Octopus.setup do |config| - config.shards = { :crazy_shard => { :adapter => 'mysql2', :database => 'octopus_shard_5', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => '' } } + config.shards = { :crazy_shard => { :adapter => 'mysql2', :database => 'octopus_shard_5', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => "#{ENV['MYSQL_PASSWORD'] || ''}", :host => "#{ENV['MYSQL_HOST'] || 'localhost'}" } } end expect { User.using(:crazy_shard).create!(:name => 'Joaquim') }.not_to raise_error diff --git a/spec/support/database_connection.rb b/spec/support/database_connection.rb index 20b5f2cf..71c9cb90 100644 --- a/spec/support/database_connection.rb +++ b/spec/support/database_connection.rb @@ -1,4 +1,11 @@ require 'logger' -ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'octopus_shard_1', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => '') +ActiveRecord::Base.establish_connection( + :adapter => 'mysql2', + :database => 'octopus_shard_1', + :username => "#{ENV['MYSQL_USER'] || 'root'}", + :password => "#{ENV['MYSQL_PASSWORD'] || ''}", + :host => "#{ENV['MYSQL_HOST'] || 'localhost'}" +) + ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a')) diff --git a/spec/support/database_models.rb b/spec/support/database_models.rb index 787ecebc..5cdc59d7 100644 --- a/spec/support/database_models.rb +++ b/spec/support/database_models.rb @@ -28,7 +28,7 @@ class Cat < ActiveRecord::Base # This class sets its own connection class CustomConnection < ActiveRecord::Base self.table_name = 'custom' - octopus_establish_connection(:adapter => 'mysql2', :database => 'octopus_shard_2', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => '') + octopus_establish_connection(:adapter => 'mysql2', :database => 'octopus_shard_2', :username => "#{ENV['MYSQL_USER'] || 'root'}", :password => "#{ENV['MYSQL_PASSWORD'] || ''}", :host => "#{ENV['MYSQL_HOST'] || 'localhost'}") end # This items belongs to a client From 48090f09fe8766dc241bc426825fce2b052d01e9 Mon Sep 17 00:00:00 2001 From: Cal Heldenbrand Date: Tue, 25 Jun 2019 13:32:20 -0500 Subject: [PATCH 2/4] Start on setting up sample_app -- not working Running cucumber gives the error: cannot load such file -- test/unit (LoadError) --- Dockerfile | 2 +- docker/startup.sh | 5 +- gemfiles/rails42.gemfile | 2 +- lib/octopus/abstract_adapter.rb | 2 +- sample_app/Gemfile | 5 +- sample_app/Gemfile.lock | 159 +++++++++++++++++++------------- sample_app/config/database.yml | 18 ++-- sample_app/script/ci_build | 14 +++ 8 files changed, 126 insertions(+), 81 deletions(-) create mode 100755 sample_app/script/ci_build diff --git a/Dockerfile b/Dockerfile index 9b6afc7e..1e5e673e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN gem install --no-document bundler -v 1.16.6 COPY Gemfile ar-octopus.gemspec /usr/src/app/ COPY lib/octopus/version.rb /usr/src/app/lib/octopus/version.rb -RUN bundle install +RUN bundle install --path=.bundle # Uncomment if you want to copy the octopus repo # into the Docker image itself. docker-compose is diff --git a/docker/startup.sh b/docker/startup.sh index de7810d1..db7bb567 100755 --- a/docker/startup.sh +++ b/docker/startup.sh @@ -19,9 +19,12 @@ done >&2 echo "MySQL is ready" set -x +bundle install bundle exec rake db:prepare bundle exec rake appraisal:install bundle exec rake spec +#Not working yet +#./sample_app/script/ci_build set +x -echo Octopus is ready for you. Run "docker exec octopus /bin/bash" +echo Octopus is ready for you. Run \"docker-compose exec octopus /bin/bash\" /bin/sleep infinity diff --git a/gemfiles/rails42.gemfile b/gemfiles/rails42.gemfile index 24e5e488..9be86420 100644 --- a/gemfiles/rails42.gemfile +++ b/gemfiles/rails42.gemfile @@ -3,5 +3,5 @@ source "https://rubygems.org" gem "activerecord", "~> 4.2.0" -gem "mysql2", "0.4.10" + gemspec path: "../" diff --git a/lib/octopus/abstract_adapter.rb b/lib/octopus/abstract_adapter.rb index f6ce7956..646f2272 100644 --- a/lib/octopus/abstract_adapter.rb +++ b/lib/octopus/abstract_adapter.rb @@ -19,7 +19,7 @@ def method_missing(meth, *args, &block) end def octopus_shard - @config[:octopus_shard] + @config && @config[:octopus_shard] end def initialize(*args) diff --git a/sample_app/Gemfile b/sample_app/Gemfile index 7f667363..49331897 100644 --- a/sample_app/Gemfile +++ b/sample_app/Gemfile @@ -5,10 +5,11 @@ gem 'rails', '3.2.13' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' -gem 'pg' -gem 'sqlite3' +gem 'pg', '~> 0.11' +gem 'sqlite3', '~> 1.3.5' gem 'ar-octopus', '0.6.0' gem 'pry' +gem 'json', '~> 1.8.6' group :test do gem 'capybara' diff --git a/sample_app/Gemfile.lock b/sample_app/Gemfile.lock index 54b6f2ba..5483f1eb 100644 --- a/sample_app/Gemfile.lock +++ b/sample_app/Gemfile.lock @@ -28,70 +28,88 @@ GEM activesupport (3.2.13) i18n (= 0.6.1) multi_json (~> 1.0) - addressable (2.3.5) + addressable (2.6.0) + public_suffix (>= 2.0.2, < 4.0) ar-octopus (0.6.0) activerecord (>= 3.0.0, < 4.0) activesupport (>= 3.0.0, < 4.0) - arel (3.0.2) - aruba (0.5.3) - childprocess (>= 0.3.6) - cucumber (>= 1.1.1) - rspec-expectations (>= 2.7.0) + arel (3.0.3) + aruba (0.14.10) + childprocess (>= 0.6.3, < 1.1.0) + contracts (~> 0.9) + cucumber (>= 1.3.19) + ffi (~> 1.9) + rspec-expectations (>= 2.99) + thor (~> 0.19) + backports (3.15.0) builder (3.0.4) - capybara (2.1.0) - mime-types (>= 1.16) + capybara (2.18.0) + addressable + mini_mime (>= 0.1.3) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - xpath (~> 2.0) - childprocess (0.3.9) - ffi (~> 1.0, >= 1.0.11) - coderay (1.0.9) - cucumber (1.3.3) + xpath (>= 2.0, < 4.0) + childprocess (1.0.1) + rake (< 13.0) + coderay (1.1.2) + contracts (0.16.0) + cucumber (3.1.2) builder (>= 2.1.2) - diff-lcs (>= 1.1.3) - gherkin (~> 2.12.0) - multi_json (~> 1.7.5) - multi_test (~> 0.0.1) - cucumber-rails (1.3.1) - capybara (>= 1.1.2) - cucumber (>= 1.2.0) - nokogiri (>= 1.5.0) - rails (~> 3.0) - database_cleaner (1.0.1) - diff-lcs (1.2.4) + cucumber-core (~> 3.2.0) + cucumber-expressions (~> 6.0.1) + cucumber-wire (~> 0.0.1) + diff-lcs (~> 1.3) + gherkin (~> 5.1.0) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.2) + cucumber-core (3.2.1) + backports (>= 3.8.0) + cucumber-tag_expressions (~> 1.1.0) + gherkin (~> 5.0) + cucumber-expressions (6.0.1) + cucumber-rails (1.4.5) + capybara (>= 1.1.2, < 3) + cucumber (>= 1.3.8, < 4) + mime-types (>= 1.16, < 4) + nokogiri (~> 1.5) + railties (>= 3, < 5.1) + cucumber-tag_expressions (1.1.1) + cucumber-wire (0.0.1) + database_cleaner (1.7.0) + diff-lcs (1.3) erubis (2.7.0) - ffi (1.9.0) - gherkin (2.12.0) - multi_json (~> 1.3) + ffi (1.11.1) + gherkin (5.1.0) hike (1.2.3) i18n (0.6.1) journey (1.0.4) - json (1.8.0) - launchy (2.3.0) + json (1.8.6) + launchy (2.4.3) addressable (~> 2.3) - mail (2.5.4) + mail (2.5.5) mime-types (~> 1.16) treetop (~> 1.4.8) - method_source (0.8.1) - mime-types (1.23) - mini_portile (0.5.1) - multi_json (1.7.7) - multi_test (0.0.1) - nokogiri (1.6.0) - mini_portile (~> 0.5.0) - pg (0.15.1) - polyglot (0.3.3) - pry (0.9.12.2) - coderay (~> 1.0.5) - method_source (~> 0.8) - slop (~> 3.4) - rack (1.4.5) - rack-cache (1.2) + method_source (0.9.2) + mime-types (1.25.1) + mini_mime (1.0.1) + mini_portile2 (2.4.0) + multi_json (1.13.1) + multi_test (0.1.2) + nokogiri (1.10.3) + mini_portile2 (~> 2.4.0) + pg (0.21.0) + polyglot (0.3.5) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + public_suffix (3.1.0) + rack (1.4.7) + rack-cache (1.9.0) rack (>= 0.4) - rack-ssl (1.3.3) + rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) rails (3.2.13) actionmailer (= 3.2.13) @@ -108,35 +126,40 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.1.0) + rake (12.3.2) rdoc (3.12.2) json (~> 1.4) - rspec-core (2.14.0) - rspec-expectations (2.14.0) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.0) - rspec-rails (2.14.0) + rspec-core (3.8.1) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-rails (3.8.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - slop (3.4.5) - sprockets (2.2.2) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.2) + sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - sqlite3 (1.3.7) - thor (0.18.1) + sqlite3 (1.3.13) + thor (0.20.3) tilt (1.4.1) - treetop (1.4.14) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) - xpath (2.0.0) - nokogiri (~> 1.3) + tzinfo (0.3.55) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby @@ -147,9 +170,13 @@ DEPENDENCIES capybara cucumber-rails database_cleaner + json (~> 1.8.6) launchy - pg + pg (~> 0.11) pry rails (= 3.2.13) rspec-rails - sqlite3 + sqlite3 (~> 1.3.5) + +BUNDLED WITH + 1.17.3 diff --git a/sample_app/config/database.yml b/sample_app/config/database.yml index d26cc790..d75ece45 100644 --- a/sample_app/config/database.yml +++ b/sample_app/config/database.yml @@ -2,27 +2,27 @@ # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: postgresql - username: postgres - password: + username: <%= ENV['POSTGRES_USER'] || 'postgres' %> + password: <%= ENV['POSTGRES_PASSWORD'] || '' %> database: octopus_sample_app_development encoding: unicode - host: localhost + host: <%= ENV['POSTGRES_HOST'] || 'localhost' %> # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: &test adapter: postgresql - username: postgres - password: + username: <%= ENV['POSTGRES_USER'] || 'postgres' %> + password: <%= ENV['POSTGRES_PASSWORD'] || '' %> database: octopus_sample_app_test encoding: unicode - host: localhost + host: <%= ENV['POSTGRES_HOST'] || 'localhost' %> production: adapter: postgresql - username: postgres - password: + username: <%= ENV['POSTGRES_USER'] || 'postgres' %> + password: <%= ENV['POSTGRES_PASSWORD'] || '' %> database: octopus_sample_app_production encoding: unicode - host: localhost + host: <%= ENV['POSTGRES_HOST'] || 'localhost' %> diff --git a/sample_app/script/ci_build b/sample_app/script/ci_build new file mode 100755 index 00000000..38ba2d93 --- /dev/null +++ b/sample_app/script/ci_build @@ -0,0 +1,14 @@ +#!/bin/bash +dir=`readlink -f $0` +dir="`dirname $dir`/.." +RAILS_ROOT=`readlink -f $dir` +cd $RAILS_ROOT + +bundle install --path=$RAILS_ROOT/.bundle + +for stage in test development production; do + PGPASSWORD=$POSTGRES_PASSWORD psql -h "$POSTGRES_HOST" -U "$POSTGRES_USER" -c "create database octopus_sample_app_$stage" +done + +# Not working... +bundle exec cucumber From 8e2671d20dd6ff48c82e58ac2eedbee8b592765f Mon Sep 17 00:00:00 2001 From: Cal Heldenbrand Date: Tue, 25 Jun 2019 13:55:15 -0500 Subject: [PATCH 3/4] Ooops, revert a couple files. These weren't supposed to make it into this PR --- gemfiles/rails42.gemfile | 2 +- lib/octopus/abstract_adapter.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gemfiles/rails42.gemfile b/gemfiles/rails42.gemfile index 9be86420..24e5e488 100644 --- a/gemfiles/rails42.gemfile +++ b/gemfiles/rails42.gemfile @@ -3,5 +3,5 @@ source "https://rubygems.org" gem "activerecord", "~> 4.2.0" - +gem "mysql2", "0.4.10" gemspec path: "../" diff --git a/lib/octopus/abstract_adapter.rb b/lib/octopus/abstract_adapter.rb index 646f2272..f6ce7956 100644 --- a/lib/octopus/abstract_adapter.rb +++ b/lib/octopus/abstract_adapter.rb @@ -19,7 +19,7 @@ def method_missing(meth, *args, &block) end def octopus_shard - @config && @config[:octopus_shard] + @config[:octopus_shard] end def initialize(*args) From 3e9f50b32060c8deccbc8c79038a55d027f14423 Mon Sep 17 00:00:00 2001 From: Cal Heldenbrand Date: Wed, 26 Jun 2019 14:43:39 -0500 Subject: [PATCH 4/4] Check that @config exists. Fixes #413 Error message is: ActiveRecord::StatementInvalid: NoMethodError: undefined method `[]' for nil:NilClass: from octopus/lib/octopus/abstract_adapter.rb:23:in `octopus_shard' from octopus/lib/octopus/abstract_adapter.rb:12:in `instrument' from vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log' This has shown to surface in the ibm_db and sqlserver adapters. --- lib/octopus/abstract_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/octopus/abstract_adapter.rb b/lib/octopus/abstract_adapter.rb index f6ce7956..646f2272 100644 --- a/lib/octopus/abstract_adapter.rb +++ b/lib/octopus/abstract_adapter.rb @@ -19,7 +19,7 @@ def method_missing(meth, *args, &block) end def octopus_shard - @config[:octopus_shard] + @config && @config[:octopus_shard] end def initialize(*args)