Class: DBGeni::Migrator::Mysql

Inherits:
MigratorInterface show all
Defined in:
lib/dbgeni/migrators/mysql.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) ⇒ Mysql

Returns a new instance of Mysql.


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

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

Instance Method Details

#code_errorsObject


42
43
44
45
46
47
48
49
# File 'lib/dbgeni/migrators/mysql.rb', line 42

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

#migration_errorsObject

def rollback(migration, force=nil) end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dbgeni/migrators/mysql.rb', line 17

def migration_errors
  error = ''
  # MYSQL prints the errors at the start of the log file
  begin
    fh = File.open(@logfile, 'r')
    error = fh.readline
    unless error =~ /^ERROR/
      error = ''
    end
  ensure
    fh.close if fh
  end
  error
end

#remove(code, force = false) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'lib/dbgeni/migrators/mysql.rb', line 32

def remove(code, force=false)
  begin
    @connection.execute(drop_command(code))
  rescue Exception => e
    unless e.to_s =~ /(procedure|function|trigger).+does not exist/i
      raise DBGeni::CodeRemoveFailed, e.to_s
    end
  end
end