Skip to content

Commit 3b34eff

Browse files
committed
Remove native string and type configs.
These are not needed and there all have easy escape hatches given AR migrations capacity to use pure SQL types.
1 parent 27ab2ca commit 3b34eff

File tree

6 files changed

+73
-151
lines changed

6 files changed

+73
-151
lines changed

CHANGELOG.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,26 @@
1414
* Use `ARTest` namespace with `SQLServer` module for our helpers/objects.
1515
* Simple 2012 schmea addition and extensive column/type_cast object tests.
1616

17+
#### Deprecated
1718

18-
## v4.1.0
19+
* n/a
1920

20-
* Not sure if this even happened. Just got to 4.2.0 :)
21+
#### Removed
2122

23+
* SQL Server versions < 2012 which do not support OFFSET and FETCH. http://bit.ly/1B5Bwsd
24+
* The `enable_default_unicode_types` option. Default to national types all the time. Use SQL type name in migrations if needed.
25+
* Native type configs for older DB support. Includes the following with new default value.
26+
* native_string_database_type => `nvarchar`
27+
* native_text_database_type => `nvarchar(max)`
28+
* native_binary_database_type => `varbinary(max)`
2229

23-
## v4.0.0
2430

25-
* Dropped support for ruby 1.8.7
26-
* Removed deadlock victim retry in favor of Isolation Level
27-
* Removed auto_explain_threshold_in_seconds (not used in rails 4)
31+
#### Fixed
2832

33+
* n/a
2934

30-
## v3.2.12
31-
35+
#### Security
3236

37+
* n/a
3338

3439

README.md

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# ActiveRecord SQL Server Adapter. For SQL Server 2005 And Higher.
1+
2+
# ActiveRecord SQL Server Adapter. For SQL Server 2012 And Higher.
23

34
**This project is looking for a new maintainers. Join the [discusion here](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/364)**
45

@@ -55,45 +56,6 @@ end
5556
Manually creating a `varchar(max)` is not necessary since this is the default type created when specifying a `:text` field. As time goes on we will be testing other SQL Server specific data types are handled correctly when created in a migration.
5657

5758

58-
#### Native Text/String/Binary Data Type Accessor
59-
60-
To pass the ActiveRecord tests we had to implement an class accessor for the native type created for `:text` columns. By default any `:text` column created by migrations will create a `varchar(max)` data type. This type can be queried using the SQL = operator and has plenty of storage space which is why we made it the default. If for some reason you want to change the data type created during migrations you can configure this line to your liking in a config/initializers file.
61-
62-
```ruby
63-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'varchar(8000)'
64-
```
65-
66-
Also, there is a class attribute setter for the native string database type. This is the same for all SQL Server versions, `varchar`. However it can be used instead of the #enable_default_unicode_types below for finer grain control over which types you want unicode safe when adding or changing the schema.
67-
68-
```ruby
69-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
70-
```
71-
72-
By default any :binary column created by migrations will create a `varbinary(max)` data type. This too can be set using an initializer.
73-
74-
```ruby
75-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_binary_database_type = 'image'
76-
```
77-
78-
#### Setting Unicode Types As Default
79-
80-
By default the adapter will use unicode safe data types for `:string` and `:text` types when defining/changing the schema! This was changed in version 3.1 since it is about time we push better unicode support and since we default to TinyTDS (DBLIB) which supports unicode queries and data. If you choose, you can set the following class attribute in a config/initializers file that will disable this behavior.
81-
82-
```ruby
83-
# Default
84-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = true
85-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'nvarchar(max)'
86-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'nvarchar'
87-
88-
# Disabled
89-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.enable_default_unicode_types = false
90-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_text_database_type = 'varchar(max)'
91-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type = 'varchar'
92-
```
93-
94-
It is important to remember that unicode types in SQL Server have approximately half the storage capacity as their counter parts. So where a normal string would max out at (8000) a unicode string will top off at (4000).
95-
96-
9759
#### Force Schema To Lowercase
9860

9961
Although it is not necessary, the Ruby convention is to use lowercase method names. If your database schema is in upper or mixed case, we can force all table and column names during the schema reflection process to be lowercase. Add this to your config/initializers file for the adapter.

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ def views
163163
def initialize_native_database_types
164164
{
165165
primary_key: 'int NOT NULL IDENTITY(1,1) PRIMARY KEY',
166-
string: { name: native_string_database_type, limit: 255 },
167-
text: { name: native_text_database_type },
166+
string: { name: 'nvarchar', limit: 255 },
167+
text: { name: 'nvarchar(max)' },
168168
integer: { name: 'int', limit: 4 },
169169
float: { name: 'float', limit: 8 },
170170
decimal: { name: 'decimal' },
171171
datetime: { name: 'datetime' },
172172
timestamp: { name: 'datetime' },
173-
time: { name: native_time_database_type },
174-
date: { name: native_date_database_type },
175-
binary: { name: native_binary_database_type },
173+
time: { name: 'time' },
174+
date: { name: 'date' },
175+
binary: { name: 'varbinary(max)' },
176176
boolean: { name: 'bit' },
177177
uuid: { name: 'uniqueidentifier' },
178178
# These are custom types that may move somewhere else for good schema_dumper.rb hacking to output them.

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ class SQLServerAdapter < AbstractAdapter
3737

3838
attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition
3939

40-
cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
41-
:enable_default_unicode_types, :auto_connect, :cs_equality_operator,
40+
cattr_accessor :auto_connect, :cs_equality_operator,
4241
:lowercase_schema_reflection, :auto_connect_duration, :showplan_option
4342

44-
self.enable_default_unicode_types = true
45-
4643
def initialize(connection, logger, pool, config)
4744
super(connection, logger, pool)
4845
# AbstractAdapter Responsibility
@@ -221,26 +218,6 @@ def auto_connect_duration
221218
@@auto_connect_duration ||= 10
222219
end
223220

224-
def native_string_database_type
225-
@@native_string_database_type || (enable_default_unicode_types ? 'nvarchar' : 'varchar')
226-
end
227-
228-
def native_text_database_type
229-
@@native_text_database_type || enable_default_unicode_types ? 'nvarchar(max)' : 'varchar(max)'
230-
end
231-
232-
def native_time_database_type
233-
sqlserver_2005? ? 'datetime' : 'time'
234-
end
235-
236-
def native_date_database_type
237-
sqlserver_2005? ? 'datetime' : 'date'
238-
end
239-
240-
def native_binary_database_type
241-
@@native_binary_database_type || 'varbinary(max)'
242-
end
243-
244221
def cs_equality_operator
245222
@@cs_equality_operator || 'COLLATE Latin1_General_CS_AS_WS'
246223
end

0 commit comments

Comments
 (0)