Skip to content

Commit d32dbe8

Browse files
authored
Merge branch 'main' into remove-calculate-patch
2 parents f4224dc + b6fdbeb commit d32dbe8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+801
-561
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}
66

77
# TinyTDS
88
RUN apt-get -y install libc6-dev \
9-
&& wget http://www.freetds.org/files/stable/freetds-1.1.32.tar.gz \
10-
&& tar -xzf freetds-1.1.32.tar.gz \
11-
&& cd freetds-1.1.32 \
9+
&& wget http://www.freetds.org/files/stable/freetds-1.4.14.tar.gz \
10+
&& tar -xzf freetds-1.4.14.tar.gz \
11+
&& cd freetds-1.4.14 \
1212
&& ./configure --prefix=/usr/local --with-tdsver=7.3 \
1313
&& make \
1414
&& make install

.github/workflows/ci.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 18 * * *'
410

511
jobs:
612
test:
@@ -14,9 +20,9 @@ jobs:
1420
fail-fast: false
1521
matrix:
1622
ruby:
17-
- 3.0.6
18-
- 3.1.4
19-
- 3.2.2
23+
- 3.1.6
24+
- 3.2.4
25+
- 3.3.2
2026

2127
steps:
2228
- name: Checkout code

CHANGELOG.md

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,7 @@
1-
## v7.1.3
2-
3-
#### Fixed
4-
5-
- [#1152](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1152) Fix Composite Key Inserts with Triggers
6-
7-
## v7.1.2
8-
9-
#### Fixed
10-
11-
- [#1151](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1151) FROM subquery should work if order provided
12-
13-
## v7.1.1
14-
15-
#### Fixed
16-
17-
- [#1145](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1145) Ensure correct order of COLLATE and NOT NULL in CREATE TABLE statements
18-
- [#1144](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1144) Fix precision handling in time migration
19-
- [#1143](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1143) Fix precision handling for datetimeoffset migration
20-
21-
## v7.1.0
22-
23-
#### Added
24-
25-
- [#1141](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1141) Added support for check constraints.
26-
27-
## v7.1.0.rc2
28-
29-
#### Added
30-
31-
- [#1136](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1136) Prevent marking broken connections as verified
32-
- [#1138](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1138) Cache quoted names
33-
34-
## v7.1.0.rc1
35-
36-
#### Added
37-
38-
* Rails 7.1 Support
39-
40-
The adapter supports new Rails 7.1 features such as composite primary keys. See the
41-
[Rails 7.1 release notes](https://guides.rubyonrails.org/7_1_release_notes.html) for more information.
1+
## Unreleased
422

433
#### Changed
444

45-
* Configure Connection
46-
47-
If you require additional connection configuration you now need to call `super` within the `configure_connection`
48-
method so that the default configuration is also applied.
49-
50-
v7.1.x adapter:
51-
```ruby
52-
module ActiveRecord
53-
module ConnectionAdapters
54-
class SQLServerAdapter < AbstractAdapter
55-
def configure_connection
56-
super
57-
raw_connection_do "SET TEXTSIZE #{64.megabytes}"
58-
end
59-
end
60-
end
61-
end
62-
```
63-
64-
v7.0.x adapter:
65-
```ruby
66-
module ActiveRecord
67-
module ConnectionAdapters
68-
class SQLServerAdapter < AbstractAdapter
69-
def configure_connection
70-
raw_connection_do "SET TEXTSIZE #{64.megabytes}"
71-
end
72-
end
73-
end
74-
end
75-
```
5+
- [#1153](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1153) Only support Ruby v3.1+
766

77-
Please check [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/7-0-stable/CHANGELOG.md) for previous changes.
7+
Please check [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/7-1-stable/CHANGELOG.md) for previous changes.

Dockerfile.ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ WORKDIR $WORKDIR
99

1010
COPY . $WORKDIR
1111

12-
RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
12+
RUN RAILS_BRANCH=7-2-stable bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
1313

1414
CMD ["sh"]

Gemfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ gemspec
88

99
gem "bcrypt"
1010
gem "pg", ">= 0.18.0"
11-
gem "sqlite3", "~> 1.4"
11+
gem "sqlite3", ">= 1.6.6"
1212
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
1313
gem "benchmark-ips"
14-
gem "minitest", ">= 5.15.0", "< 5.16"
14+
gem "minitest", ">= 5.15.0"
1515
gem "msgpack", ">= 1.7.0"
1616

1717
if ENV["RAILS_SOURCE"]
1818
gemspec path: ENV["RAILS_SOURCE"]
19-
elsif ENV["RAILS_MAIN"]
20-
gem "rails", github: "rails/rails", branch: 'main'
19+
elsif ENV["RAILS_BRANCH"]
20+
gem "rails", github: "rails/rails", branch: ENV["RAILS_BRANCH"]
2121
else
2222
# Need to get rails source because the gem doesn't include tests
2323
version = ENV["RAILS_VERSION"] || begin

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ The SQL Server adapter for ActiveRecord using SQL Server 2012 or higher.
1111

1212
Interested in older versions? We follow a rational versioning policy that tracks Rails. That means that our 7.x version of the adapter is only for the latest 7.x 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

14-
| Adapter Version | Rails Version | Support | Branch |
15-
|-----------------|---------------|---------|--------------------------------------------------------------------------------------------------|
16-
| `7.1.3` | `7.1.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
17-
| `7.0.5.1` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
18-
| `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
19-
| `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
20-
| `5.2.1` | `5.2.x` | Ended | [5-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
21-
| `5.1.6` | `5.1.x` | Ended | [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
22-
| `4.2.18` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
23-
| `4.1.8` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
14+
| Adapter Version | Rails Version | Support | Branch |
15+
|-----------------|---------------|----------------|-------------------------------------------------------------------------------------------------|
16+
| Unreleased | `7.2.x` | In Development | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
17+
| `7.1.3` | `7.1.x` | Active | [7-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-1-stable) |
18+
| `7.0.5.1` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
19+
| `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
20+
| `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
21+
| `5.2.1` | `5.2.x` | Ended | [5-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-2-stable) |
22+
| `5.1.6` | `5.1.x` | Ended | [5-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/5-1-stable) |
23+
| `4.2.18` | `4.2.x` | Ended | [4-2-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-2-stable) |
24+
| `4.1.8` | `4.1.x` | Ended | [4-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/4-1-stable) |
2425

2526
For older versions, please check their stable branches.
2627

@@ -49,6 +50,10 @@ adapter.exclude_output_inserted_table_names['my_table_name'] = true
4950

5051
# Explicitly set the data type for the temporary key table.
5152
adapter.exclude_output_inserted_table_names['my_uuid_table_name'] = 'uniqueidentifier'
53+
54+
55+
# Explicitly set data types when data type is different for composite primary keys.
56+
adapter.exclude_output_inserted_table_names['my_composite_pk_table_name'] = { pk_col_one: "uniqueidentifier", pk_col_two: "int" }
5257
```
5358

5459

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.1.3
1+
7.2.0.beta2

activerecord-sqlserver-adapter.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
77
spec.platform = Gem::Platform::RUBY
88
spec.version = version
99

10-
spec.required_ruby_version = ">= 2.7.0"
10+
spec.required_ruby_version = ">= 3.1.0"
1111

1212
spec.license = "MIT"
1313
spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward", "Aidan Haran"]
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
2727
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
2828
spec.require_paths = ["lib"]
2929

30-
spec.add_dependency "activerecord", "~> 7.1.1"
30+
spec.add_dependency "activerecord", "~> 7.2.0.beta2"
3131
spec.add_dependency "tiny_tds"
3232
end

docker-compose.ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
ci:
66
environment:
77
- ACTIVERECORD_UNITTEST_HOST=sqlserver
8+
- RAILS_BRANCH=7-2-stable
89
build:
910
context: .
1011
dockerfile: Dockerfile.ci

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ module AttributeMethods
1010
private
1111

1212
def attributes_for_update(attribute_names)
13-
return super unless self.class.connection.adapter_name == "SQLServer"
13+
self.class.with_connection do |connection|
14+
return super(attribute_names) unless connection.sqlserver?
1415

15-
super.reject do |name|
16-
column = self.class.columns_hash[name]
17-
column && column.respond_to?(:is_identity?) && column.is_identity?
16+
super(attribute_names).reject do |name|
17+
column = self.class.columns_hash[name]
18+
column && column.respond_to?(:is_identity?) && column.is_identity?
19+
end
1820
end
1921
end
2022
end

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ module SQLServer
99
module CoreExt
1010
module Calculations
1111
def build_count_subquery(relation, column_name, distinct)
12-
return super unless klass.connection.adapter_name == "SQLServer"
13-
14-
super(relation.unscope(:order), column_name, distinct)
12+
klass.with_connection do |connection|
13+
relation = relation.unscope(:order) if connection.sqlserver?
14+
super(relation, column_name, distinct)
15+
end
1516
end
1617
end
1718
end

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ module Explain
99
SQLSERVER_STATEMENT_REGEXP = /N'(.+)', N'(.+)', (.+)/
1010

1111
def exec_explain(queries, options = [])
12-
return super unless connection.adapter_name == "SQLServer"
12+
with_connection do |connection|
13+
return super(queries, options) unless connection.sqlserver?
1314

14-
unprepared_queries = queries.map do |(sql, binds)|
15-
[unprepare_sqlserver_statement(sql, binds), binds]
15+
unprepared_queries = queries.map do |(sql, binds)|
16+
[unprepare_sqlserver_statement(sql, binds), binds]
17+
end
18+
19+
super(unprepared_queries, options)
1620
end
17-
super(unprepared_queries, options)
1821
end
1922

2023
private

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ module FinderMethods
1111
private
1212

1313
def construct_relation_for_exists(conditions)
14-
if klass.connection.sqlserver?
15-
_construct_relation_for_exists(conditions)
16-
else
17-
super
14+
klass.with_connection do |connection|
15+
if connection.sqlserver?
16+
_construct_relation_for_exists(conditions)
17+
else
18+
super
19+
end
1820
end
1921
end
2022

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ module SQLServer
88
module CoreExt
99
module LoaderQuery
1010
def load_records_for_keys(keys, &block)
11-
return super unless scope.connection.sqlserver?
11+
scope.with_connection do |connection|
12+
return super unless connection.sqlserver?
1213

13-
return [] if keys.empty?
14+
return [] if keys.empty?
1415

15-
if association_key_name.is_a?(Array)
16-
query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new }
16+
if association_key_name.is_a?(Array)
17+
query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new }
1718

18-
keys.each_with_object(query_constraints) do |values_set, constraints|
19-
association_key_name.zip(values_set).each do |key_name, value|
20-
constraints[key_name] << value
19+
keys.each_with_object(query_constraints) do |values_set, constraints|
20+
association_key_name.zip(values_set).each do |key_name, value|
21+
constraints[key_name] << value
22+
end
2123
end
22-
end
2324

24-
scope.where(query_constraints).load(&block)
25-
else
26-
keys.each_slice(in_clause_length).flat_map do |slice|
27-
scope.where(association_key_name => slice).load(&block).records
25+
scope.where(query_constraints).load(&block)
26+
else
27+
keys.each_slice(in_clause_length).flat_map do |slice|
28+
scope.where(association_key_name => slice).load(&block).records
29+
end
2830
end
2931
end
3032
end

0 commit comments

Comments
 (0)