Skip to content

Commit c2b9952

Browse files
committed
Standardrb
1 parent dcfc7e1 commit c2b9952

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- [#1301](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1301) Add support for `INDEX INCLUDE`.
66
- [#1312](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1312) Add support for `insert_all` and `upsert_all`.
7-
- [#](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/) Added support for computed columns.
7+
- [#1367](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1367) Added support for computed columns.
88

99
#### Changed
1010

lib/active_record/connection_adapters/sqlserver/schema_creation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def add_column_options!(sql, options)
6666
sql << " DEFAULT #{quote_default_expression_for_column_definition(options[:default], options[:column])}" if options_include_default?(options)
6767

6868
sql << " COLLATE #{options[:collation]}" if options[:collation].present?
69-
sql << " NOT NULL" if options[:null] == false
70-
sql << " IDENTITY(1,1)" if options[:is_identity] == true
71-
sql << " PRIMARY KEY" if options[:primary_key] == true
69+
sql << " NOT NULL" if options[:null] == false
70+
sql << " IDENTITY(1,1)" if options[:is_identity] == true
71+
sql << " PRIMARY KEY" if options[:primary_key] == true
7272

73-
if as = options[:as]
73+
if (as = options[:as])
7474
sql << " AS #{as}"
7575
sql << " PERSISTED" if options[:stored]
7676
end

lib/active_record/connection_adapters/sqlserver/schema_dumper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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)
17+
spec = {type: schema_type(column).inspect}.merge!(spec)
1818
end
1919

2020
spec

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,26 @@ def index_include_columns(table_name, index_name)
8585
select_all(sql, "SCHEMA").map { |row| row["column_name"] }
8686
end
8787

88+
def columns(table_name)
89+
return [] if table_name.blank?
8890

89-
# def columns(table_name)
90-
# return [] if table_name.blank?
91-
#
92-
# definitions = column_definitions(table_name)
93-
# definitions.map do |field|
94-
# new_column_from_field(table_name, field, definitions)
95-
# end
96-
# end
91+
definitions = column_definitions(table_name)
92+
definitions.map do |field|
93+
new_column_from_field(table_name, field, definitions)
94+
end
95+
end
9796

9897
def new_column_from_field(table_name, field, definitions)
9998
sqlserver_options = field.slice(:ordinal_position, :is_primary, :is_identity, :table_name)
10099
sql_type_metadata = fetch_type_metadata(field[:type], sqlserver_options)
101100
generated_type = extract_generated_type(field)
102101

103-
104-
105-
106-
if generated_type.present?
107-
# binding.pry if field[:name] == "mutated_name"
108-
109-
110-
default_function = field[:computed_formula]
102+
default_function = if generated_type.present?
103+
field[:computed_formula]
111104
else
112-
default_function = field[:default_function]
105+
field[:default_function]
113106
end
114107

115-
116108
SQLServer::Column.new(
117109
field[:name],
118110
lookup_cast_type(field[:type]),

lib/active_record/connection_adapters/sqlserver_column.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ def case_sensitive?
3333
end
3434

3535
def virtual?
36-
37-
# binding.pry
38-
3936
@generated_type.present?
4037
end
4138

test/cases/virtual_column_test_sqlserver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class VirtualColumn < ActiveRecord::Base
1212
def setup
1313
@connection = ActiveRecord::Base.lease_connection
1414
@connection.create_table :virtual_columns, force: true do |t|
15-
t.string :name
15+
t.string :name
1616
t.virtual :upper_name, type: :string, as: "UPPER(name)", stored: true
1717
t.virtual :lower_name, type: :string, as: "LOWER(name)", stored: false
1818
t.virtual :octet_name, type: :integer, as: "LEN(name)"
@@ -110,4 +110,3 @@ def test_build_fixture_sql
110110
assert_equal 2, fixtures.size
111111
end
112112
end
113-

0 commit comments

Comments
 (0)