Class: ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/oracle-enhanced-enhanced.rb

Constant Summary collapse

VARCHAR2_MAX_LENGTH =

Maximum length of an Oracle VARCHAR2 field

4000
INTEGER_LENGTH =

Default length of an Oracle integer field (as opposed to NUMBER(38))

12

Class Method Summary collapse

Class Method Details

.set_enhanced_defaultsObject

Enable our enhanced settings/defaults



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oracle-enhanced-enhanced.rb', line 30

def self.set_enhanced_defaults
  # Use sane length for PK/FK fields
  NATIVE_DATABASE_TYPES[:primary_key] = "NUMBER(#{INTEGER_LENGTH}) NOT NULL PRIMARY KEY"
  NATIVE_DATABASE_TYPES[:integer][:limit] = INTEGER_LENGTH

  # Use varchar2(4000) for TEXT fields
  set_text_storage_representation true

  # Cache columns because we don't need to hit the database to check metadata all the time.
  # This requires that you restart your server when developing if your models change.
  #TODO: should we disable this for development?
  self.cache_columns = true

  # Oracle's default sequence behaviour doesn't appeal to us OCD freaks who prefer monotonically increasing sequences
  self.default_sequence_start_value = "1 NOCACHE ORDER"
end

.set_text_storage_representation(use_varchar2, length = VARCHAR2_MAX_LENGTH) ⇒ Object

Indicate whether to use varchar2(length) for TEXT columns or clob (default). Pass true or false to select varchar2 or clob, respectively. Optionally pass in the desired varchar2 length.



15
16
17
# File 'lib/oracle-enhanced-enhanced.rb', line 15

def self.set_text_storage_representation(use_varchar2, length = VARCHAR2_MAX_LENGTH)
  NATIVE_DATABASE_TYPES[:text] = use_varchar2 ? {:name => 'VARCHAR2', :limit => length} : {:name => 'CLOB'}
end