Module: ActiveRecord::ConnectionAdapters::OracleEnhancedSchemaStatementsExt

Defined in:
lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb

Instance Method Summary collapse

Instance Method Details

#add_primary_key_trigger(table_name, options = {}) ⇒ Object

Create primary key trigger (so that you can skip primary key value in INSERT statement). By default trigger name will be “table_name_pkt”, you can override the name with :trigger_name option (but it is not recommended to override it as then this trigger will not be detected by ActiveRecord model and it will still do prefetching of sequence value).

add_primary_key_trigger :users

You can also create primary key trigger using create_table with :primary_key_trigger option:

create_table :users, :primary_key_trigger => true do |t|
  # ...
end

20
21
22
23
# File 'lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb', line 20

def add_primary_key_trigger(table_name, options={})
  # call the same private method that is used for create_table :primary_key_trigger => true
  create_primary_key_trigger(table_name, options)
end

#add_synonym(name, table_name, options = {}) ⇒ Object

Add synonym to existing table or view or sequence. Can be used to create local synonym to remote table in other schema or in other database Examples:

add_synonym :posts, "blog.posts"
add_synonym :posts_seq, "blog.posts_seq"
add_synonym :employees, "[email protected]", :force => true

33
34
35
36
37
38
39
40
# File 'lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb', line 33

def add_synonym(name, table_name, options = {})
  sql = "CREATE"
  if options[:force] == true
    sql << " OR REPLACE"
  end
  sql << " SYNONYM #{quote_table_name(name)} FOR #{quote_table_name(table_name)}"
  execute sql
end

#remove_synonym(name) ⇒ Object

Remove existing synonym to table or view or sequence Example:

remove_synonym :posts, "blog.posts"

47
48
49
# File 'lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb', line 47

def remove_synonym(name)
  execute "DROP SYNONYM #{quote_table_name(name)}"
end

#synonymsObject

get synonyms for schema dump


52
53
54
55
56
57
# File 'lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb', line 52

def synonyms #:nodoc:
  select_all("SELECT synonym_name, table_owner, table_name, db_link FROM user_synonyms").collect do |row|
    OracleEnhanced::SynonymDefinition.new(oracle_downcase(row['synonym_name']),
      oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
  end
end