activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/History.md +87 -0
- data/README.md +271 -174
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +26 -22
- data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +0 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +17 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +92 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +543 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
- data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +26 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +159 -66
- data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
- data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
- data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +63 -63
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +21 -175
- data/spec/spec_config.yaml.template +10 -0
- data/spec/spec_helper.rb +21 -10
- metadata +29 -25
- data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
- data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0666c234c8895bc18f1fa4c031c0f8a3990d2a16
|
4
|
+
data.tar.gz: be6e762e334b31cced2092ff0ba5cea2dd0ac534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f975ab990ef8c3ddc397141ad3d8cf432a9518f6fea12f1405e3cc5e5b498c0de9dff555605ade1bb844e1c2754149569e4c73fdf140b61bc80b2620a6564906
|
7
|
+
data.tar.gz: 47a94ecdc4670af38ae4e138d6e2ca96c76622cd96e1d39084d1af9d16a1a8c0a3892749d32604d57f97eb6f1cbaa10de9fda46066466ef4a10478288b1d6da5
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem 'jeweler', '~>
|
4
|
+
gem 'jeweler', '~> 2.0'
|
5
5
|
gem 'rspec', '~> 2.4'
|
6
6
|
gem 'rdoc'
|
7
7
|
|
@@ -11,7 +11,7 @@ group :development do
|
|
11
11
|
gem 'actionpack', github: 'rails/rails'
|
12
12
|
gem 'railties', github: 'rails/rails'
|
13
13
|
|
14
|
-
gem 'arel', github: 'rails/arel'
|
14
|
+
gem 'arel', github: 'rails/arel', branch: '6-0-stable'
|
15
15
|
gem 'journey', github: 'rails/journey'
|
16
16
|
|
17
17
|
gem 'activerecord-deprecated_finders'
|
data/History.md
CHANGED
@@ -1,3 +1,90 @@
|
|
1
|
+
## 1.6.0.beta 1 / 2016-06-19
|
2
|
+
* Enhancements and bug fix
|
3
|
+
* Support Rails 4.2
|
4
|
+
* Support Rails native foreign key syntax [#488, #618]
|
5
|
+
|
6
|
+
* Other changes and bug fixes
|
7
|
+
* Column#primary method removed from Rails [#483]
|
8
|
+
* ActiveRecord::Migrator.proper_table_name has been removed from Rails [#481]
|
9
|
+
* New db/schema.rb files will be created with force: :cascade [#593]
|
10
|
+
* Rails42 add unique index creates unique constraint [#617]
|
11
|
+
* Modify remove_column to add cascade constraint to avoid ORA-12991 [#617]
|
12
|
+
* Add `null: true` to avoid DEPRECATION WARNING [#489, #499]
|
13
|
+
* Rails 4.2 Add `connection.supports_views?` [#496]
|
14
|
+
* text? has been removed from Column class [#487]
|
15
|
+
* Remove call to deprecated `serialized_attributes` [#550, #552]
|
16
|
+
* Support :cascade option for drop_table [#579]
|
17
|
+
* Raise a better exception for renaming long indexes [#577]
|
18
|
+
* Override aliased_types [#575]
|
19
|
+
* Revert "Add options_include_default!" [#586]
|
20
|
+
* Remove substitute_at method from Oracle enhanced adapter [#520]
|
21
|
+
* Require 'active_record/base' in rake task #526
|
22
|
+
* Make it easier to spot which version of active record is actually used [#550]
|
23
|
+
* Rails4.2 Add Type::Raw type [#503]
|
24
|
+
* Support :bigint datatype [#580]
|
25
|
+
* Map :bigint as NUMBER(19) sql_type not NUMBER(8) [#608]
|
26
|
+
* Use Oracle BINARY_FLOAT datatype for Rails :float type [#610]
|
27
|
+
* Revert "Implement possibility of handling of NUMBER columns as :float" [#576]
|
28
|
+
* Rails 4.2 Support NCHAR correctly [#490]
|
29
|
+
* Support :timestamp datatype in Rails 4.2 [#575]
|
30
|
+
* Rails 4.2 Handle NUMBER sql_type as `Type::Integer` cast type [#509]
|
31
|
+
* ActiveRecord::OracleEnhanced::Type::Integer for max_value to take 38 digits [#605]
|
32
|
+
* Rails 4.2 add `module OracleEnhanced` and migrate classes/modules under this [#584]
|
33
|
+
* Migrate to ActiveRecord::ConnectionAdapters::OracleEnhanced::ColumnDumper [#597]
|
34
|
+
* Migrated from OracleEnhancedContextIndex to OracleEnhanced::ContextIndex [#599]
|
35
|
+
* Make OracleEnhancedIndexDefinition as subclass of IndexDefinition [#600]
|
36
|
+
* Refactor add_index and add_index_options [#601]
|
37
|
+
* Types namespace moved to `ActiveRecord::Type::Value` [#484]
|
38
|
+
* Add new_column method [#482]
|
39
|
+
* Rename type_cast to type_cast_from_database [#485]
|
40
|
+
* Removed `forced_column_type` by using `cast_type` [#595]
|
41
|
+
* Move dump_schema_information to SchemaStatements [#611]
|
42
|
+
* Move OracleEnhancedIndexDefinition to OracleEnhanced::IndexDefinition [#614]
|
43
|
+
* Move OracleEnhancedSynonymDefinition to OracleEnhanced::SynonymDefinition [#615]
|
44
|
+
* Move types under OracleEnhanced module [#603]
|
45
|
+
* Make OracleEnhancedForeignKeyDefinition as subclass of ForeignKeyDefinition [#581]
|
46
|
+
* Support _field_changed argument changes [#479]
|
47
|
+
* Rails 4.2 Don't type cast the default on the column [#504]
|
48
|
+
* Rename variable names in create_table to follow Rails implementation [#616]
|
49
|
+
* Rails 4.2: Fix create_savepoint and rollback_to_savepoint name [#497]
|
50
|
+
* Shorten foreign key name if it is longer than 30 byte [#621]
|
51
|
+
* Restore foreign_key_definition [#624]
|
52
|
+
* Rails 4.2 Support OracleEnhancedAdapter.emulate_integers_by_column_name [#491]
|
53
|
+
* Rails 4.2 Support OracleEnhancedAdapter.emulate_dates_by_column_name [#492]
|
54
|
+
* Rails 4.2 Support emulate_booleans_from_strings and is_boolean_column? [#506]
|
55
|
+
* Rails 4.2 Support OracleEnhancedAdapter.number_datatype_coercion [#512]
|
56
|
+
* Rails 4.2 Use register_class_with_limit [#502]
|
57
|
+
* Rails 4.2 Remove redundant substitute index when constructing bind values [#517]
|
58
|
+
* Rails 4.2 Unit test updated to support `substitute_at` in Arel [#522]
|
59
|
+
* Change log method signiture to support Rails 4.2 [#539]
|
60
|
+
* Enable loading spec configuration from config file instead of env [#550]
|
61
|
+
* Rails42: Issue with non-existent columns [#545, #551]
|
62
|
+
* Squelch warning "#column_for_attribute` will return a null object
|
63
|
+
for non-existent columns in Rails 5. Use `#has_attribute?`" [#551]
|
64
|
+
* Use arel 6-0-stable [#565]
|
65
|
+
* Support 'Y' as true and 'N' as false in Rails 4.2 [#574, #573]
|
66
|
+
* Remove alias_method_chain :references, :foreign_keys [#582]
|
67
|
+
* Use quote_value method to avoid undefined method `type_cast_for_database' for nil:NilClass [#486]
|
68
|
+
* Rails 4.2: Set @nchar and @object_type only when sql_type is true [#493]
|
69
|
+
* Rails 4.2: Handle forced_column_type temporary [#498]
|
70
|
+
* Rails 4.2 Address ArgumentError: wrong number of arguments (1 for 2) at `quote_value` [#511]
|
71
|
+
* Address ORA-00932: inconsistent datatypes: expected NUMBER got DATE [#538]
|
72
|
+
* Remove duplicate alias_method_chain for indexes [#560]
|
73
|
+
* Address RangeError: 6000000000 is out of range for ActiveRecord::Type::Integer
|
74
|
+
with limit 4 [#578]
|
75
|
+
* Return foreign_keys_without_oracle_enhanced when non Oracle database used [#583]
|
76
|
+
* Add missing database_tasks.rb to gemspec [#585]
|
77
|
+
* Fixed typo in the rake tasks load statement [#587]
|
78
|
+
* Call super when column typs is serialized [#563, #591]
|
79
|
+
* Clear query cache on rollback [#592]
|
80
|
+
* Modify default to `false` if database default value is "N" [#596]
|
81
|
+
* refer correct location if filess in gemspec [#606]
|
82
|
+
* Add integer.rb to gemspec [#607]
|
83
|
+
|
84
|
+
* Known Issues
|
85
|
+
* Override aliased_types [#575]
|
86
|
+
* Multi column foreign key is not supported
|
87
|
+
|
1
88
|
## 1.5.6 / 2015-03-30
|
2
89
|
|
3
90
|
* Enhancements
|
data/README.md
CHANGED
@@ -17,17 +17,23 @@ Oracle enhanced adapter version 1.5 just supports Rails 4 and does not support R
|
|
17
17
|
|
18
18
|
When using Ruby on Rails version 4 then in Gemfile include
|
19
19
|
|
20
|
-
|
20
|
+
```ruby
|
21
|
+
gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.0'
|
22
|
+
```
|
21
23
|
|
22
24
|
where instead of 1.5.0 you can specify any other desired version. It is recommended to specify version with `~>` which means that use specified version or later patch versions (in this example any later 1.5.x version but not 1.6.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.
|
23
25
|
|
24
26
|
If you would like to use latest adapter version from github then specify
|
25
27
|
|
26
|
-
|
28
|
+
```ruby
|
29
|
+
gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
|
30
|
+
```
|
27
31
|
|
28
32
|
If you are using CRuby 1.9.3 or 2.0 then you need to install ruby-oci8 gem as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html). Include in Gemfile also ruby-oci8:
|
29
33
|
|
30
|
-
|
34
|
+
```ruby
|
35
|
+
gem 'ruby-oci8', '~> 2.1.0'
|
36
|
+
```
|
31
37
|
|
32
38
|
If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc7.jar or ojdbc6.jar for Java 7, ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:
|
33
39
|
|
@@ -38,7 +44,9 @@ If you are using JRuby then you need to download latest [Oracle JDBC driver](htt
|
|
38
44
|
|
39
45
|
After specifying necessary gems in Gemfile run
|
40
46
|
|
41
|
-
|
47
|
+
```bash
|
48
|
+
bundle install
|
49
|
+
```
|
42
50
|
|
43
51
|
to install the adapter (or later run `bundle update` to force updating to latest version).
|
44
52
|
|
@@ -46,17 +54,23 @@ to install the adapter (or later run `bundle update` to force updating to latest
|
|
46
54
|
|
47
55
|
When using Ruby on Rails version 3 then in Gemfile include
|
48
56
|
|
49
|
-
|
57
|
+
```ruby
|
58
|
+
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
|
59
|
+
```
|
50
60
|
|
51
61
|
where instead of 1.4.0 you can specify any other desired version. It is recommended to specify version with `~>` which means that use specified version or later patch versions (in this example any later 1.4.x version but not 1.5.x version). Oracle enhanced adapter maintains API backwards compatibility during patch version upgrades and therefore it is safe to always upgrade to latest patch version.
|
52
62
|
|
53
63
|
If you would like to use latest adapter version from github then specify
|
54
64
|
|
55
|
-
|
65
|
+
```ruby
|
66
|
+
gem 'activerecord-oracle_enhanced-adapter', :git => 'git://github.com/rsim/oracle-enhanced.git'
|
67
|
+
```
|
56
68
|
|
57
69
|
If you are using MRI 1.8 or 1.9 Ruby implementation then you need to install ruby-oci8 gem as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html). Include in Gemfile also ruby-oci8:
|
58
70
|
|
59
|
-
|
71
|
+
```ruby
|
72
|
+
gem 'ruby-oci8', '~> 2.1.0'
|
73
|
+
```
|
60
74
|
|
61
75
|
If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5. And copy this file to one of these locations:
|
62
76
|
|
@@ -67,7 +81,9 @@ If you are using JRuby then you need to download latest [Oracle JDBC driver](htt
|
|
67
81
|
|
68
82
|
After specifying necessary gems in Gemfile run
|
69
83
|
|
70
|
-
|
84
|
+
```bash
|
85
|
+
bundle install
|
86
|
+
```
|
71
87
|
|
72
88
|
to install the adapter (or later run `bundle update` to force updating to latest version).
|
73
89
|
|
@@ -75,12 +91,14 @@ to install the adapter (or later run `bundle update` to force updating to latest
|
|
75
91
|
|
76
92
|
If you don't use Bundler in Rails 2 application then you need to specify gems in `config/environment.rb`, e.g.
|
77
93
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
94
|
+
```ruby
|
95
|
+
Rails::Initializer.run do |config|
|
96
|
+
# ...
|
97
|
+
config.gem 'activerecord-oracle_enhanced-adapter', :lib => 'active_record/connection_adapters/oracle_enhanced_adapter'
|
98
|
+
config.gem 'ruby-oci8'
|
99
|
+
# ...
|
100
|
+
end
|
101
|
+
```
|
84
102
|
|
85
103
|
But it is recommended to use Bundler for gem version management also for Rails 2.3 applications (search for instructions in Google).
|
86
104
|
|
@@ -88,7 +106,9 @@ But it is recommended to use Bundler for gem version management also for Rails 2
|
|
88
106
|
|
89
107
|
If you want to use ActiveRecord and Oracle enhanced adapter without Rails and Bundler then install it just as a gem:
|
90
108
|
|
91
|
-
|
109
|
+
```bash
|
110
|
+
gem install activerecord-oracle_enhanced-adapter
|
111
|
+
```
|
92
112
|
|
93
113
|
USAGE
|
94
114
|
-----
|
@@ -97,52 +117,64 @@ USAGE
|
|
97
117
|
|
98
118
|
In Rails application `config/database.yml` use oracle_enhanced as adapter name, e.g.
|
99
119
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
120
|
+
```yml
|
121
|
+
development:
|
122
|
+
adapter: oracle_enhanced
|
123
|
+
database: xe
|
124
|
+
username: user
|
125
|
+
password: secret
|
126
|
+
```
|
105
127
|
|
106
128
|
If you're connecting to a service name, indicate the service with a
|
107
129
|
leading slash on the database parameter:
|
108
130
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
131
|
+
```yml
|
132
|
+
development:
|
133
|
+
adapter: oracle_enhanced
|
134
|
+
database: /xe
|
135
|
+
username: user
|
136
|
+
password: secret
|
137
|
+
```
|
114
138
|
|
115
139
|
If `TNS_ADMIN` environment variable is pointing to directory where `tnsnames.ora` file is located then you can use TNS connection name in `database` parameter. Otherwise you can directly specify database host, port (defaults to 1521) and database name in the following way:
|
116
140
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
141
|
+
```yml
|
142
|
+
development:
|
143
|
+
adapter: oracle_enhanced
|
144
|
+
host: localhost
|
145
|
+
port: 1521
|
146
|
+
database: xe
|
147
|
+
username: user
|
148
|
+
password: secret
|
149
|
+
```
|
124
150
|
|
125
151
|
or you can use Oracle specific format in `database` parameter:
|
126
152
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
153
|
+
```yml
|
154
|
+
development:
|
155
|
+
adapter: oracle_enhanced
|
156
|
+
database: //localhost:1521/xe
|
157
|
+
username: user
|
158
|
+
password: secret
|
159
|
+
```
|
132
160
|
|
133
161
|
or you can even use Oracle specific TNS connection description:
|
134
162
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
163
|
+
```yml
|
164
|
+
development:
|
165
|
+
adapter: oracle_enhanced
|
166
|
+
database: "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=xe)))"
|
167
|
+
username: user
|
168
|
+
password: secret
|
169
|
+
```
|
140
170
|
|
141
171
|
If you deploy JRuby on Rails application in Java application server that supports JNDI connections then you can specify JNDI connection as well:
|
142
172
|
|
143
|
-
|
144
|
-
|
145
|
-
|
173
|
+
```yml
|
174
|
+
development:
|
175
|
+
adapter: oracle_enhanced
|
176
|
+
jndi: "jdbc/jndi_connection_name"
|
177
|
+
```
|
146
178
|
|
147
179
|
To use jndi with Tomcat you need to set the accessToUnderlyingConnectionAllowed to true property on the pool. See the [Tomcat Documentation](http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html) for reference.
|
148
180
|
|
@@ -152,22 +184,28 @@ You can find other available database.yml connection parameters in [oracle_enhan
|
|
152
184
|
|
153
185
|
If you want to change Oracle enhanced adapter default settings then create initializer file e.g. `config/initializers/oracle.rb` specify there necessary defaults, e.g.:
|
154
186
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
187
|
+
```ruby
|
188
|
+
# It is recommended to set time zone in TZ environment variable so that the same timezone will be used by Ruby and by Oracle session
|
189
|
+
ENV['TZ'] = 'UTC'
|
190
|
+
|
191
|
+
ActiveSupport.on_load(:active_record) do
|
192
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
|
193
|
+
# id columns and columns which end with _id will always be converted to integers
|
194
|
+
self.emulate_integers_by_column_name = true
|
195
|
+
|
196
|
+
# DATE columns which include "date" in name will be converted to Date, otherwise to Time
|
197
|
+
self.emulate_dates_by_column_name = true
|
198
|
+
|
199
|
+
# true and false will be stored as 'Y' and 'N'
|
200
|
+
self.emulate_booleans_from_strings = true
|
201
|
+
|
202
|
+
# start primary key sequences from 1 (and not 10000) and take just one next value in each session
|
203
|
+
self.default_sequence_start_value = "1 NOCACHE INCREMENT BY 1"
|
204
|
+
|
205
|
+
# other settings ...
|
206
|
+
end
|
207
|
+
end
|
208
|
+
```
|
171
209
|
|
172
210
|
In case of Rails 2 application you do not need to use `ActiveSupport.on_load(:active_record) do ... end` around settings code block.
|
173
211
|
|
@@ -177,81 +215,108 @@ See other adapter settings in [oracle_enhanced_adapter.rb](http://github.com/rsi
|
|
177
215
|
|
178
216
|
If you want to put Oracle enhanced adapter on top of existing schema tables then there are several methods how to override ActiveRecord defaults, see example:
|
179
217
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
218
|
+
```ruby
|
219
|
+
class Employee < ActiveRecord::Base
|
220
|
+
# specify schema and table name
|
221
|
+
self.table_name = "hr.hr_employees"
|
222
|
+
|
223
|
+
# specify primary key name
|
224
|
+
self.primary_key = "employee_id"
|
225
|
+
|
226
|
+
# specify sequence name
|
227
|
+
self.sequence_name = "hr.hr_employee_s"
|
228
|
+
|
229
|
+
# set which DATE columns should be converted to Ruby Date
|
230
|
+
set_date_columns :hired_on, :birth_date_on
|
231
|
+
|
232
|
+
# set which DATE columns should be converted to Ruby Time
|
233
|
+
set_datetime_columns :last_login_time
|
234
|
+
|
235
|
+
# set which VARCHAR2 columns should be converted to true and false
|
236
|
+
set_boolean_columns :manager, :active
|
237
|
+
|
238
|
+
# set which columns should be ignored in ActiveRecord
|
239
|
+
ignore_table_columns :attribute1, :attribute2
|
240
|
+
end
|
241
|
+
```
|
196
242
|
|
197
243
|
You can also access remote tables over database link using
|
198
244
|
|
199
|
-
|
245
|
+
```ruby
|
246
|
+
self.table_name "hr_employees@db_link"
|
247
|
+
```
|
200
248
|
|
201
249
|
Examples for Rails 3.2 and lower version of Rails
|
202
250
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
251
|
+
```ruby
|
252
|
+
class Employee < ActiveRecord::Base
|
253
|
+
# specify schema and table name
|
254
|
+
set_table_name "hr.hr_employees"
|
255
|
+
|
256
|
+
# specify primary key name
|
257
|
+
set_primary_key "employee_id"
|
258
|
+
|
259
|
+
# specify sequence name
|
260
|
+
set_sequence_name "hr.hr_employee_s"
|
261
|
+
|
262
|
+
# set which DATE columns should be converted to Ruby Date
|
263
|
+
set_date_columns :hired_on, :birth_date_on
|
264
|
+
|
265
|
+
# set which DATE columns should be converted to Ruby Time
|
266
|
+
set_datetime_columns :last_login_time
|
267
|
+
|
268
|
+
# set which VARCHAR2 columns should be converted to true and false
|
269
|
+
set_boolean_columns :manager, :active
|
270
|
+
|
271
|
+
# set which columns should be ignored in ActiveRecord
|
272
|
+
ignore_table_columns :attribute1, :attribute2
|
273
|
+
end
|
274
|
+
```
|
219
275
|
|
220
276
|
You can also access remote tables over database link using
|
221
277
|
|
222
|
-
|
278
|
+
```ruby
|
279
|
+
set_table_name "hr_employees@db_link"
|
280
|
+
```
|
223
281
|
|
224
282
|
### Custom create, update and delete methods
|
225
283
|
|
226
284
|
If you have legacy schema and you are not allowed to do direct INSERTs, UPDATEs and DELETEs in legacy schema tables and need to use existing PL/SQL procedures for create, updated, delete operations then you should add `ruby-plsql` gem to your application, include `ActiveRecord::OracleEnhancedProcedures` in your model and then define custom create, update and delete methods, see example:
|
227
285
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
286
|
+
```ruby
|
287
|
+
class Employee < ActiveRecord::Base
|
288
|
+
include ActiveRecord::OracleEnhancedProcedures
|
289
|
+
|
290
|
+
# when defining create method then return ID of new record that will be assigned to id attribute of new object
|
291
|
+
set_create_method do
|
292
|
+
plsql.employees_pkg.create_employee(
|
293
|
+
:p_first_name => first_name,
|
294
|
+
:p_last_name => last_name,
|
295
|
+
:p_employee_id => nil
|
296
|
+
)[:p_employee_id]
|
297
|
+
end
|
298
|
+
|
299
|
+
set_update_method do
|
300
|
+
plsql.employees_pkg.update_employee(
|
301
|
+
:p_employee_id => id,
|
302
|
+
:p_first_name => first_name,
|
303
|
+
:p_last_name => last_name
|
304
|
+
)
|
305
|
+
end
|
306
|
+
|
307
|
+
set_delete_method do
|
308
|
+
plsql.employees_pkg.delete_employee(
|
309
|
+
:p_employee_id => id
|
310
|
+
)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
```
|
251
314
|
|
252
315
|
In addition in `config/initializers/oracle.rb` initializer specify that ruby-plsql should use ActiveRecord database connection:
|
253
316
|
|
254
|
-
|
317
|
+
```ruby
|
318
|
+
plsql.activerecord_class = ActiveRecord::Base
|
319
|
+
```
|
255
320
|
|
256
321
|
### Oracle CONTEXT index support
|
257
322
|
|
@@ -259,60 +324,78 @@ Every edition of Oracle database includes [Oracle Text](http://www.oracle.com/te
|
|
259
324
|
|
260
325
|
To create simple single column index create migration with, e.g.
|
261
326
|
|
262
|
-
|
327
|
+
```ruby
|
328
|
+
add_context_index :posts, :title
|
329
|
+
```
|
263
330
|
|
264
331
|
and you can remove context index with
|
265
332
|
|
266
|
-
|
333
|
+
```ruby
|
334
|
+
remove_context_index :posts, :title
|
335
|
+
```
|
267
336
|
|
268
337
|
Include in class definition
|
269
338
|
|
270
|
-
|
339
|
+
```ruby
|
340
|
+
has_context_index
|
341
|
+
```
|
271
342
|
|
272
343
|
and then you can do full text search with
|
273
344
|
|
274
|
-
|
345
|
+
```ruby
|
346
|
+
Post.contains(:title, 'word')
|
347
|
+
```
|
275
348
|
|
276
349
|
You can create index on several columns (which will generate additional stored procedure for providing XML document with specified columns to indexer):
|
277
350
|
|
278
|
-
|
351
|
+
```ruby
|
352
|
+
add_context_index :posts, [:title, :body]
|
353
|
+
```
|
279
354
|
|
280
355
|
And you can search either in all columns or specify in which column you want to search (as first argument you need to specify first column name as this is the column which is referenced during index creation):
|
281
356
|
|
282
|
-
|
283
|
-
|
284
|
-
|
357
|
+
```ruby
|
358
|
+
Post.contains(:title, 'word')
|
359
|
+
Post.contains(:title, 'word within title')
|
360
|
+
Post.contains(:title, 'word within body')
|
361
|
+
```
|
285
362
|
|
286
363
|
See Oracle Text documentation for syntax that you can use in CONTAINS function in SELECT WHERE clause.
|
287
364
|
|
288
365
|
You can also specify some dummy main column name when creating multiple column index as well as specify to update index automatically after each commit (as otherwise you need to synchronize index manually or schedule periodic update):
|
289
366
|
|
290
|
-
|
367
|
+
```ruby
|
368
|
+
add_context_index :posts, [:title, :body], :index_column => :all_text, :sync => 'ON COMMIT'
|
291
369
|
|
292
|
-
|
370
|
+
Post.contains(:all_text, 'word')
|
371
|
+
```
|
293
372
|
|
294
373
|
Or you can specify that index should be updated when specified columns are updated (e.g. in ActiveRecord you can specify to trigger index update when created_at or updated_at columns are updated). Otherwise index is updated only when main index column is updated.
|
295
374
|
|
296
|
-
|
297
|
-
|
375
|
+
```ruby
|
376
|
+
add_context_index :posts, [:title, :body], :index_column => :all_text,
|
377
|
+
:sync => 'ON COMMIT', :index_column_trigger_on => [:created_at, :updated_at]
|
378
|
+
```
|
298
379
|
|
299
380
|
And you can even create index on multiple tables by providing SELECT statements which should be used to fetch necessary columns from related tables:
|
300
381
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
382
|
+
```ruby
|
383
|
+
add_context_index :posts,
|
384
|
+
[:title, :body,
|
385
|
+
# specify aliases always with AS keyword
|
386
|
+
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
387
|
+
],
|
388
|
+
:name => 'post_and_comments_index',
|
389
|
+
:index_column => :all_text,
|
390
|
+
:index_column_trigger_on => [:updated_at, :comments_count],
|
391
|
+
:sync => 'ON COMMIT'
|
392
|
+
|
393
|
+
# search in any table columns
|
394
|
+
Post.contains(:all_text, 'word')
|
395
|
+
# search in specified column
|
396
|
+
Post.contains(:all_text, "aaa within title")
|
397
|
+
Post.contains(:all_text, "bbb within comment_author")
|
398
|
+
```
|
316
399
|
|
317
400
|
### Oracle virtual columns support
|
318
401
|
|
@@ -321,43 +404,53 @@ They can be used as normal fields in the queries, in the foreign key contstraint
|
|
321
404
|
|
322
405
|
To define virtual column you can use `virtual` method in the `create_table` block, providing column expression in the `:as` option:
|
323
406
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
407
|
+
```ruby
|
408
|
+
create_table :mytable do |t|
|
409
|
+
t.decimal :price, :precision => 15, :scale => 2
|
410
|
+
t.decimal :quantity, :precision => 15, :scale => 2
|
411
|
+
t.virtual :amount, :as => 'price * quantity'
|
412
|
+
end
|
413
|
+
```
|
329
414
|
|
330
415
|
Oracle tries to predict type of the virtual column, based on its expression but sometimes it is necessary to state type explicitly.
|
331
416
|
This can be done by providing `:type` option to the `virtual` method:
|
332
417
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
418
|
+
```ruby
|
419
|
+
# ...
|
420
|
+
t.virtual :amount_2, :as => 'ROUND(price * quantity,2)', :type => :decimal, :precision => 15, :scale => 2
|
421
|
+
t.virtual :amount_str, :as => "TO_CHAR(quantity) || ' x ' || TO_CHAR(price) || ' USD = ' || TO_CHAR(quantity*price) || ' USD'",
|
422
|
+
:type => :string, :limit => 100
|
423
|
+
# ...
|
424
|
+
```
|
338
425
|
|
339
426
|
It is possible to add virtual column to existing table:
|
340
427
|
|
341
|
-
|
428
|
+
```ruby
|
429
|
+
add_column :mytable, :amount_4, :virtual, :as => 'ROUND(price * quantity,4)', :precision => 38, :scale => 4
|
430
|
+
```
|
342
431
|
|
343
432
|
You can use the same options here as in the `create_table` `virtual` method.
|
344
433
|
|
345
434
|
Changing virtual columns is also possible:
|
346
435
|
|
347
|
-
|
436
|
+
```ruby
|
437
|
+
change_column :mytable, :amount, :virtual, :as => 'ROUND(price * quantity,0)', :type => :integer
|
438
|
+
```
|
348
439
|
|
349
440
|
Virtual columns allowed in the foreign key constraints.
|
350
441
|
For example it can be used to force foreign key constraint on polymorphic association:
|
351
442
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
443
|
+
```ruby
|
444
|
+
create_table :comments do |t|
|
445
|
+
t.string :subject_type
|
446
|
+
t.integer :subject_id
|
447
|
+
t.virtual :subject_photo_id, :as => "CASE subject_type WHEN 'Photo' THEN subject_id END"
|
448
|
+
t.virtual :subject_event_id, :as => "CASE subject_type WHEN 'Event' THEN subject_id END"
|
449
|
+
end
|
358
450
|
|
359
|
-
|
360
|
-
|
451
|
+
add_foreign_key :comments, :photos, :column => :subject_photo_id
|
452
|
+
add_foreign_key :comments, :events, :column => :subject_event_id
|
453
|
+
```
|
361
454
|
|
362
455
|
For backward compatibility reasons it is possible to use `:default` option in the `create_table` instead of `:as` option.
|
363
456
|
But this is deprecated and may be removed in the future version.
|
@@ -373,8 +466,10 @@ There are several additional schema statements and data types available that you
|
|
373
466
|
* You can add table and column comments with `:comment` option
|
374
467
|
* Default tablespaces can be specified for tables, indexes, clobs and blobs, for example:
|
375
468
|
|
376
|
-
|
377
|
-
|
469
|
+
```ruby
|
470
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces =
|
471
|
+
{:clob => 'TS_LOB', :blob => 'TS_LOB', :index => 'TS_INDEX', :table => 'TS_DATA'}
|
472
|
+
```
|
378
473
|
|
379
474
|
TROUBLESHOOTING
|
380
475
|
---------------
|
@@ -395,13 +490,15 @@ Please verify that
|
|
395
490
|
|
396
491
|
3. Verify that activerecord-oracle_enhanced-adapter is working from irb
|
397
492
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
493
|
+
```ruby
|
494
|
+
require 'rubygems'
|
495
|
+
gem 'activerecord'
|
496
|
+
gem 'activerecord-oracle_enhanced-adapter'
|
497
|
+
require 'active_record'
|
498
|
+
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")
|
499
|
+
```
|
403
500
|
|
404
|
-
|
501
|
+
and see if it is successful (use your correct database, username and password)
|
405
502
|
|
406
503
|
### What to do if Oracle enhanced adapter is not working with Phusion Passenger?
|
407
504
|
|