From c94461932f496ede74dee6baba81f46e58e6db5c Mon Sep 17 00:00:00 2001 From: Rodrigo Kochenburger Date: Thu, 4 Dec 2014 13:49:26 -0800 Subject: [PATCH] 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. --- driver/mysql/mysql.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/driver/mysql/mysql.go b/driver/mysql/mysql.go index 81bc7a4..c264f3d 100644 --- a/driver/mysql/mysql.go +++ b/driver/mysql/mysql.go @@ -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 }