Skip to content

Commit b42579b

Browse files
committed
Workaround
1 parent 387b467 commit b42579b

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

lib/active_record/connection_adapters/sqlserver/table_definition.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ def ss_timestamp(*names, **options)
9494
def json(*names, **options)
9595
names.each { |name| column(name, :text, **options) }
9696
end
97-
98-
def decimal(*names, **options)
99-
# binding.pry if names.include? :atoms_in_universe
100-
# binding.pry if options[:precision].to_i > 38
101-
102-
options[:precision] = 38 if options[:precision].to_i == 55
103-
104-
# options[:precision] ||= 18
105-
106-
names.each { |name| column(name, :decimal, **options) }
107-
end
108-
10997
end
11098

11199
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition

test/cases/helper_sqlserver.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
require "support/core_ext/query_cache"
88
require "support/minitest_sqlserver"
99
require "support/test_in_memory_oltp"
10+
11+
12+
require "support/table_definition_sqlserver"
13+
module ActiveRecord
14+
module ConnectionAdapters
15+
module SQLServer
16+
class TableDefinition < ::ActiveRecord::ConnectionAdapters::TableDefinition
17+
include ARTest::SQLServer::TableDefinition
18+
end
19+
end
20+
end
21+
end
22+
1023
require "cases/helper"
1124
require "support/load_schema_sqlserver"
1225
require "support/coerceable_test_sqlserver"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module ARTest
4+
module SQLServer
5+
module TableDefinition
6+
extend ActiveSupport::Concern
7+
8+
included do
9+
# SQL Server supports precision of 38 for decimal columns. In Rails the test schema includes a column
10+
# with a precision of 55. This is a problem for SQL Server 2008. This method will override the default
11+
# decimal method to limit the precision to 38 for the :atoms_in_universe column.
12+
# See https://github.com/rails/rails/pull/51826/files#diff-2a57b61bbf9ee2c23938fc571d403799f68b4b530d65e2cde219a429bbf10af5L876
13+
def decimal(*names, **options)
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

0 commit comments

Comments
 (0)