activerecord-native_db_types_override 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -15,10 +15,6 @@ In your ActiveRecord/Rails 3.1+ project, add this to your Gemfile:
|
|
15
15
|
|
16
16
|
gem 'activerecord-native_db_types_override'
|
17
17
|
|
18
|
-
For the development version:
|
19
|
-
|
20
|
-
gem 'activerecord-native_db_types_override', :git => 'git://github.com/garysweaver/activerecord-native_db_types_override.git'
|
21
|
-
|
22
18
|
Then run:
|
23
19
|
|
24
20
|
bundle install
|
@@ -31,7 +27,7 @@ In your config/environment.rb or environment specfic configuration, you may spec
|
|
31
27
|
|
32
28
|
For example, if you want Rails to use the timestamptz type for all datetimes and timestamps created by migrations, you could use:
|
33
29
|
|
34
|
-
NativeDbTypesOverride
|
30
|
+
NativeDbTypesOverride.configure({
|
35
31
|
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter => {
|
36
32
|
:datetime => { :name => "timestamptz" },
|
37
33
|
:timestamp => { :name => "timestamptz" }
|
@@ -44,7 +40,7 @@ See [PostgreSQLAdapter][postgres_adapter] for the default types.
|
|
44
40
|
|
45
41
|
For the MySQL/MySQL2 adapters, maybe you could change boolean to a string type:
|
46
42
|
|
47
|
-
NativeDbTypesOverride
|
43
|
+
NativeDbTypesOverride.configure({
|
48
44
|
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter => {
|
49
45
|
:boolean => { :name => "varchar", :limit => 1 }
|
50
46
|
}
|
@@ -56,7 +52,7 @@ See [AbstractMysqlAdapter][mysql_adapter] for the default types.
|
|
56
52
|
|
57
53
|
Maybe you need to extend the default string limit from 255 to 4096:
|
58
54
|
|
59
|
-
NativeDbTypesOverride
|
55
|
+
NativeDbTypesOverride.configure({
|
60
56
|
ActiveRecord::ConnectionAdapters::SQLite3Adapter => {
|
61
57
|
:string => { :name => "varchar", :limit => 4096 }
|
62
58
|
}
|
@@ -74,7 +70,7 @@ In addition, it's native_database_types method can define boolean as VARCHAR2 (1
|
|
74
70
|
|
75
71
|
However, if you need to make another change like making datetime and timestamp store timezones *and* you want to emulate_booleans_from_strings, just ensure that you define the boolean shown in the following example rather than using OracleEnhancedAdapter's emulate_booleans_from_strings option:
|
76
72
|
|
77
|
-
NativeDbTypesOverride
|
73
|
+
NativeDbTypesOverride.configure({
|
78
74
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter => {
|
79
75
|
:datetime => { :name => "TIMESTAMP WITH TIMEZONE" },
|
80
76
|
:timestamp => { :name => "TIMESTAMP WITH TIMEZONE" },
|
@@ -119,6 +115,10 @@ And try to play with data (this is postgres-specific):
|
|
119
115
|
m.a_tsvector = nil
|
120
116
|
m.save!
|
121
117
|
|
118
|
+
Turn on debug output by adding this prior to NativeDbTypesOverride.configure:
|
119
|
+
|
120
|
+
NativeDbTypesOverride.debug = true
|
121
|
+
|
122
122
|
### License
|
123
123
|
|
124
124
|
Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
|
@@ -1,25 +1,23 @@
|
|
1
1
|
module NativeDbTypesOverride
|
2
|
-
class
|
3
|
-
|
4
|
-
puts "ActiveRecord - Native Database Types Override #{NativeDbTypesOverride::VERSION}"
|
2
|
+
class << self
|
3
|
+
attr_accessor :debug
|
5
4
|
|
5
|
+
def debug?
|
6
|
+
!!send(:debug)
|
7
|
+
end
|
8
|
+
|
9
|
+
def configure(hash)
|
10
|
+
puts "ActiveRecord - Native Database Types Override #{NativeDbTypesOverride::VERSION}" if NativeDbTypesOverride.debug?
|
6
11
|
hash.keys.each do |clazz|
|
7
|
-
# do the override
|
8
12
|
new_types = {}
|
9
|
-
|
10
13
|
begin
|
11
14
|
new_types = clazz.const_get('NATIVE_DATABASE_TYPES')
|
12
15
|
rescue
|
13
|
-
puts "No NATIVE_DATABASE_TYPES constant on #{clazz} so expecting the whole types hash to be specified in the NativeDbTypesOverride::Options.configure"
|
16
|
+
puts "No NATIVE_DATABASE_TYPES constant on #{clazz} so expecting the whole types hash to be specified in the NativeDbTypesOverride::Options.configure" if NativeDbTypesOverride.debug?
|
14
17
|
end
|
15
|
-
|
16
18
|
new_types = new_types.merge(hash[clazz])
|
17
|
-
|
18
|
-
puts "Setting #{clazz}.native_database_types to #{new_types.inspect}"
|
19
|
-
|
19
|
+
puts "Defining #{clazz}.native_database_types as #{new_types.inspect}" if NativeDbTypesOverride.debug?
|
20
20
|
clazz.class_eval "def native_database_types; #{new_types.inspect}; end"
|
21
|
-
|
22
|
-
puts "ActiveRecord - Native Database Types Override success"
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-native_db_types_override
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Overrides native database types for any database adapter with a native_database_types
|
15
15
|
method. Compatible with ActiveRecord 3.1+/4.0.
|