Skip to content

Commit 2fbded9

Browse files
aidanharanAidan Haranwpolicarpo
authored
Handle default boolean column values when deduplicating (#875)
Co-authored-by: Aidan Haran <aharan@fusioneer.com> Co-authored-by: Wanderson Policarpo <wpolicarpo@gmail.com>
1 parent 168cabe commit 2fbded9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [#876](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/876) Use native String#end_with
77
- [#873](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/873) Various fixes to get the tests running for Rails 6.1
88
- [#874](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/874) Deduplicate schema cache structures
9+
- [#875](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/875) Handle default boolean column values when deduplicating
910

1011
#### Changed
1112

lib/active_record/connection_adapters/sqlserver_column.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ def is_utf8?
2727
def case_sensitive?
2828
collation && collation.match(/_CS/)
2929
end
30+
31+
private
32+
33+
# Handle when the default value is a boolean. Boolean's do not respond to the method `:-@`. Method now
34+
# checks whether the default value is already frozen and if so it uses that, otherwise it calls `:-@` to
35+
# freeze it.
36+
def deduplicated
37+
@name = -name
38+
@sql_type_metadata = sql_type_metadata.deduplicate if sql_type_metadata
39+
@default = (default.frozen? ? default : -default) if default
40+
@default_function = -default_function if default_function
41+
@collation = -collation if collation
42+
@comment = -comment if comment
43+
44+
freeze
45+
end
3046
end
3147
end
3248
end

0 commit comments

Comments
 (0)