From db82bee534f69efba4b5ecb87788ddc593bea128 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 17 May 2017 14:19:54 -0400 Subject: [PATCH 1/5] Add more advanced exclusion_condition method and reference in order to solve #445 --- lib/database_cleaner/active_record/base.rb | 8 ++++++++ lib/database_cleaner/active_record/deletion.rb | 2 +- lib/database_cleaner/active_record/truncation.rb | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index 1540483..5f2d885 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -65,6 +65,14 @@ module DatabaseCleaner end end + def self.exclusion_condition + result = " table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' " + if ::ActiveRecord::VERSION::MAJOR >= 5 + result += " AND table_name <> '#{ActiveRecord::Base.internal_metadata_table_name}' " + end + result + end + private def lookup_from_connection_pool diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index c10b3bd..dc99cd7 100644 --- a/lib/database_cleaner/active_record/deletion.rb +++ b/lib/database_cleaner/active_record/deletion.rb @@ -72,7 +72,7 @@ module DatabaseCleaner::ActiveRecord INFORMATION_SCHEMA.TABLES WHERE table_schema = '#{db_name}' - AND table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}'; + AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition}; SQL end end diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index d3f91c6..39c7f75 100644 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -192,7 +192,7 @@ module DatabaseCleaner FROM pg_tables WHERE tablename !~ '_prt_' AND - tablename <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' AND + #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition} AND schemaname = ANY (current_schemas(false)) _SQL rows.collect { |result| result.first } From fdaa552f6edfbc7f7a68f6440a4d0fcc97c9f8fd Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 17 May 2017 14:38:46 -0400 Subject: [PATCH 2/5] Support different column names for MySQL and Postgres --- lib/database_cleaner/active_record/base.rb | 6 +++--- lib/database_cleaner/active_record/deletion.rb | 2 +- lib/database_cleaner/active_record/truncation.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/database_cleaner/active_record/base.rb b/lib/database_cleaner/active_record/base.rb index 5f2d885..42a0b51 100644 --- a/lib/database_cleaner/active_record/base.rb +++ b/lib/database_cleaner/active_record/base.rb @@ -65,10 +65,10 @@ module DatabaseCleaner end end - def self.exclusion_condition - result = " table_name <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' " + def self.exclusion_condition(column_name) + result = " #{column_name} <> '#{::DatabaseCleaner::ActiveRecord::Base.migration_table_name}' " if ::ActiveRecord::VERSION::MAJOR >= 5 - result += " AND table_name <> '#{ActiveRecord::Base.internal_metadata_table_name}' " + result += " AND #{column_name} <> '#{ActiveRecord::Base.internal_metadata_table_name}' " end result end diff --git a/lib/database_cleaner/active_record/deletion.rb b/lib/database_cleaner/active_record/deletion.rb index dc99cd7..59a41c4 100644 --- a/lib/database_cleaner/active_record/deletion.rb +++ b/lib/database_cleaner/active_record/deletion.rb @@ -72,7 +72,7 @@ module DatabaseCleaner::ActiveRecord INFORMATION_SCHEMA.TABLES WHERE table_schema = '#{db_name}' - AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition}; + AND #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('table_name')}; SQL end end diff --git a/lib/database_cleaner/active_record/truncation.rb b/lib/database_cleaner/active_record/truncation.rb index 39c7f75..a470a6c 100644 --- a/lib/database_cleaner/active_record/truncation.rb +++ b/lib/database_cleaner/active_record/truncation.rb @@ -192,7 +192,7 @@ module DatabaseCleaner FROM pg_tables WHERE tablename !~ '_prt_' AND - #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition} AND + #{::DatabaseCleaner::ActiveRecord::Base.exclusion_condition('tablename')} AND schemaname = ANY (current_schemas(false)) _SQL rows.collect { |result| result.first } From 24d592a674b0e8c49610608635ea9aea895bcb31 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Wed, 17 May 2017 14:43:11 -0400 Subject: [PATCH 3/5] Bumped version of database_cleaner. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6c31693..770a873 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - database_cleaner (1.6.0) + database_cleaner (1.6.1) GEM remote: https://rubygems.org/ From c8bc42b9f669667da1a629026cbb50bd8814a907 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Thu, 18 May 2017 08:55:26 -0400 Subject: [PATCH 4/5] Remove Gemfile.lock --- Gemfile.lock | 286 --------------------------------------------------- 1 file changed, 286 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 770a873..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,286 +0,0 @@ -PATH - remote: . - specs: - database_cleaner (1.6.1) - -GEM - remote: https://rubygems.org/ - specs: - abstract (1.0.0) - actionpack (3.0.0) - activemodel (= 3.0.0) - activesupport (= 3.0.0) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.4.1) - rack (~> 1.2.1) - rack-mount (~> 0.6.12) - rack-test (~> 0.5.4) - tzinfo (~> 0.3.23) - activemodel (3.0.0) - activesupport (= 3.0.0) - builder (~> 2.1.2) - i18n (~> 0.4.1) - activerecord (3.0.0) - activemodel (= 3.0.0) - activesupport (= 3.0.0) - arel (~> 1.0.0) - tzinfo (~> 0.3.23) - activerecord-mysql2-adapter (0.0.3) - mysql2 - activesupport (3.0.0) - addressable (2.3.6) - arel (1.0.1) - activesupport (~> 3.0.0) - bcrypt (3.1.7) - bcrypt (3.1.7-java) - bcrypt-ruby (3.1.5) - bcrypt (>= 3.1.3) - bcrypt-ruby (3.1.5-java) - bcrypt (>= 3.1.3) - bson (1.11.1) - bson (1.11.1-java) - bson_ext (1.11.1) - bson (~> 1.11.1) - builder (2.1.2) - coderay (1.1.0) - couch_potato (1.3.0) - activemodel - couchrest (~> 1.2.0) - json (~> 1.6) - couchrest (1.2.0) - mime-types (~> 1.15) - multi_json (~> 1.0) - rest-client (~> 1.6.1) - cucumber (1.2.1) - builder (>= 2.1.2) - diff-lcs (>= 1.1.3) - gherkin (~> 2.11.0) - json (>= 1.4.6) - data_objects (0.10.14) - addressable (~> 2.1) - datamapper (1.2.0) - dm-aggregates (~> 1.2.0) - dm-constraints (~> 1.2.0) - dm-core (~> 1.2.0) - dm-migrations (~> 1.2.0) - dm-serializer (~> 1.2.0) - dm-timestamps (~> 1.2.0) - dm-transactions (~> 1.2.0) - dm-types (~> 1.2.0) - dm-validations (~> 1.2.0) - diff-lcs (1.2.5) - dm-aggregates (1.2.0) - dm-core (~> 1.2.0) - dm-constraints (1.2.0) - dm-core (~> 1.2.0) - dm-core (1.2.1) - addressable (~> 2.3) - dm-do-adapter (1.2.0) - data_objects (~> 0.10.6) - dm-core (~> 1.2.0) - dm-migrations (1.2.0) - dm-core (~> 1.2.0) - dm-serializer (1.2.2) - dm-core (~> 1.2.0) - fastercsv (~> 1.5) - json (~> 1.6) - json_pure (~> 1.6) - multi_json (~> 1.0) - dm-sqlite-adapter (1.2.0) - dm-do-adapter (~> 1.2.0) - do_sqlite3 (~> 0.10.6) - dm-timestamps (1.2.0) - dm-core (~> 1.2.0) - dm-transactions (1.2.0) - dm-core (~> 1.2.0) - dm-types (1.2.2) - bcrypt-ruby (~> 3.0) - dm-core (~> 1.2.0) - fastercsv (~> 1.5) - json (~> 1.6) - multi_json (~> 1.0) - stringex (~> 1.4) - uuidtools (~> 2.1) - dm-validations (1.2.0) - dm-core (~> 1.2.0) - do_jdbc (0.10.14-java) - data_objects (= 0.10.14) - do_sqlite3 (0.10.14) - data_objects (= 0.10.14) - do_sqlite3 (0.10.14-java) - data_objects (= 0.10.14) - do_jdbc (= 0.10.14) - jdbc-sqlite3 (>= 3.5.8) - erubis (2.6.6) - abstract (>= 1.0.0) - faraday (0.9.0) - multipart-post (>= 1.2, < 3) - faraday_middleware (0.9.1) - faraday (>= 0.7.4, < 0.10) - fastercsv (1.5.5) - ffi (1.9.6) - ffi (1.9.6-java) - formatador (0.2.5) - gherkin (2.11.6) - json (>= 1.7.6) - gherkin (2.11.6-java) - json (>= 1.7.6) - guard (1.8.3) - formatador (>= 0.2.4) - listen (~> 1.3) - lumberjack (>= 1.0.2) - pry (>= 0.9.10) - thor (>= 0.14.6) - guard-rspec (2.5.4) - guard (>= 1.1) - rspec (~> 2.11) - httparty (0.13.3) - json (~> 1.8) - multi_xml (>= 0.5.2) - httpclient (2.5.3.3) - i18n (0.4.2) - jdbc-sqlite3 (3.8.10.1) - json (1.8.1) - json (1.8.1-java) - json_pure (1.8.1) - listen (1.3.1) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - rb-kqueue (>= 0.2) - lumberjack (1.0.9) - method_source (0.8.2) - mime-types (1.25.1) - mongo (1.11.1) - bson (= 1.11.1) - mongo_ext (0.19.3) - mongo_mapper (0.12.0) - activemodel (~> 3.0) - activesupport (~> 3.0) - plucky (~> 0.5.2) - mongoid (2.2.6) - activemodel (~> 3.0.0) - mongo (~> 1.3) - tzinfo (~> 0.3.22) - mongoid-tree (0.7.0) - mongoid (~> 2.0) - moped (1.5.2) - multi_json (1.2.0) - multi_xml (0.5.5) - multipart-post (2.0.0) - mysql (2.9.1) - mysql2 (0.3.18) - neo4j-community (2.1.5) - neo4j-core (3.0.8) - activesupport - faraday (~> 0.9.0) - faraday_middleware (~> 0.9.1) - httparty - httpclient - json - neo4j-community (~> 2.1.1) - net-http-persistent - os - zip - nest (1.1.2) - redis - net-http-persistent (2.9.4) - ohm (0.1.5) - nest (~> 1.0) - os (0.9.6) - pg (0.18.2) - plucky (0.5.2) - mongo (~> 1.5) - pry (0.10.1) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - pry (0.10.1-java) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - spoon (~> 0.0) - rack (1.2.8) - rack-mount (0.6.14) - rack (>= 1.0.0) - rack-test (0.5.7) - rack (>= 1.0) - railties (3.0.0) - actionpack (= 3.0.0) - activesupport (= 3.0.0) - rake (>= 0.8.4) - thor (~> 0.14.0) - rake (11.1.2) - rb-fsevent (0.9.4) - rb-inotify (0.9.5) - ffi (>= 0.5.0) - rb-kqueue (0.2.3) - ffi (>= 0.5.0) - rdoc (4.1.2) - json (~> 1.4) - redis (3.1.0) - rest-client (1.6.8) - mime-types (~> 1.16) - rdoc (>= 2.4.2) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rspec-rails (2.14.2) - actionpack (>= 3.0) - activemodel (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - sequel (3.21.0) - slop (3.6.0) - spoon (0.0.4) - ffi - sqlite3 (1.3.10) - stringex (1.5.1) - thor (0.14.6) - tzinfo (0.3.48) - uuidtools (2.1.5) - zip (2.0.2) - -PLATFORMS - java - ruby - -DEPENDENCIES - activerecord - activerecord-mysql2-adapter - bson_ext - bundler - couch_potato - cucumber - database_cleaner! - datamapper - dm-migrations - dm-sqlite-adapter - guard-rspec - json_pure - mongo_ext - mongo_mapper - mongoid - mongoid-tree - moped - mysql (~> 2.9.1) - mysql2 - neo4j-core - ohm (~> 0.1.3) - pg - rake - rspec-rails (~> 2.14.2) - sequel (~> 3.21.0) - sqlite3 - tzinfo - -BUNDLED WITH - 1.14.6 From ac6964eeac245f0ce9e9523e00d16d05f798c399 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Mon, 22 May 2017 09:38:26 -0400 Subject: [PATCH 5/5] Revert "Remove Gemfile.lock" This reverts commit c8bc42b9f669667da1a629026cbb50bd8814a907. --- Gemfile.lock | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..770a873 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,286 @@ +PATH + remote: . + specs: + database_cleaner (1.6.1) + +GEM + remote: https://rubygems.org/ + specs: + abstract (1.0.0) + actionpack (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + builder (~> 2.1.2) + erubis (~> 2.6.6) + i18n (~> 0.4.1) + rack (~> 1.2.1) + rack-mount (~> 0.6.12) + rack-test (~> 0.5.4) + tzinfo (~> 0.3.23) + activemodel (3.0.0) + activesupport (= 3.0.0) + builder (~> 2.1.2) + i18n (~> 0.4.1) + activerecord (3.0.0) + activemodel (= 3.0.0) + activesupport (= 3.0.0) + arel (~> 1.0.0) + tzinfo (~> 0.3.23) + activerecord-mysql2-adapter (0.0.3) + mysql2 + activesupport (3.0.0) + addressable (2.3.6) + arel (1.0.1) + activesupport (~> 3.0.0) + bcrypt (3.1.7) + bcrypt (3.1.7-java) + bcrypt-ruby (3.1.5) + bcrypt (>= 3.1.3) + bcrypt-ruby (3.1.5-java) + bcrypt (>= 3.1.3) + bson (1.11.1) + bson (1.11.1-java) + bson_ext (1.11.1) + bson (~> 1.11.1) + builder (2.1.2) + coderay (1.1.0) + couch_potato (1.3.0) + activemodel + couchrest (~> 1.2.0) + json (~> 1.6) + couchrest (1.2.0) + mime-types (~> 1.15) + multi_json (~> 1.0) + rest-client (~> 1.6.1) + cucumber (1.2.1) + builder (>= 2.1.2) + diff-lcs (>= 1.1.3) + gherkin (~> 2.11.0) + json (>= 1.4.6) + data_objects (0.10.14) + addressable (~> 2.1) + datamapper (1.2.0) + dm-aggregates (~> 1.2.0) + dm-constraints (~> 1.2.0) + dm-core (~> 1.2.0) + dm-migrations (~> 1.2.0) + dm-serializer (~> 1.2.0) + dm-timestamps (~> 1.2.0) + dm-transactions (~> 1.2.0) + dm-types (~> 1.2.0) + dm-validations (~> 1.2.0) + diff-lcs (1.2.5) + dm-aggregates (1.2.0) + dm-core (~> 1.2.0) + dm-constraints (1.2.0) + dm-core (~> 1.2.0) + dm-core (1.2.1) + addressable (~> 2.3) + dm-do-adapter (1.2.0) + data_objects (~> 0.10.6) + dm-core (~> 1.2.0) + dm-migrations (1.2.0) + dm-core (~> 1.2.0) + dm-serializer (1.2.2) + dm-core (~> 1.2.0) + fastercsv (~> 1.5) + json (~> 1.6) + json_pure (~> 1.6) + multi_json (~> 1.0) + dm-sqlite-adapter (1.2.0) + dm-do-adapter (~> 1.2.0) + do_sqlite3 (~> 0.10.6) + dm-timestamps (1.2.0) + dm-core (~> 1.2.0) + dm-transactions (1.2.0) + dm-core (~> 1.2.0) + dm-types (1.2.2) + bcrypt-ruby (~> 3.0) + dm-core (~> 1.2.0) + fastercsv (~> 1.5) + json (~> 1.6) + multi_json (~> 1.0) + stringex (~> 1.4) + uuidtools (~> 2.1) + dm-validations (1.2.0) + dm-core (~> 1.2.0) + do_jdbc (0.10.14-java) + data_objects (= 0.10.14) + do_sqlite3 (0.10.14) + data_objects (= 0.10.14) + do_sqlite3 (0.10.14-java) + data_objects (= 0.10.14) + do_jdbc (= 0.10.14) + jdbc-sqlite3 (>= 3.5.8) + erubis (2.6.6) + abstract (>= 1.0.0) + faraday (0.9.0) + multipart-post (>= 1.2, < 3) + faraday_middleware (0.9.1) + faraday (>= 0.7.4, < 0.10) + fastercsv (1.5.5) + ffi (1.9.6) + ffi (1.9.6-java) + formatador (0.2.5) + gherkin (2.11.6) + json (>= 1.7.6) + gherkin (2.11.6-java) + json (>= 1.7.6) + guard (1.8.3) + formatador (>= 0.2.4) + listen (~> 1.3) + lumberjack (>= 1.0.2) + pry (>= 0.9.10) + thor (>= 0.14.6) + guard-rspec (2.5.4) + guard (>= 1.1) + rspec (~> 2.11) + httparty (0.13.3) + json (~> 1.8) + multi_xml (>= 0.5.2) + httpclient (2.5.3.3) + i18n (0.4.2) + jdbc-sqlite3 (3.8.10.1) + json (1.8.1) + json (1.8.1-java) + json_pure (1.8.1) + listen (1.3.1) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + rb-kqueue (>= 0.2) + lumberjack (1.0.9) + method_source (0.8.2) + mime-types (1.25.1) + mongo (1.11.1) + bson (= 1.11.1) + mongo_ext (0.19.3) + mongo_mapper (0.12.0) + activemodel (~> 3.0) + activesupport (~> 3.0) + plucky (~> 0.5.2) + mongoid (2.2.6) + activemodel (~> 3.0.0) + mongo (~> 1.3) + tzinfo (~> 0.3.22) + mongoid-tree (0.7.0) + mongoid (~> 2.0) + moped (1.5.2) + multi_json (1.2.0) + multi_xml (0.5.5) + multipart-post (2.0.0) + mysql (2.9.1) + mysql2 (0.3.18) + neo4j-community (2.1.5) + neo4j-core (3.0.8) + activesupport + faraday (~> 0.9.0) + faraday_middleware (~> 0.9.1) + httparty + httpclient + json + neo4j-community (~> 2.1.1) + net-http-persistent + os + zip + nest (1.1.2) + redis + net-http-persistent (2.9.4) + ohm (0.1.5) + nest (~> 1.0) + os (0.9.6) + pg (0.18.2) + plucky (0.5.2) + mongo (~> 1.5) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry (0.10.1-java) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + spoon (~> 0.0) + rack (1.2.8) + rack-mount (0.6.14) + rack (>= 1.0.0) + rack-test (0.5.7) + rack (>= 1.0) + railties (3.0.0) + actionpack (= 3.0.0) + activesupport (= 3.0.0) + rake (>= 0.8.4) + thor (~> 0.14.0) + rake (11.1.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) + rb-kqueue (0.2.3) + ffi (>= 0.5.0) + rdoc (4.1.2) + json (~> 1.4) + redis (3.1.0) + rest-client (1.6.8) + mime-types (~> 1.16) + rdoc (>= 2.4.2) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.8) + rspec-expectations (2.14.5) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.6) + rspec-rails (2.14.2) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + sequel (3.21.0) + slop (3.6.0) + spoon (0.0.4) + ffi + sqlite3 (1.3.10) + stringex (1.5.1) + thor (0.14.6) + tzinfo (0.3.48) + uuidtools (2.1.5) + zip (2.0.2) + +PLATFORMS + java + ruby + +DEPENDENCIES + activerecord + activerecord-mysql2-adapter + bson_ext + bundler + couch_potato + cucumber + database_cleaner! + datamapper + dm-migrations + dm-sqlite-adapter + guard-rspec + json_pure + mongo_ext + mongo_mapper + mongoid + mongoid-tree + moped + mysql (~> 2.9.1) + mysql2 + neo4j-core + ohm (~> 0.1.3) + pg + rake + rspec-rails (~> 2.14.2) + sequel (~> 3.21.0) + sqlite3 + tzinfo + +BUNDLED WITH + 1.14.6