activerecord-native_db_types_override 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,12 +21,15 @@ Then run:
21
21
 
22
22
  ### Usage
23
23
 
24
- In your config/environment.rb or environment specfic configuration, you may specify one or more options in the config hash that will be merged into the default types. The act of configuring does the hash merge/activation of changes.
24
+ In your config/environment.rb or an environment specific configuration, you may specify one or more options in the config hash that will be merged into the default types. The act of configuring does the hash merge/activation of changes.
25
+
26
+ Some gems may require the adapter prior to this point, so it may not need to be required, but we do not load the Rails adapters in the NativeDbTypesOverride gem because all are most likely not needed.
25
27
 
26
28
  #### PostgreSQL
27
29
 
28
30
  For example, if you want Rails to use the timestamptz type for all datetimes and timestamps created by migrations, you could use:
29
31
 
32
+ require 'active_record/connection_adapters/postgresql_adapter'
30
33
  NativeDbTypesOverride.configure({
31
34
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter => {
32
35
  :datetime => { :name => "timestamptz" },
@@ -40,6 +43,7 @@ See [PostgreSQLAdapter][postgres_adapter] for the default types.
40
43
 
41
44
  For the MySQL/MySQL2 adapters, maybe you could change boolean to a string type:
42
45
 
46
+ require 'active_record/connection_adapters/abstract_mysql_adapter'
43
47
  NativeDbTypesOverride.configure({
44
48
  ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter => {
45
49
  :boolean => { :name => "varchar", :limit => 1 }
@@ -52,6 +56,7 @@ See [AbstractMysqlAdapter][mysql_adapter] for the default types.
52
56
 
53
57
  Maybe you need to extend the default string limit from 255 to 4096:
54
58
 
59
+ require 'active_record/connection_adapters/sqlite3_adapter'
55
60
  NativeDbTypesOverride.configure({
56
61
  ActiveRecord::ConnectionAdapters::SQLite3Adapter => {
57
62
  :string => { :name => "varchar", :limit => 4096 }
@@ -70,6 +75,7 @@ In addition, it's native_database_types method can define boolean as VARCHAR2 (1
70
75
 
71
76
  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:
72
77
 
78
+ require 'active_record/connection_adapters/oracle_enhanced_adapter'
73
79
  NativeDbTypesOverride.configure({
74
80
  ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter => {
75
81
  :datetime => { :name => "TIMESTAMP WITH TIMEZONE" },
@@ -84,10 +90,16 @@ See [OracleEnhancedAdapter][oracle_adapter] for the default types.
84
90
 
85
91
  #### Others
86
92
 
87
- Look for the adapter class that contains the native_database_types method and specify the fully-qualified name (e.g. ActiveRecord::ConnectionAdapters::MyDbAdapter) as the key in the options hash. Let us know if we can list your adapter here.
93
+ Look for the adapter class that contains the `native_database_types` method and specify the fully-qualified name (e.g. ActiveRecord::ConnectionAdapters::MyDbAdapter) as the key in the options hash.
94
+
95
+ Be sure to add a require for the adapter, if it has not been loaded already prior to configuration.
96
+
97
+ Let us know if we can list a new or revised adapter here. Pull requests are welcome!
88
98
 
89
99
  ### Troubleshooting
90
100
 
101
+ Make sure that you add the configuration after the `NameOfMyApp::Application.initialize!` or you will get an `uninitialized constant (adapter class)` error.
102
+
91
103
  Test out a migration and include all the types defined in your adapter's NATIVE_DATABASE_TYPES if you're unsure whether it is defining things correctly, e.g. in a test project for PostgreSQL in Rails 3.1/3.2 you could do this and then look at the my_models table in your database:
92
104
 
93
105
  rails g model MyModel a_string:string a_text:text an_integer:integer a_float:float a_decimal:decimal a_datetime:datetime a_timestamp:timestamp a_time:time a_date:date a_binary:binary a_boolean:boolean a_xml:xml a_tsvector:tsvector
@@ -1,3 +1,3 @@
1
1
  module NativeDbTypesOverride
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  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.1.0
4
+ version: 0.1.1
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-10-10 00:00:00.000000000 Z
12
+ date: 2012-12-12 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.