Skip to content

Commit 7a9b2b7

Browse files
committed
Type not required for virtual column
1 parent ec766d0 commit 7a9b2b7

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/active_record/connection_adapters/sqlserver/schema_dumper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def prepare_column_options(column)
1414
if @connection.supports_virtual_columns? && column.virtual?
1515
spec[:as] = extract_expression_for_virtual_column(column)
1616
spec[:stored] = column.virtual_stored?
17-
spec = {type: schema_type(column).inspect}.merge!(spec)
1817
end
1918

2019
spec

test/cases/virtual_column_test_sqlserver.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def setup
1313
@connection = ActiveRecord::Base.lease_connection
1414
@connection.create_table :virtual_columns, force: true do |t|
1515
t.string :name
16-
t.virtual :upper_name, type: :string, as: "UPPER(name)", stored: true
17-
t.virtual :lower_name, type: :string, as: "LOWER(name)", stored: false
18-
t.virtual :octet_name, type: :integer, as: "LEN(name)"
19-
t.virtual :mutated_name, type: :string, as: "REPLACE(name, 'l', 'L')"
16+
t.virtual :upper_name, as: "UPPER(name)", stored: true
17+
t.virtual :lower_name, as: "LOWER(name)", stored: false
18+
t.virtual :octet_name, as: "LEN(name)"
19+
t.virtual :mutated_name, as: "REPLACE(name, 'l', 'L')"
2020
t.integer :column1
2121
end
2222
VirtualColumn.create(name: "Rails", column1: 10)
@@ -68,7 +68,7 @@ def test_virtual_column_with_comma_in_definition
6868

6969
def test_change_table_with_stored_generated_column
7070
@connection.change_table :virtual_columns do |t|
71-
t.virtual :decr_column1, type: :integer, as: "column1 - 1", stored: true
71+
t.virtual :decr_column1, as: "column1 - 1", stored: true
7272
end
7373
VirtualColumn.reset_column_information
7474
column = VirtualColumn.columns_hash["decr_column1"]
@@ -79,7 +79,7 @@ def test_change_table_with_stored_generated_column
7979

8080
def test_change_table_with_explicit_virtual_generated_column
8181
@connection.change_table :virtual_columns do |t|
82-
t.virtual :incr_column1, type: :integer, as: "column1 + 1", stored: false
82+
t.virtual :incr_column1, as: "column1 + 1", stored: false
8383
end
8484
VirtualColumn.reset_column_information
8585
column = VirtualColumn.columns_hash["incr_column1"]
@@ -90,7 +90,7 @@ def test_change_table_with_explicit_virtual_generated_column
9090

9191
def test_change_table_with_implicit_virtual_generated_column
9292
@connection.change_table :virtual_columns do |t|
93-
t.virtual :sqr_column1, type: :integer, as: "power(column1, 2)"
93+
t.virtual :sqr_column1, as: "power(column1, 2)"
9494
end
9595
VirtualColumn.reset_column_information
9696
column = VirtualColumn.columns_hash["sqr_column1"]
@@ -101,8 +101,8 @@ def test_change_table_with_implicit_virtual_generated_column
101101

102102
def test_schema_dumping
103103
output = dump_table_schema("virtual_columns")
104-
assert_match(/t\.virtual\s+"lower_name",\s+type: :string,\s+as: "\(lower\(\[name\]\)\)", stored: false$/i, output)
105-
assert_match(/t\.virtual\s+"upper_name",\s+type: :string,\s+as: "\(upper\(\[name\]\)\)", stored: true$/i, output)
104+
assert_match(/t\.virtual\s+"lower_name",\s+as: "\(lower\(\[name\]\)\)", stored: false$/i, output)
105+
assert_match(/t\.virtual\s+"upper_name",\s+as: "\(upper\(\[name\]\)\)", stored: true$/i, output)
106106
end
107107

108108
def test_build_fixture_sql

0 commit comments

Comments
 (0)