Class: ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DatabaseTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DatabaseTasks



9
10
11
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 9

def initialize(config)
  @config = config
end

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 13

def create
  system_password = ENV.fetch('ORACLE_SYSTEM_PASSWORD') {
    print "Please provide the SYSTEM password for your Oracle installation (set ORACLE_SYSTEM_PASSWORD to avoid this prompt)\n>"
    $stdin.gets.strip
  }
  establish_connection(@config.merge('username' => 'SYSTEM', 'password' => system_password))
  begin
    connection.execute "CREATE USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
  rescue => e
    if e.message =~ /ORA-01920/ # user name conflicts with another user or role name
      connection.execute "ALTER USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
    else
      raise e
    end
  end
  connection.execute "GRANT unlimited tablespace TO #{@config['username']}"
  connection.execute "GRANT create session TO #{@config['username']}"
  connection.execute "GRANT create table TO #{@config['username']}"
  connection.execute "GRANT create view TO #{@config['username']}"
  connection.execute "GRANT create sequence TO #{@config['username']}"
end

#dropObject



35
36
37
38
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 35

def drop
  establish_connection(@config)
  connection.execute_structure_dump(connection.full_drop)
end

#purgeObject



40
41
42
43
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 40

def purge
  drop
  connection.execute('PURGE RECYCLEBIN') rescue nil
end

#structure_dump(filename) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 45

def structure_dump(filename)
  establish_connection(@config)
  File.open(filename, 'w:utf-8') { |f| f << connection.structure_dump }
  if @config['structure_dump'] == 'db_stored_code'
     File.open(filename, 'a') { |f| f << connection.structure_dump_db_stored_code }
  end
end

#structure_load(filename) ⇒ Object



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

def structure_load(filename)
  establish_connection(@config)
  connection.execute_structure_dump(File.read(filename))
end