activerecord-sqlserver-adapter 7.1.10 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +3 -3
  3. data/.github/workflows/ci.yml +11 -5
  4. data/CHANGELOG.md +5 -117
  5. data/Gemfile +4 -4
  6. data/README.md +40 -17
  7. data/VERSION +1 -1
  8. data/activerecord-sqlserver-adapter.gemspec +2 -2
  9. data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +6 -4
  10. data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +6 -5
  11. data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +7 -4
  12. data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +6 -4
  13. data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +14 -12
  14. data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +49 -34
  15. data/lib/active_record/connection_adapters/sqlserver/quoting.rb +44 -46
  16. data/lib/active_record/connection_adapters/sqlserver/savepoints.rb +2 -0
  17. data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +4 -9
  18. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +2 -5
  19. data/lib/active_record/tasks/sqlserver_database_tasks.rb +38 -32
  20. data/lib/arel/visitors/sqlserver.rb +22 -9
  21. data/test/cases/active_schema_test_sqlserver.rb +6 -6
  22. data/test/cases/adapter_test_sqlserver.rb +17 -27
  23. data/test/cases/coerced_tests.rb +262 -190
  24. data/test/cases/disconnected_test_sqlserver.rb +9 -3
  25. data/test/cases/eager_load_too_many_ids_test_sqlserver.rb +1 -1
  26. data/test/cases/enum_test_sqlserver.rb +1 -1
  27. data/test/cases/execute_procedure_test_sqlserver.rb +9 -5
  28. data/test/cases/helper_sqlserver.rb +11 -5
  29. data/test/cases/index_test_sqlserver.rb +8 -6
  30. data/test/cases/json_test_sqlserver.rb +1 -1
  31. data/test/cases/lateral_test_sqlserver.rb +2 -2
  32. data/test/cases/migration_test_sqlserver.rb +1 -1
  33. data/test/cases/optimizer_hints_test_sqlserver.rb +12 -12
  34. data/test/cases/pessimistic_locking_test_sqlserver.rb +8 -7
  35. data/test/cases/primary_keys_test_sqlserver.rb +2 -2
  36. data/test/cases/rake_test_sqlserver.rb +8 -4
  37. data/test/cases/schema_dumper_test_sqlserver.rb +4 -5
  38. data/test/cases/schema_test_sqlserver.rb +0 -4
  39. data/test/cases/showplan_test_sqlserver.rb +7 -7
  40. data/test/cases/specific_schema_test_sqlserver.rb +17 -13
  41. data/test/cases/view_test_sqlserver.rb +1 -9
  42. data/test/schema/sqlserver_specific_schema.rb +4 -4
  43. data/test/support/connection_reflection.rb +1 -1
  44. data/test/support/core_ext/query_cache.rb +2 -2
  45. data/test/support/query_assertions.rb +49 -0
  46. data/test/support/table_definition_sqlserver.rb +24 -0
  47. data/test/support/test_in_memory_oltp.rb +2 -2
  48. metadata +12 -13
  49. data/lib/active_record/sqlserver_base.rb +0 -13
  50. data/test/cases/scratchpad_test_sqlserver.rb +0 -8
  51. 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.connection.supports_in_memory_oltp?
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.connection.execute(inmem_sql)
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.1.10
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-12-08 00:00:00.000000000 Z
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.1.1
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.1.1
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/sql_counter_sqlserver.rb
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.1.10/CHANGELOG.md
244
- source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.10
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: 2.7.0
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.21
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/sql_counter_sqlserver.rb
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,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cases/helper_sqlserver"
4
-
5
- class ScratchpadTestSQLServer < ActiveRecord::TestCase
6
- it "helps debug things" do
7
- end
8
- 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