Class: DBGeni::Migrator::Sybase

Inherits:
MigratorInterface show all
Defined in:
lib/dbgeni/migrators/sybase.rb

Instance Attribute Summary

Attributes inherited from MigratorInterface

#logfile

Instance Method Summary collapse

Methods inherited from MigratorInterface

#apply, #compile, #rollback, #verify

Constructor Details

#initialize(config, connection) ⇒ Sybase

Returns a new instance of Sybase.

[View source]

6
7
8
# File 'lib/dbgeni/migrators/sybase.rb', line 6

def initialize(config, connection)
  super(config, connection)
end

Instance Method Details

#code_errorsObject

[View source]

60
61
62
63
64
65
66
67
# File 'lib/dbgeni/migrators/sybase.rb', line 60

def code_errors
  # In sybase the code errors are just the same as migration errors
  errors = migration_errors
  if errors == ''
    errors = nil
  end
  errors
end

#migration_errorsObject

def rollback(migration, force=nil) end

[View source]

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
44
45
# File 'lib/dbgeni/migrators/sybase.rb', line 17

def migration_errors
  error = ''
  # The first error is the one to report - with sybase isql doesn't stop on errors
  # The error lines tend to look like:
  # Msg 156, Level 15, State 2:
  # Server 'WW637L18714A', Line 2:
  # Incorrect syntax near the keyword 'table'.
  begin
    fh = File.open(@logfile, 'r')
    # search for a line starting Msg or Error and then grab the next 2 lines to make up the error.
    while (l = fh.readline)
      if l =~ /^(Msg|Error)\s\d+/
        error = l
        break
      end
    end
    unless error == ''
      # if an error was found, add the next two lines to the error message
      error << fh.readline
      error << fh.readline
    end
  rescue ::EOFError
    # reached the end of file before a full error message was found ...
    # Just catch and move on ...
  ensure
    fh.close if fh
  end
  error
end

#remove(code, force = false) ⇒ Object

def verify(migration) end

[View source]

50
51
52
53
54
55
56
57
58
# File 'lib/dbgeni/migrators/sybase.rb', line 50

def remove(code, force=false)
  begin
    @connection.execute(drop_command(code))
  rescue Exception => e
    unless e.to_s =~ /Cannot drop the .*(procedure|function|trigger).+exist in the system catalogs/i
      raise DBGeni::CodeRemoveFailed, e.to_s
    end
  end
end