Class: ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DatabaseTasks
- Defined in:
- lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb
Instance Method Summary collapse
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(config) ⇒ DatabaseTasks
constructor
A new instance of DatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename, extra_flags) ⇒ Object
- #structure_load(filename, extra_flags) ⇒ Object
Constructor Details
#initialize(config) ⇒ DatabaseTasks
Returns a new instance of DatabaseTasks.
11 12 13 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 11 def initialize(config) @config = config end |
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 15 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 /ORA-01920/.match?(e.) # user name conflicts with another user or role name connection.execute "ALTER USER #{@config[:username]} IDENTIFIED BY #{@config[:password]}" else raise e end end OracleEnhancedAdapter..each do || connection.execute "GRANT #{} TO #{@config[:username]}" end end |
#drop ⇒ Object
36 37 38 39 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 36 def drop establish_connection(@config) connection.execute_structure_dump(connection.full_drop) end |
#purge ⇒ Object
41 42 43 44 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 41 def purge drop connection.execute("PURGE RECYCLEBIN") rescue nil end |
#structure_dump(filename, extra_flags) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 46 def structure_dump(filename, extra_flags) 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, extra_flags) ⇒ Object
54 55 56 57 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb', line 54 def structure_load(filename, extra_flags) establish_connection(@config) connection.execute_structure_dump(File.read(filename)) end |