Skip to content

Commit c98e72f

Browse files
aidanharanAidan Haran
andauthored
Handle any default column class when deduplicating (#880)
Co-authored-by: Aidan Haran <aharan@fusioneer.com>
1 parent bee6e1d commit c98e72f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [#874](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/874) Deduplicate schema cache structures
99
- [#875](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/875) Handle default boolean column values when deduplicating
1010
- [#879](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/879) Added visit method for HomogeneousIn
11+
- [#880](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/880) Handle any default column class when deduplicating
1112

1213
#### Changed
1314

lib/active_record/connection_adapters/sqlserver_column.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ def case_sensitive?
3030

3131
private
3232

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.
33+
# In the Rails version of this method there is an assumption that the `default` value will always be a
34+
# `String` class, which must be true for the MySQL/PostgreSQL/SQLite adapters. However, in the SQL Server
35+
# adapter the `default` value can also be Boolean/Date/Time/etc. Changed the implementation of this method
36+
# to handle non-String `default` objects.
3637
def deduplicated
3738
@name = -name
3839
@sql_type_metadata = sql_type_metadata.deduplicate if sql_type_metadata
39-
@default = (default.frozen? ? default : -default) if default
40+
@default = (default.is_a?(String) ? -default : default.dup.freeze) if default
4041
@default_function = -default_function if default_function
4142
@collation = -collation if collation
4243
@comment = -comment if comment

0 commit comments

Comments
 (0)