activerecord-sqlserver-adapter 7.1.9 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +3 -3
- data/.github/workflows/ci.yml +11 -5
- data/CHANGELOG.md +5 -111
- data/Gemfile +4 -4
- data/README.md +40 -17
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +2 -2
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +6 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +6 -5
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +7 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +6 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +14 -12
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +49 -34
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +44 -46
- data/lib/active_record/connection_adapters/sqlserver/savepoints.rb +2 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +1 -2
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +2 -5
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +38 -32
- data/lib/arel/visitors/sqlserver.rb +22 -9
- data/test/cases/active_schema_test_sqlserver.rb +6 -6
- data/test/cases/adapter_test_sqlserver.rb +17 -18
- data/test/cases/coerced_tests.rb +262 -190
- data/test/cases/disconnected_test_sqlserver.rb +9 -3
- data/test/cases/eager_load_too_many_ids_test_sqlserver.rb +1 -1
- data/test/cases/enum_test_sqlserver.rb +1 -1
- data/test/cases/execute_procedure_test_sqlserver.rb +9 -5
- data/test/cases/helper_sqlserver.rb +11 -5
- data/test/cases/index_test_sqlserver.rb +8 -6
- data/test/cases/json_test_sqlserver.rb +1 -1
- data/test/cases/lateral_test_sqlserver.rb +2 -2
- data/test/cases/migration_test_sqlserver.rb +1 -1
- data/test/cases/optimizer_hints_test_sqlserver.rb +12 -12
- data/test/cases/pessimistic_locking_test_sqlserver.rb +8 -7
- data/test/cases/primary_keys_test_sqlserver.rb +2 -2
- data/test/cases/rake_test_sqlserver.rb +8 -4
- data/test/cases/schema_dumper_test_sqlserver.rb +4 -5
- data/test/cases/schema_test_sqlserver.rb +0 -4
- data/test/cases/showplan_test_sqlserver.rb +7 -7
- data/test/cases/specific_schema_test_sqlserver.rb +17 -13
- data/test/cases/view_test_sqlserver.rb +1 -9
- data/test/schema/sqlserver_specific_schema.rb +4 -4
- data/test/support/connection_reflection.rb +1 -1
- data/test/support/core_ext/query_cache.rb +2 -2
- data/test/support/query_assertions.rb +49 -0
- data/test/support/table_definition_sqlserver.rb +24 -0
- data/test/support/test_in_memory_oltp.rb +2 -2
- metadata +12 -13
- data/lib/active_record/sqlserver_base.rb +0 -13
- data/test/cases/scratchpad_test_sqlserver.rb +0 -8
- data/test/support/sql_counter_sqlserver.rb +0 -14
@@ -0,0 +1,49 @@
|
|
1
|
+
module ARTest
|
2
|
+
module SQLServer
|
3
|
+
module QueryAssertions
|
4
|
+
def assert_queries_count(count = nil, include_schema: false, &block)
|
5
|
+
ActiveRecord::Base.lease_connection.materialize_transactions
|
6
|
+
|
7
|
+
counter = ActiveRecord::Assertions::QueryAssertions::SQLCounter.new
|
8
|
+
ActiveSupport::Notifications.subscribed(counter, "sql.active_record") do
|
9
|
+
result = _assert_nothing_raised_or_warn("assert_queries_count", &block)
|
10
|
+
queries = include_schema ? counter.log_all : counter.log
|
11
|
+
|
12
|
+
# Start of monkey-patch
|
13
|
+
queries = include_release_savepoint_placeholder_queries(queries)
|
14
|
+
# End of monkey-patch
|
15
|
+
|
16
|
+
if count
|
17
|
+
assert_equal count, queries.size, "#{queries.size} instead of #{count} queries were executed. Queries: #{queries.join("\n\n")}"
|
18
|
+
else
|
19
|
+
assert_operator queries.size, :>=, 1, "1 or more queries expected, but none were executed.#{queries.empty? ? '' : "\nQueries:\n#{queries.join("\n")}"}"
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Rails tests expect a save-point to be created and released. SQL Server does not release
|
28
|
+
# save-points and so the number of queries will be off. This monkey patch adds a placeholder queries
|
29
|
+
# to replace the missing save-point releases.
|
30
|
+
def include_release_savepoint_placeholder_queries(queries)
|
31
|
+
grouped_queries = [[]]
|
32
|
+
|
33
|
+
queries.each do |query|
|
34
|
+
if query =~ /SAVE TRANSACTION \S+/
|
35
|
+
grouped_queries << [query]
|
36
|
+
else
|
37
|
+
grouped_queries.last << query
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
grouped_queries.each do |group|
|
42
|
+
group.append "/* release savepoint placeholder for testing */" if group.first =~ /SAVE TRANSACTION \S+/
|
43
|
+
end
|
44
|
+
|
45
|
+
grouped_queries.flatten
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
module SQLServer
|
6
|
+
class TableDefinition < ::ActiveRecord::ConnectionAdapters::TableDefinition
|
7
|
+
# SQL Server supports precision of 38 for decimal columns. In Rails the test schema includes a column
|
8
|
+
# with a precision of 55. This is a problem for SQL Server 2008. This method will override the default
|
9
|
+
# decimal method to limit the precision to 38 for the :atoms_in_universe column.
|
10
|
+
# See https://github.com/rails/rails/pull/51826/files#diff-2a57b61bbf9ee2c23938fc571d403799f68b4b530d65e2cde219a429bbf10af5L876
|
11
|
+
def decimal(*names, **options)
|
12
|
+
throw "This 'decimal' method should only be used in a test environment." unless defined?(ActiveSupport::TestCase)
|
13
|
+
|
14
|
+
names.each do |name|
|
15
|
+
options_for_name = options.dup
|
16
|
+
options_for_name[:precision] = 38 if name == :atoms_in_universe && options_for_name[:precision].to_i == 55
|
17
|
+
|
18
|
+
column(name, :decimal, **options_for_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -8,10 +8,10 @@ if ENV["IN_MEMORY_OLTP"]
|
|
8
8
|
|
9
9
|
ARTest.connect
|
10
10
|
|
11
|
-
if ActiveRecord::Base.
|
11
|
+
if ActiveRecord::Base.lease_connection.supports_in_memory_oltp?
|
12
12
|
puts "Configuring In-Memory OLTP..."
|
13
13
|
inmem_file = ARTest::SQLServer.test_root_sqlserver, "schema", "enable-in-memory-oltp.sql"
|
14
14
|
inmem_sql = File.read File.join(inmem_file)
|
15
|
-
ActiveRecord::Base.
|
15
|
+
ActiveRecord::Base.lease_connection.execute(inmem_sql)
|
16
16
|
end
|
17
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2024-
|
18
|
+
date: 2024-08-12 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -23,14 +23,14 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 7.
|
26
|
+
version: 7.2.0
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 7.
|
33
|
+
version: 7.2.0
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: tiny_tds
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,6 @@ files:
|
|
139
139
|
- lib/active_record/connection_adapters/sqlserver/version.rb
|
140
140
|
- lib/active_record/connection_adapters/sqlserver_adapter.rb
|
141
141
|
- lib/active_record/connection_adapters/sqlserver_column.rb
|
142
|
-
- lib/active_record/sqlserver_base.rb
|
143
142
|
- lib/active_record/tasks/sqlserver_database_tasks.rb
|
144
143
|
- lib/activerecord-sqlserver-adapter.rb
|
145
144
|
- lib/arel/visitors/sqlserver.rb
|
@@ -176,7 +175,6 @@ files:
|
|
176
175
|
- test/cases/rake_test_sqlserver.rb
|
177
176
|
- test/cases/schema_dumper_test_sqlserver.rb
|
178
177
|
- test/cases/schema_test_sqlserver.rb
|
179
|
-
- test/cases/scratchpad_test_sqlserver.rb
|
180
178
|
- test/cases/showplan_test_sqlserver.rb
|
181
179
|
- test/cases/specific_schema_test_sqlserver.rb
|
182
180
|
- test/cases/transaction_test_sqlserver.rb
|
@@ -232,16 +230,17 @@ files:
|
|
232
230
|
- test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic_associations.dump
|
233
231
|
- test/support/minitest_sqlserver.rb
|
234
232
|
- test/support/paths_sqlserver.rb
|
233
|
+
- test/support/query_assertions.rb
|
235
234
|
- test/support/rake_helpers.rb
|
236
|
-
- test/support/
|
235
|
+
- test/support/table_definition_sqlserver.rb
|
237
236
|
- test/support/test_in_memory_oltp.rb
|
238
237
|
homepage: http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
|
239
238
|
licenses:
|
240
239
|
- MIT
|
241
240
|
metadata:
|
242
241
|
bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
|
243
|
-
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.
|
244
|
-
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.
|
242
|
+
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.2.0/CHANGELOG.md
|
243
|
+
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.2.0
|
245
244
|
post_install_message:
|
246
245
|
rdoc_options: []
|
247
246
|
require_paths:
|
@@ -250,14 +249,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
249
|
requirements:
|
251
250
|
- - ">="
|
252
251
|
- !ruby/object:Gem::Version
|
253
|
-
version:
|
252
|
+
version: 3.1.0
|
254
253
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
254
|
requirements:
|
256
255
|
- - ">="
|
257
256
|
- !ruby/object:Gem::Version
|
258
257
|
version: '0'
|
259
258
|
requirements: []
|
260
|
-
rubygems_version: 3.5.
|
259
|
+
rubygems_version: 3.5.17
|
261
260
|
signing_key:
|
262
261
|
specification_version: 4
|
263
262
|
summary: ActiveRecord SQL Server Adapter.
|
@@ -294,7 +293,6 @@ test_files:
|
|
294
293
|
- test/cases/rake_test_sqlserver.rb
|
295
294
|
- test/cases/schema_dumper_test_sqlserver.rb
|
296
295
|
- test/cases/schema_test_sqlserver.rb
|
297
|
-
- test/cases/scratchpad_test_sqlserver.rb
|
298
296
|
- test/cases/showplan_test_sqlserver.rb
|
299
297
|
- test/cases/specific_schema_test_sqlserver.rb
|
300
298
|
- test/cases/transaction_test_sqlserver.rb
|
@@ -350,6 +348,7 @@ test_files:
|
|
350
348
|
- test/support/marshal_compatibility_fixtures/SQLServer/rails_7_1_topic_associations.dump
|
351
349
|
- test/support/minitest_sqlserver.rb
|
352
350
|
- test/support/paths_sqlserver.rb
|
351
|
+
- test/support/query_assertions.rb
|
353
352
|
- test/support/rake_helpers.rb
|
354
|
-
- test/support/
|
353
|
+
- test/support/table_definition_sqlserver.rb
|
355
354
|
- test/support/test_in_memory_oltp.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionHandling
|
5
|
-
def sqlserver_adapter_class
|
6
|
-
ConnectionAdapters::SQLServerAdapter
|
7
|
-
end
|
8
|
-
|
9
|
-
def sqlserver_connection(config) #:nodoc:
|
10
|
-
sqlserver_adapter_class.new(config)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ARTest
|
4
|
-
module SQLServer
|
5
|
-
module SqlCounterSqlserver
|
6
|
-
# Only return the log vs. log_all
|
7
|
-
def capture_sql_ss
|
8
|
-
ActiveRecord::SQLCounter.clear_log
|
9
|
-
yield
|
10
|
-
ActiveRecord::SQLCounter.log.dup
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|