Class: DBGeni::Migrator::Oracle
- Inherits:
-
MigratorInterface
- Object
- MigratorInterface
- DBGeni::Migrator::Oracle
- Defined in:
- lib/dbgeni/migrators/oracle.rb
Instance Attribute Summary
Attributes inherited from MigratorInterface
Instance Method Summary collapse
- #code_errors ⇒ Object
-
#compile(code, force = false) ⇒ Object
def verify(migration) end.
-
#initialize(config, connection) ⇒ Oracle
constructor
A new instance of Oracle.
-
#migration_errors ⇒ Object
def rollback(migration, force=nil) end.
- #remove(code, force = false) ⇒ Object
Methods inherited from MigratorInterface
Constructor Details
#initialize(config, connection) ⇒ Oracle
Returns a new instance of Oracle.
6 7 8 |
# File 'lib/dbgeni/migrators/oracle.rb', line 6 def initialize(config, connection) super(config, connection) end |
Instance Method Details
#code_errors ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dbgeni/migrators/oracle.rb', line 62 def code_errors # The error part of the file file either looks like: # SQL> show err # No errors. # SQL> spool off # or # SQL> show err # Errors for PACKAGE BODY PKG1: # LINE/COL ERROR # -------- ----------------------------------------------------------------- # 5/1 PLS-00103: Encountered the symbol "END" when expecting one of the # following: # Error messages here # SQL> spool off # In the first case, return nil, but in the second case get everything after show err error_msg = '' start_search = false File.open(@logfile, 'r').each_line do |l| if !start_search && l =~ /^SQL> show err/ start_search = true next end if start_search if l =~ /^No errors\./ error_msg = nil break elsif l =~ /^SQL> spool off/ break else error_msg << l end end end error_msg end |
#compile(code, force = false) ⇒ Object
def verify(migration) end
48 49 50 |
# File 'lib/dbgeni/migrators/oracle.rb', line 48 def compile(code, force=false) run_in_client(code.runnable_code, force, true) end |
#migration_errors ⇒ Object
def rollback(migration, force=nil) end
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dbgeni/migrators/oracle.rb', line 16 def migration_errors has_errors = false buffer = [] begin File.open(@logfile, 'r').each_line do |l| buffer.push l if buffer.length > 10 buffer.shift end if !has_errors && l =~ /^ERROR at line/ has_errors = true next end # After we find the ERROR at line, the next line contains the error # message, so we just want to consume it and then exit. # The line we care about will be in the buffer, so just break and join # the buffer. if has_errors break end end rescue Errno::ENOENT # assume this means the log was never written as, generally because # sqlplus didn't connect to Oracle. In this case do nothing end buffer.join("") end |
#remove(code, force = false) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/dbgeni/migrators/oracle.rb', line 52 def remove(code, force=false) begin @connection.execute(drop_command(code)) rescue Exception => e unless e.to_s =~ /(object|trigger) .+ does not exist/ raise DBGeni::CodeRemoveFailed, e.to_s end end end |