Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c944619

Browse files
committed
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.
1 parent 150ce9b commit c944619

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

driver/mysql/mysql.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ func (driver *Driver) Close() error {
5050
}
5151

5252
func (driver *Driver) ensureVersionTableExists() error {
53-
if _, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);"); err != nil {
53+
_, err := driver.db.Exec("CREATE TABLE IF NOT EXISTS " + tableName + " (version int not null primary key);")
54+
55+
if _, isWarn := err.(mysql.MySQLWarnings); err != nil && !isWarn {
5456
return err
5557
}
58+
5659
return nil
5760
}
5861

0 commit comments

Comments
 (0)