Prevents MySQL driver to failing when version table alredy exists

The MySQL driver is using `CREATE TABLE IF NOT EXISTS`, which causes
the MySQL database to raise warnings. The golang driver collects
the warnings and return a composite object (mysql.MySQLWarnings) as
an error that needs to be properly handled.

This change stops the driver from failing in case there are only
warnings.
This commit is contained in:
Rodrigo Kochenburger 2014-12-04 13:49:26 -08:00
parent 150ce9b524
commit c94461932f
1 changed files with 4 additions and 1 deletions

View File

@ -50,9 +50,12 @@ func (driver *Driver) Close() error {
}
func (driver *Driver) ensureVersionTableExists() error {
if _, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);"); err != nil {
_, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);")
if _, isWarn := err.(mysql.MySQLWarnings); err != nil && !isWarn {
return err
}
return nil
}