Skip to content

Rails 6 support #690

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 102 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
f2233d7
Update ruby versions supported by Rails 6
wpolicarpo Mar 19, 2019
c43f5a9
Update activerecord version to 6
wpolicarpo Mar 19, 2019
027ecb3
Fix Rails 6 migrations
wpolicarpo Mar 20, 2019
6ead58b
Remove `table` and `column` which are no longer passed to `case_sensi…
kamipo Jan 11, 2019
2dc497b
Remove `id_value` argument which is no longer passed to `sql_for_insert`
kamipo Jan 11, 2019
1057a81
Fix constants missing in 6.0.0.rc1
auroranockert May 24, 2019
0f76d92
Fix concatenate syntax
auroranockert Jul 5, 2019
3be1cb8
Adapt to changed method signature in Rails 6.0.
robotex82 Nov 4, 2019
848e668
Merge pull request #703 from jensnockert/concat-sql-syntax
wpolicarpo Feb 25, 2020
21b98bb
Merge branch 'master' into 6-0-dev
wpolicarpo Mar 25, 2020
f91b626
Merge pull request #711 from robotex82/feature/rails-6-0
wpolicarpo Mar 25, 2020
915fd79
Update version Rails 6.0.2.2
aidanharan Mar 25, 2020
98505fe
Merge pull request #747 from aidanharan/update-to-rails-6
wpolicarpo Mar 26, 2020
e24ec67
Fix method signature
aidanharan Mar 26, 2020
7a1552d
Updated comment
aidanharan Mar 26, 2020
3106e81
Merge pull request #748 from aidanharan/fix-rake-test
wpolicarpo Mar 30, 2020
ee65b45
Fix for table from statement join
aidanharan Mar 30, 2020
ae1bccd
Merge pull request #750 from aidanharan/fix-table-from-statement-join
wpolicarpo Mar 31, 2020
a25eddb
Sanitize forbidden attributes for exists relation
aidanharan Mar 31, 2020
ef99277
Merge pull request #751 from aidanharan/exists-relation-sanitize-forb…
wpolicarpo Mar 31, 2020
2e00595
Added method to get database version
aidanharan Apr 1, 2020
9841e46
Merge pull request #752 from aidanharan/database-version-fix
wpolicarpo Apr 1, 2020
400314a
Use abstract controllers combine multi statements method
aidanharan Apr 1, 2020
d173241
Merge pull request #754 from aidanharan/use-default-combine-multi-sta…
wpolicarpo Apr 1, 2020
ebfd121
Add/remove foreign keys when truncating during tests
aidanharan Apr 2, 2020
694c1e5
Use https protocol for Github
aidanharan Apr 2, 2020
b10e2b2
Merge pull request #756 from aidanharan/gemfile-github-https
wpolicarpo Apr 2, 2020
3d3faf8
Subqueries cannot include ordering unless TOP/LIMIT also specified
aidanharan Apr 6, 2020
1300331
Merge pull request #758 from aidanharan/in-clause-no-ordering
wpolicarpo Apr 7, 2020
8b48e5f
Merge pull request #755 from aidanharan/fix-truncation-tests
wpolicarpo Apr 7, 2020
2360741
Store table name on columns
aidanharan Apr 7, 2020
579730f
Merge pull request #759 from aidanharan/table-name-required-on-column…
wpolicarpo Apr 8, 2020
ca78a17
Fixed migration test
aidanharan Apr 8, 2020
b73de76
Updated unsafe raw sql tests to match tests in Rails 6
aidanharan Apr 8, 2020
f89a893
Merge pull request #761 from aidanharan/fix-migration-context-initial…
wpolicarpo Apr 8, 2020
9200fa9
Fix missing parent class
aidanharan Apr 9, 2020
1ae4253
Merge branch 'master' into 6-0-dev
wpolicarpo Apr 9, 2020
dd698f1
Merge pull request #764 from aidanharan/fix-coerced-tests
wpolicarpo Apr 9, 2020
7ee2122
Fix sanitization matchers
aidanharan Apr 9, 2020
5185b3c
Merge pull request #762 from aidanharan/unsafe-raw-sql-fix-tests
wpolicarpo Apr 14, 2020
e872d91
Changed query cached test
aidanharan Apr 14, 2020
d4340fa
Added method deprecations
aidanharan Apr 14, 2020
04fb60e
Merge pull request #767 from aidanharan/query-cache-types-reset
wpolicarpo Apr 14, 2020
ddc6c60
Merge pull request #768 from aidanharan/database-limits-deprecations
wpolicarpo Apr 14, 2020
b3492a8
Fixed tests
aidanharan Apr 15, 2020
16c3949
Merge pull request #771 from aidanharan/fully-qualified-identifier-tests
wpolicarpo Apr 15, 2020
b9b5178
Add ability to block writes to a database
aidanharan Apr 14, 2020
841ed90
Merge pull request #769 from aidanharan/readonly-mode
wpolicarpo Apr 15, 2020
355fb34
Moved coerced tests to correct classes
aidanharan Apr 15, 2020
88596fc
Coerce tests that require changing identity column
aidanharan Apr 15, 2020
7589e90
Fix showplan test
aidanharan Apr 15, 2020
fa7cdad
Merge pull request #772 from aidanharan/update-all-tests
wpolicarpo Apr 15, 2020
33c1c38
Merge pull request #773 from aidanharan/show-plantest
wpolicarpo Apr 15, 2020
86506cf
Install PostgreSQL gem
aidanharan Apr 15, 2020
3aa7abb
Skip test if database case insensitive
aidanharan Apr 20, 2020
61e6833
Merge pull request #777 from aidanharan/skip-case-sensitive-test
wpolicarpo Apr 20, 2020
54ce1b6
Fix asserted SQL
aidanharan Apr 20, 2020
e67f033
Merge pull request #778 from aidanharan/limit-one-row-sql
wpolicarpo Apr 21, 2020
c256c33
Wrap original test with code to add/remove index
aidanharan Apr 16, 2020
6dcc1b7
Merge pull request #776 from aidanharan/unique-index-fixes
wpolicarpo Apr 21, 2020
420153a
added if_not_exists option with workaround
YehudaGold Apr 22, 2020
c96d91d
Coerce test as adapter doesnt use statement cache
aidanharan Apr 23, 2020
764aa3d
Updated test to match test in Rails
aidanharan Apr 23, 2020
ab38770
Merge pull request #781 from aidanharan/bind-parameter-statement-cache
wpolicarpo Apr 24, 2020
bf473c4
Merge pull request #779 from YehudaGold/add-if-not-exists
wpolicarpo Apr 24, 2020
c319b82
Merge branch 'master' into 6-0-dev
wpolicarpo Apr 24, 2020
4b30617
fix update_attributes deprecated method usage
YehudaGold Apr 24, 2020
cfc41e9
Merge pull request #774 from aidanharan/postgresql-gem
wpolicarpo Apr 24, 2020
ef35bcc
Merge pull request #784 from YehudaGold/update-attributes-deprecated
wpolicarpo Apr 24, 2020
20f91a8
Merge pull request #782 from aidanharan/update-query-cache-test
wpolicarpo Apr 24, 2020
3706bc5
fixes test_default_decimal_number to assert against number.like other…
YehudaGold Apr 26, 2020
4d3255d
Merge pull request #785 from YehudaGold/coerce-default-decimal-test
wpolicarpo Apr 26, 2020
0f92db2
Fix `EagerLoadingTooManyIdsTest#test_preloading_too_many_ids`
kamipo Apr 27, 2020
7026eb5
Merge pull request #786 from kamipo/fix_test_preloading_too_many_ids
wpolicarpo Apr 27, 2020
9061a7a
Raise ActiveRecord::InvalidForeignKey for foreign-key constraint viol…
aidanharan Apr 27, 2020
0c35cc2
Merge pull request #787 from aidanharan/foreign-key-violation-delete
wpolicarpo Apr 27, 2020
6aa992d
Coerce tests as SQL Server does not return string value for updated_at
aidanharan Apr 28, 2020
14d4619
Rails 6: Clean coerced tests (#793)
YehudaGold Apr 29, 2020
0fac1db
Merge pull request #790 from aidanharan/cache-key-no-string-value
wpolicarpo Apr 29, 2020
0f9779e
Rails 6: Coerce time no precision test (#791)
aidanharan Apr 29, 2020
967c93e
Take and first use implicit ordering on identifier column (#789)
aidanharan Apr 29, 2020
a07552c
Rails 6: Support lazy transactions (#780)
aidanharan Apr 29, 2020
9b71375
Coerce test an empty transaction does not raise if preventing writes.…
YehudaGold Apr 29, 2020
fe348fa
Rails 6: add database_exists? (#796)
YehudaGold Apr 30, 2020
d16d958
Rails 6: Use same sqlite3 and pg versions as Rails 6.0.2.2 (#794)
aidanharan Apr 30, 2020
3eba185
Updates for bulk insert/upsert (#795)
aidanharan Apr 30, 2020
6bdfc09
Fix randomly failing test (#797)
aidanharan Apr 30, 2020
66db048
Rails 6: Coerce eagerload too many IDs test (#798)
aidanharan May 5, 2020
ee8af23
Fix randomly failing tests by loading models schema
aidanharan May 6, 2020
b1e02f9
Rails 6: Log subscriber workaround (#799)
aidanharan May 6, 2020
8ab0006
Merge pull request #800 from aidanharan/random-failing-test-load-schema
wpolicarpo May 6, 2020
a72acbc
Add metadata to the gemspec
wpolicarpo May 7, 2020
6a6650b
Update README for Rails 6
wpolicarpo May 7, 2020
708570d
Workaround for randomly failing test
aidanharan May 7, 2020
0c8cdc8
Coerce predicate builder tests
aidanharan May 7, 2020
d18f933
Merge pull request #802 from aidanharan/predicate-build-coerced-tests
wpolicarpo May 7, 2020
6064f93
Merge pull request #801 from aidanharan/schema-randomly-failing-test
wpolicarpo May 7, 2020
499a6c7
Remove invalid order from FROM subquery
aidanharan May 7, 2020
14a94fd
Merge pull request #803 from aidanharan/remove-ordering-frm-subqueries
wpolicarpo May 7, 2020
01a7946
Update appveyor matrix
wpolicarpo May 7, 2020
e72371f
Update tiny_tds version for appveyor
wpolicarpo May 7, 2020
17b2053
Cleanup appveyor configuration
wpolicarpo May 7, 2020
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
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ script:
- docker-compose run ci
matrix:
include:
- name: 2.3.8
env: TARGET_VERSION=2.3.8
- name: 2.4.10
env: TARGET_VERSION=2.4.10
- name: 2.5.8
env: TARGET_VERSION=2.5.8
- name: 2.6.6
Expand Down
13 changes: 10 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# frozen_string_literal: true

require 'openssl'
source 'https://rubygems.org'

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec

gem 'sqlite3', '~> 1.3.6'
gem "sqlite3", "~> 1.4"
gem "pg", ">= 0.18.0"

gem 'bcrypt'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Expand All @@ -13,7 +20,7 @@ end
if ENV['RAILS_SOURCE']
gemspec path: ENV['RAILS_SOURCE']
else
# Need to get rails source beacause the gem doesn't include tests
# Need to get rails source because the gem doesn't include tests
version = ENV['RAILS_VERSION'] || begin
require 'net/http'
require 'yaml'
Expand All @@ -33,7 +40,7 @@ else
ver
end
end
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
gem 'rails', github: "rails/rails", tag: "v#{version}"
end

if ENV['AREL']
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

## About The Adapter

The SQL Server adapter for ActiveRecord v5.2 using SQL Server 2012 or higher.
The SQL Server adapter for ActiveRecord v6.0 using SQL Server 2012 or higher.

Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 5.1.x version of the adapter is only for the latest 5.1 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 5.2.x version of the adapter is only for the latest 5.2 version of Rails. If you need the adapter for SQL Server 2008 or 2005, you are still in the right spot. Just install the latest 3.2.x to 4.1.x version of the adapter that matches your Rails version. We also have stable branches for each major/minor release of ActiveRecord.

#### Native Data Type Support

We support every data type supported by FreeTDS. All simplified Rails types in migrations will coorespond to a matching SQL Server national (unicode) data type. Always check the `initialize_native_database_types` [(here)](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/active_record/connection_adapters/sqlserver/schema_statements.rb) for an updated list.

The following types (date, datetime2, datetimeoffset, time) all require TDS version 7.3 with TinyTDS. We recommend using FreeTDS 1.0 or higher which default to using `TDSVER` to "7.3". The adapter also sets TinyTDS's `tds_version` to this as well if non is specified.
The following types (`date`, `datetime2`, `datetimeoffset`, `time`) all require TDS version 7.3 with TinyTDS. We recommend using FreeTDS 1.0 or higher which default to using `TDSVER` to "7.3". The adapter also sets TinyTDS's `tds_version` to this as well if non is specified.

The Rails v5 adapter supports ActiveRecord's `datetime_with_precision` setting. This means that passing `:precision` to a datetime column is supported. Using a pecision with the `:datetime` type will signal the adapter to use the `datetime2` type under the hood.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.0
6.0.0.rc1
39 changes: 25 additions & 14 deletions activerecord-sqlserver-adapter.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "active_record/connection_adapters/sqlserver/version"
# frozen_string_literal: true

version = File.read(File.expand_path("VERSION", __dir__)).strip

Gem::Specification.new do |spec|
spec.name = 'activerecord-sqlserver-adapter'
spec.version = ActiveRecord::ConnectionAdapters::SQLServer::Version::VERSION
spec.name = "activerecord-sqlserver-adapter"
spec.platform = Gem::Platform::RUBY
spec.license = 'MIT'
spec.authors = ['Ken Collins', 'Anna Carey', 'Will Bond', 'Murray Steele', 'Shawn Balestracci', 'Joe Rafaniello', 'Tom Ward']
spec.email = ['ken@metaskills.net', 'will@wbond.net']
spec.homepage = 'http://github.com/rails-sqlserver/activerecord-sqlserver-adapter'
spec.summary = 'ActiveRecord SQL Server Adapter.'
spec.description = 'ActiveRecord SQL Server Adapter. SQL Server 2012 and upward.'
spec.version = version

spec.required_ruby_version = ">= 2.5.0"

spec.license = "MIT"
spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward"]
spec.email = ["ken@metaskills.net", "will@wbond.net"]
spec.homepage = "http://github.com/rails-sqlserver/activerecord-sqlserver-adapter"
spec.summary = "ActiveRecord SQL Server Adapter."
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."

spec.metadata = {
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
}

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.add_dependency 'activerecord', '~> 5.2.0'
spec.add_dependency 'tiny_tds'
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", "~> 6.0.0"
spec.add_dependency "tiny_tds"
end
37 changes: 20 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
image: Visual Studio 2017
skip_tags: true
clone_depth: 5
build: off
matrix:
fast_finish: true

services:
- mssql2014

init:
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
- SET PATH=C:\MinGW\msys\1.0\bin;%PATH%
- SET RAKEOPT=-rdevkit
- SET TINYTDS_VERSION=2.1.0
clone_depth: 5
skip_tags: true
matrix:
fast_finish: true
- SET TINYTDS_VERSION=2.1.3.pre

install:
- ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
- ruby --version
- gem --version
- bundle install
- gem uninstall bcrypt
- gem install bcrypt --platform=ruby
build: off

test_script:
- powershell -File "%APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.ps1"
- timeout /t 4 /nobreak > NUL
- ps: Start-Service 'MSSQL$SQL2014'
- timeout /t 4 /nobreak > NUL
- sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
- bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2014"
- ps: Stop-Service 'MSSQL$SQL2014'
- ps: Start-Service 'MSSQL$SQL2012SP1'
- timeout /t 4 /nobreak > NUL
- sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
- bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2012SP1"

environment:
CI_AZURE_HOST:
secure: VChrioaIWkf9iuuaSs4cryiA4honrADgZqNC0++begg=
CI_AZURE_PASS:
secure: cSQp8sk4urJYvq0utpsK+r7J+snJ2wpcdp8RdXJfB+w=
matrix:
- ruby_version: "23-x64"
- ruby_version: "23"
- ruby_version: "22-x64"
- ruby_version: "22"
- ruby_version: "25-x64"
- ruby_version: "25"
- ruby_version: "26-x64"
- ruby_version: "26"
- ruby_version: "27-x64"
- ruby_version: "27"
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module FinderMethods

# Same as original except we order by values in distinct select if present.
def construct_relation_for_exists(conditions)
if distinct_value && offset_value
relation = limit!(1)
conditions = sanitize_forbidden_attributes(conditions)

if distinct_value && offset_value
if select_values.present?
relation = relation.order(*select_values)
relation = order(*select_values).limit!(1)
else
relation = relation.except(:order)
relation = except(:order).limit!(1)
end
else
relation = except(:select, :distinct, :order)._select!(::ActiveRecord::FinderMethods::ONE_AS_ONE).limit!(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "active_record/associations/preloader"

module ActiveRecord
module ConnectionAdapters
module SQLServer
module CoreExt
module Preloader
private

def records_for(ids)
ids.each_slice(in_clause_length).flat_map do |slice|
scope.where(association_key_name => slice).load do |record|
# Processing only the first owner
# because the record is modified but not an owner
owner = owners_by_key[convert_key(record[association_key_name])].first
association = owner.association(reflection.name)
association.set_inverse_instance(record)
end.records
end
end

def in_clause_length
10_000
end
end
end
end
end
end

ActiveSupport.on_load(:active_record) do
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Preloader
ActiveRecord::Associations::Preloader::Association.prepend(mod)
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module QueryMethods

private

# Copy of original from Rails master. This patch can be removed when adapter supports Rails 6.
# Copy of original from Rails master.
# This patch can be removed when adapter supports Rails version greater than 6.0.2.2
def table_name_matches?(from)
table_name = Regexp.escape(table.name)
quoted_table_name = Regexp.escape(connection.quote_table_name(table.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ def table_alias_length
def column_name_length
128
end
deprecate :column_name_length

def table_name_length
128
end
deprecate :table_name_length

def index_name_length
128
Expand All @@ -21,14 +23,17 @@ def index_name_length
def columns_per_table
1024
end
deprecate :columns_per_table

def indexes_per_table
999
end
deprecate :indexes_per_table

def columns_per_multicolumn_index
16
end
deprecate :columns_per_multicolumn_index

def in_clause_length
10_000
Expand All @@ -37,10 +42,12 @@ def in_clause_length
def sql_query_length
65_536 * 4_096
end
deprecate :sql_query_length

def joins_per_query
256
end
deprecate :joins_per_query

private

Expand Down
Loading