Skip to content

Enable postgresql ci tests #79

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

Merged
merged 3 commits into from
Mar 10, 2021
Merged
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
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ branch:
# https://docs.travis-ci.com/user/database-setup/#mysql
services:
- mysql
- postgresql

rvm:
- 2.3
- 2.4
Expand All @@ -19,6 +21,7 @@ gemfile:
env:
- DB_ADAPTER=sqlite
- DB_ADAPTER=mysql
- DB_ADAPTER=postgresql
matrix:
allow_failures:
- rvm: ruby-head
Expand All @@ -29,30 +32,45 @@ matrix:
- rvm: 2.2
gemfile: gemfiles/rails_3.gemfile
env: DB_ADAPTER=mysql
- rvm: 2.2
gemfile: gemfiles/rails_3.gemfile
env: DB_ADAPTER=postgresql
- rvm: 2.2
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=sqlite
- rvm: 2.2
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=mysql
- rvm: 2.2
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=postgresql
- rvm: 2.3
gemfile: gemfiles/rails_3.gemfile
env: DB_ADAPTER=sqlite
- rvm: 2.3
gemfile: gemfiles/rails_3.gemfile
env: DB_ADAPTER=mysql
- rvm: 2.3
gemfile: gemfiles/rails_3.gemfile
env: DB_ADAPTER=postgresql
- rvm: 2.3
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=sqlite
- rvm: 2.3
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=mysql
- rvm: 2.3
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=postgresql
- rvm: 2.4
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=sqlite
- rvm: 2.4
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=mysql
- rvm: 2.4
gemfile: gemfiles/rails_4.gemfile
env: DB_ADAPTER=postgresql
exclude:
- rvm: 2.3
gemfile: gemfiles/rails_6.gemfile
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
appraise "rails-3" do
gem "mysql2", "~> 0.3.10"
gem "pg", "~> 0.11"
gem "rails", "~> 3"
gem "sqlite3", "~> 1.3.6"
gem "test-unit", "~> 3.0"
end

appraise "rails-4" do
gem "mysql2"
gem "pg", "~> 0.15"
gem "rails", "~> 4"
gem "sqlite3", "~> 1.3.6"
end

appraise "rails-5" do
gem "mysql2"
gem "pg"
gem "rails", "~> 5"
gem "sqlite3"
end

appraise "rails-6" do
gem "mysql2"
gem "pg"
gem "rails", "~> 6"
gem "sqlite3"
end
92 changes: 0 additions & 92 deletions FIXME.md

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ ruby / rails | `~>3` | `~>4` | `~>5` | `~>6`
2.6 | no | no | yes | yes
2.7 | no | no | yes | yes

> Any extension to the test suite to validate other db adapter than sqlite is welcome.
The adapters covered in the CI are:
* sqlite
* mysql
* postgresql


## License

Expand Down
12 changes: 9 additions & 3 deletions ci/000-prepare-database
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
set -euo pipefail

export DB_ADAPTER=${DB_ADAPTER:-mysql}
if [[ "${DB_ADAPTER}" == "mysql" ]]; then
mysql -e 'CREATE DATABASE bulk_insert_test;'
fi

case $DB_ADAPTER in
mysql)
mysql -e 'CREATE DATABASE bulk_insert_test;'
;;
postgresql)
psql -c 'create database bulk_insert_test;' -U postgres
;;
esac

cd test/dummy
bundle exec rake db:test:load
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem "minitest"
gem "rails", "~> 3"
gem "sqlite3", "~> 1.3.6"
gem "mysql2", "~> 0.3.10"
gem "pg", "~> 0.11"
gem "test-unit", "~> 3.0"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem "minitest"
gem "rails", "~> 4"
gem "sqlite3", "~> 1.3.6"
gem "mysql2"
gem "pg", "~> 0.15"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem "minitest"
gem "rails", "~> 5"
gem "sqlite3"
gem "mysql2"
gem "pg"

gemspec path: "../"
1 change: 1 addition & 0 deletions gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem "minitest"
gem "rails", "~> 6"
gem "sqlite3"
gem "mysql2"
gem "pg"

gemspec path: "../"
28 changes: 24 additions & 4 deletions test/bulk_insert/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,12 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
pgsql_worker.add ["Yo", 15, false, nil, nil]

assert_statement_adapter pgsql_worker, 'BulkInsert::StatementAdapters::PostgreSQLAdapter'
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"

if ActiveRecord::VERSION::STRING >= "5.0.0"
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,FALSE,NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"
else
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"
end
end
end

Expand All @@ -392,7 +397,12 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
pgsql_worker.add ["Yo", 15, false, nil, nil]

assert_statement_adapter pgsql_worker, 'BulkInsert::StatementAdapters::PostgreSQLAdapter'
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') RETURNING id"

if ActiveRecord::VERSION::STRING >= "5.0.0"
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,FALSE,NULL,NULL,'chartreuse') RETURNING id"
else
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') RETURNING id"
end
end
end

Expand All @@ -412,7 +422,12 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
pgsql_worker.add ["Yo", 15, false, nil, nil]

assert_statement_adapter pgsql_worker, 'BulkInsert::StatementAdapters::PostgreSQLAdapter'
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') ON CONFLICT(greeting, age, happy) DO UPDATE SET greeting=EXCLUDED.greeting, age=EXCLUDED.age, happy=EXCLUDED.happy, created_at=EXCLUDED.created_at, updated_at=EXCLUDED.updated_at, color=EXCLUDED.color RETURNING id"

if ActiveRecord::VERSION::STRING >= "5.0.0"
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,FALSE,NULL,NULL,'chartreuse') ON CONFLICT(greeting, age, happy) DO UPDATE SET greeting=EXCLUDED.greeting, age=EXCLUDED.age, happy=EXCLUDED.happy, created_at=EXCLUDED.created_at, updated_at=EXCLUDED.updated_at, color=EXCLUDED.color RETURNING id"
else
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON CONFLICT(greeting, age, happy) DO UPDATE SET greeting=EXCLUDED.greeting, age=EXCLUDED.age, happy=EXCLUDED.happy, created_at=EXCLUDED.created_at, updated_at=EXCLUDED.updated_at, color=EXCLUDED.color RETURNING id"
end
end
end

Expand All @@ -432,7 +447,12 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
pgsql_worker.add ["Yo", 15, false, nil, nil]

assert_statement_adapter pgsql_worker, 'BulkInsert::StatementAdapters::PostgreSQLAdapter'
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"

if ActiveRecord::VERSION::STRING >= "5.0.0"
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,FALSE,NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"
else
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,'f',NULL,NULL,'chartreuse') ON CONFLICT DO NOTHING RETURNING id"
end
end
end

Expand Down
48 changes: 42 additions & 6 deletions test/connection_mocks.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module ConnectionMocks
DOUBLE_QUOTE_PROC = Proc.new do |value, *_column|
DOUBLE_QUOTE_PROC = Proc.new do |value, *_column|
return value unless value.is_a? String
"\"#{value}\""
end

BACKTICK_QUOTE_PROC = Proc.new do |value, *_column|
BACKTICK_QUOTE_PROC = Proc.new do |value, *_column|
return value unless value.is_a? String
'`' + value + '`'
end

MYSQL_VALUE_QUOTE_PROC = Proc.new do |value, *_column|
BOOLEAN_VALUE_QUOTE_PROC = Proc.new do |value, *_column|
case value
when String
"'" + value + "'"
Expand All @@ -24,7 +24,22 @@ module ConnectionMocks
end
end

DEFAULT_VALUE_QUOTE_PROC = Proc.new do |value, *_column|
LITERAL_BOOLEAN_VALUE_QUOTE_PROC = Proc.new do |value, *_column|
case value
when String
"'" + value + "'"
when TrueClass
"'t'"
when FalseClass
"'f'"
when NilClass
'NULL'
else
value
end
end

DEFAULT_VALUE_QUOTE_PROC = Proc.new do |value, *_column|
case value
when String
"'" + value + "'"
Expand Down Expand Up @@ -61,10 +76,15 @@ def stub_connection_if_needed(connection, adapter_name)
yield
else
common_mocks(connection, adapter_name) do
if adapter_name =~ /^mysql/i
case adapter_name
when /^mysql/i
mock_mysql_connection(connection, adapter_name) do
yield
end
when /\APost(?:greSQL|GIS)/i
mock_postgresql_connection(connection, adapter_name) do
yield
end
else
connection.stub :quote_table_name, DOUBLE_QUOTE_PROC do
connection.stub :quote_column_name, DOUBLE_QUOTE_PROC do
Expand Down Expand Up @@ -95,10 +115,26 @@ def common_mocks(connection, adapter_name)
def mock_mysql_connection(connection, adapter_name)
connection.stub :quote_table_name, BACKTICK_QUOTE_PROC do
connection.stub :quote_column_name, BACKTICK_QUOTE_PROC do
connection.stub :quote, MYSQL_VALUE_QUOTE_PROC do
connection.stub :quote, BOOLEAN_VALUE_QUOTE_PROC do
yield
end
end
end
end

def mock_postgresql_connection(connection, adapter_name)
connection.stub :quote_table_name, DOUBLE_QUOTE_PROC do
connection.stub :quote_column_name, DOUBLE_QUOTE_PROC do
if ActiveRecord::VERSION::STRING >= "5.0.0"
connection.stub :quote, BOOLEAN_VALUE_QUOTE_PROC do
yield
end
else
connection.stub :quote, LITERAL_BOOLEAN_VALUE_QUOTE_PROC do
yield
end
end
end
end
end
end
Loading