Skip to content

Commit dc1baf7

Browse files
authored
Merge pull request #690 from rails-sqlserver/6-0-dev
Rails 6
2 parents 4712c92 + 17b2053 commit dc1baf7

26 files changed

+909
-299
lines changed

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ script:
1515
- docker-compose run ci
1616
matrix:
1717
include:
18-
- name: 2.3.8
19-
env: TARGET_VERSION=2.3.8
20-
- name: 2.4.10
21-
env: TARGET_VERSION=2.4.10
2218
- name: 2.5.8
2319
env: TARGET_VERSION=2.5.8
2420
- name: 2.6.6

Gemfile

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
# frozen_string_literal: true
2+
13
require 'openssl'
24
source 'https://rubygems.org'
5+
6+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
7+
38
gemspec
49

5-
gem 'sqlite3', '~> 1.3.6'
10+
gem "sqlite3", "~> 1.4"
11+
gem "pg", ">= 0.18.0"
12+
613
gem 'bcrypt'
714
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
815

@@ -13,7 +20,7 @@ end
1320
if ENV['RAILS_SOURCE']
1421
gemspec path: ENV['RAILS_SOURCE']
1522
else
16-
# Need to get rails source beacause the gem doesn't include tests
23+
# Need to get rails source because the gem doesn't include tests
1724
version = ENV['RAILS_VERSION'] || begin
1825
require 'net/http'
1926
require 'yaml'
@@ -33,7 +40,7 @@ else
3340
ver
3441
end
3542
end
36-
gem 'rails', git: "git://github.com/rails/rails.git", tag: "v#{version}"
43+
gem 'rails', github: "rails/rails", tag: "v#{version}"
3744
end
3845

3946
if ENV['AREL']

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
## About The Adapter
99

10-
The SQL Server adapter for ActiveRecord v5.2 using SQL Server 2012 or higher.
10+
The SQL Server adapter for ActiveRecord v6.0 using SQL Server 2012 or higher.
1111

12-
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.
12+
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.
1313

1414
#### Native Data Type Support
1515

1616
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.
1717

18-
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.
18+
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.
1919

2020
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.
2121

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.2.0
1+
6.0.0.rc1
+25-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
# -*- encoding: utf-8 -*-
2-
$:.push File.expand_path("../lib", __FILE__)
3-
require "active_record/connection_adapters/sqlserver/version"
1+
# frozen_string_literal: true
2+
3+
version = File.read(File.expand_path("VERSION", __dir__)).strip
44

55
Gem::Specification.new do |spec|
6-
spec.name = 'activerecord-sqlserver-adapter'
7-
spec.version = ActiveRecord::ConnectionAdapters::SQLServer::Version::VERSION
6+
spec.name = "activerecord-sqlserver-adapter"
87
spec.platform = Gem::Platform::RUBY
9-
spec.license = 'MIT'
10-
spec.authors = ['Ken Collins', 'Anna Carey', 'Will Bond', 'Murray Steele', 'Shawn Balestracci', 'Joe Rafaniello', 'Tom Ward']
11-
12-
spec.homepage = 'http://github.com/rails-sqlserver/activerecord-sqlserver-adapter'
13-
spec.summary = 'ActiveRecord SQL Server Adapter.'
14-
spec.description = 'ActiveRecord SQL Server Adapter. SQL Server 2012 and upward.'
8+
spec.version = version
9+
10+
spec.required_ruby_version = ">= 2.5.0"
11+
12+
spec.license = "MIT"
13+
spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward"]
14+
15+
spec.homepage = "http://github.com/rails-sqlserver/activerecord-sqlserver-adapter"
16+
spec.summary = "ActiveRecord SQL Server Adapter."
17+
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."
18+
19+
spec.metadata = {
20+
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
21+
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
22+
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
23+
}
24+
1525
spec.files = `git ls-files -z`.split("\x0")
1626
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
1727
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18-
spec.require_paths = ['lib']
19-
spec.add_dependency 'activerecord', '~> 5.2.0'
20-
spec.add_dependency 'tiny_tds'
28+
spec.require_paths = ["lib"]
29+
30+
spec.add_dependency "activerecord", "~> 6.0.0"
31+
spec.add_dependency "tiny_tds"
2132
end

appveyor.yml

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1+
image: Visual Studio 2017
2+
skip_tags: true
3+
clone_depth: 5
4+
build: off
5+
matrix:
6+
fast_finish: true
7+
8+
services:
9+
- mssql2014
10+
111
init:
212
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
313
- SET PATH=C:\MinGW\msys\1.0\bin;%PATH%
414
- SET RAKEOPT=-rdevkit
5-
- SET TINYTDS_VERSION=2.1.0
6-
clone_depth: 5
7-
skip_tags: true
8-
matrix:
9-
fast_finish: true
15+
- SET TINYTDS_VERSION=2.1.3.pre
16+
1017
install:
1118
- ps: Update-AppveyorBuild -Version "$(Get-Content $env:appveyor_build_folder\VERSION).$env:appveyor_build_number"
1219
- ruby --version
1320
- gem --version
1421
- bundle install
1522
- gem uninstall bcrypt
1623
- gem install bcrypt --platform=ruby
17-
build: off
24+
1825
test_script:
1926
- powershell -File "%APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.ps1"
2027
- timeout /t 4 /nobreak > NUL
21-
- ps: Start-Service 'MSSQL$SQL2014'
22-
- timeout /t 4 /nobreak > NUL
2328
- sqlcmd -S ".\SQL2014" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
2429
- bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2014"
25-
- ps: Stop-Service 'MSSQL$SQL2014'
26-
- ps: Start-Service 'MSSQL$SQL2012SP1'
27-
- timeout /t 4 /nobreak > NUL
28-
- sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -i %APPVEYOR_BUILD_FOLDER%\test\appveyor\dbsetup.sql
29-
- bundle exec rake test ACTIVERECORD_UNITTEST_DATASERVER="localhost\SQL2012SP1"
30+
3031
environment:
3132
CI_AZURE_HOST:
3233
secure: VChrioaIWkf9iuuaSs4cryiA4honrADgZqNC0++begg=
3334
CI_AZURE_PASS:
3435
secure: cSQp8sk4urJYvq0utpsK+r7J+snJ2wpcdp8RdXJfB+w=
3536
matrix:
36-
- ruby_version: "23-x64"
37-
- ruby_version: "23"
38-
- ruby_version: "22-x64"
39-
- ruby_version: "22"
37+
- ruby_version: "25-x64"
38+
- ruby_version: "25"
39+
- ruby_version: "26-x64"
40+
- ruby_version: "26"
41+
- ruby_version: "27-x64"
42+
- ruby_version: "27"

lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ module FinderMethods
1111

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

16+
if distinct_value && offset_value
1717
if select_values.present?
18-
relation = relation.order(*select_values)
18+
relation = order(*select_values).limit!(1)
1919
else
20-
relation = relation.except(:order)
20+
relation = except(:order).limit!(1)
2121
end
2222
else
2323
relation = except(:select, :distinct, :order)._select!(::ActiveRecord::FinderMethods::ONE_AS_ONE).limit!(1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "active_record/associations/preloader"
2+
3+
module ActiveRecord
4+
module ConnectionAdapters
5+
module SQLServer
6+
module CoreExt
7+
module Preloader
8+
private
9+
10+
def records_for(ids)
11+
ids.each_slice(in_clause_length).flat_map do |slice|
12+
scope.where(association_key_name => slice).load do |record|
13+
# Processing only the first owner
14+
# because the record is modified but not an owner
15+
owner = owners_by_key[convert_key(record[association_key_name])].first
16+
association = owner.association(reflection.name)
17+
association.set_inverse_instance(record)
18+
end.records
19+
end
20+
end
21+
22+
def in_clause_length
23+
10_000
24+
end
25+
end
26+
end
27+
end
28+
end
29+
end
30+
31+
ActiveSupport.on_load(:active_record) do
32+
mod = ActiveRecord::ConnectionAdapters::SQLServer::CoreExt::Preloader
33+
ActiveRecord::Associations::Preloader::Association.prepend(mod)
34+
end

lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module QueryMethods
99

1010
private
1111

12-
# Copy of original from Rails master. This patch can be removed when adapter supports Rails 6.
12+
# Copy of original from Rails master.
13+
# This patch can be removed when adapter supports Rails version greater than 6.0.2.2
1314
def table_name_matches?(from)
1415
table_name = Regexp.escape(table.name)
1516
quoted_table_name = Regexp.escape(connection.quote_table_name(table.name))

lib/active_record/connection_adapters/sqlserver/database_limits.rb

+7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ def table_alias_length
99
def column_name_length
1010
128
1111
end
12+
deprecate :column_name_length
1213

1314
def table_name_length
1415
128
1516
end
17+
deprecate :table_name_length
1618

1719
def index_name_length
1820
128
@@ -21,14 +23,17 @@ def index_name_length
2123
def columns_per_table
2224
1024
2325
end
26+
deprecate :columns_per_table
2427

2528
def indexes_per_table
2629
999
2730
end
31+
deprecate :indexes_per_table
2832

2933
def columns_per_multicolumn_index
3034
16
3135
end
36+
deprecate :columns_per_multicolumn_index
3237

3338
def in_clause_length
3439
10_000
@@ -37,10 +42,12 @@ def in_clause_length
3742
def sql_query_length
3843
65_536 * 4_096
3944
end
45+
deprecate :sql_query_length
4046

4147
def joins_per_query
4248
256
4349
end
50+
deprecate :joins_per_query
4451

4552
private
4653

0 commit comments

Comments
 (0)