Don't consider warnings as errors

This commit is contained in:
Rodrigo Kochenburger 2014-12-04 13:59:40 -08:00
parent c94461932f
commit 6bce23e36a
1 changed files with 36 additions and 34 deletions

View File

@ -105,46 +105,48 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
for _, sqlStmt := range sqlStmts {
if len(bytes.TrimSpace(sqlStmt)) > 0 {
if _, err := tx.Exec(string(sqlStmt)); err != nil {
mysqlErr := err.(*mysql.MySQLError)
mysqlErr, isErr := err.(*mysql.MySQLError)
re, err := regexp.Compile(`at line ([0-9]+)$`)
if err != nil {
pipe <- err
if err := tx.Rollback(); err != nil {
if isErr {
re, err := regexp.Compile(`at line ([0-9]+)$`)
if err != nil {
pipe <- err
}
}
var lineNo int
lineNoRe := re.FindStringSubmatch(mysqlErr.Message)
if len(lineNoRe) == 2 {
lineNo, err = strconv.Atoi(lineNoRe[1])
}
if err == nil {
// get white-space offset
// TODO this is broken, because we use sqlStmt instead of f.Content
wsLineOffset := 0
b := bufio.NewReader(bytes.NewBuffer(sqlStmt))
for {
line, _, err := b.ReadLine()
if err != nil {
break
}
if bytes.TrimSpace(line) == nil {
wsLineOffset += 1
} else {
break
if err := tx.Rollback(); err != nil {
pipe <- err
}
}
message := mysqlErr.Error()
message = re.ReplaceAllString(message, fmt.Sprintf("at line %v", lineNo+wsLineOffset))
var lineNo int
lineNoRe := re.FindStringSubmatch(mysqlErr.Message)
if len(lineNoRe) == 2 {
lineNo, err = strconv.Atoi(lineNoRe[1])
}
if err == nil {
errorPart := file.LinesBeforeAndAfter(sqlStmt, lineNo, 5, 5, true)
pipe <- errors.New(fmt.Sprintf("%s\n\n%s", message, string(errorPart)))
} else {
pipe <- errors.New(mysqlErr.Error())
// get white-space offset
// TODO this is broken, because we use sqlStmt instead of f.Content
wsLineOffset := 0
b := bufio.NewReader(bytes.NewBuffer(sqlStmt))
for {
line, _, err := b.ReadLine()
if err != nil {
break
}
if bytes.TrimSpace(line) == nil {
wsLineOffset += 1
} else {
break
}
}
message := mysqlErr.Error()
message = re.ReplaceAllString(message, fmt.Sprintf("at line %v", lineNo+wsLineOffset))
errorPart := file.LinesBeforeAndAfter(sqlStmt, lineNo, 5, 5, true)
pipe <- errors.New(fmt.Sprintf("%s\n\n%s", message, string(errorPart)))
} else {
pipe <- errors.New(mysqlErr.Error())
}
}
if err := tx.Rollback(); err != nil {