@@ -361,7 +361,7 @@ func (m *Mysql) SetVersion(version int, dirty bool) error {
361361 return & database.Error {OrigErr : err , Err : "transaction start failed" }
362362 }
363363
364- query := "DELETE FROM `" + m .config .MigrationsTable + "` LIMIT 1"
364+ query := fmt . Sprintf ( "DELETE FROM `%s`.`%s` LIMIT 1" , m . config . DatabaseName , m .config .MigrationsTable )
365365 if _ , err := tx .ExecContext (context .Background (), query ); err != nil {
366366 if errRollback := tx .Rollback (); errRollback != nil {
367367 err = multierror .Append (err , errRollback )
@@ -373,7 +373,7 @@ func (m *Mysql) SetVersion(version int, dirty bool) error {
373373 // empty schema version for failed down migration on the first migration
374374 // See: https://github.com/golang-migrate/migrate/issues/330
375375 if version >= 0 || (version == database .NilVersion && dirty ) {
376- query := "INSERT INTO `" + m . config . MigrationsTable + "` (version, dirty) VALUES (?, ?)"
376+ query := fmt . Sprintf ( "INSERT INTO `%s`.`%s` (version, dirty) VALUES (?, ?)" , m . config . DatabaseName , m . config . MigrationsTable )
377377 if _ , err := tx .ExecContext (context .Background (), query , version , dirty ); err != nil {
378378 if errRollback := tx .Rollback (); errRollback != nil {
379379 err = multierror .Append (err , errRollback )
@@ -390,7 +390,7 @@ func (m *Mysql) SetVersion(version int, dirty bool) error {
390390}
391391
392392func (m * Mysql ) Version () (version int , dirty bool , err error ) {
393- query := "SELECT version, dirty FROM `" + m .config .MigrationsTable + "` LIMIT 1"
393+ query := fmt . Sprintf ( "SELECT version, dirty FROM `%s`.`%s` LIMIT 1" , m . config . DatabaseName , m .config .MigrationsTable )
394394 err = m .conn .QueryRowContext (context .Background (), query ).Scan (& version , & dirty )
395395 switch {
396396 case err == sql .ErrNoRows :
@@ -411,7 +411,7 @@ func (m *Mysql) Version() (version int, dirty bool, err error) {
411411
412412func (m * Mysql ) Drop () (err error ) {
413413 // select all tables
414- query := ` SHOW TABLES LIKE '%'`
414+ query := fmt . Sprintf ( " SHOW TABLES FROM `%s` LIKE '%'" , m . config . DatabaseName )
415415 tables , err := m .conn .QueryContext (context .Background (), query )
416416 if err != nil {
417417 return & database.Error {OrigErr : err , Query : []byte (query )}
@@ -451,7 +451,7 @@ func (m *Mysql) Drop() (err error) {
451451
452452 // delete one by one ...
453453 for _ , t := range tableNames {
454- query = "DROP TABLE IF EXISTS `" + t + "`"
454+ query = fmt . Sprintf ( "DROP TABLE IF EXISTS `%s`.`%s`" , m . config . DatabaseName , t )
455455 if _ , err := m .conn .ExecContext (context .Background (), query ); err != nil {
456456 return & database.Error {OrigErr : err , Query : []byte (query )}
457457 }
@@ -481,7 +481,7 @@ func (m *Mysql) ensureVersionTable() (err error) {
481481
482482 // check if migration table exists
483483 var result string
484- query := ` SHOW TABLES LIKE '` + m .config .MigrationsTable + `'`
484+ query := fmt . Sprintf ( " SHOW TABLES FROM `%s` LIKE '%s'" , m . config . DatabaseName , m .config .MigrationsTable )
485485 if err := m .conn .QueryRowContext (context .Background (), query ).Scan (& result ); err != nil {
486486 if err != sql .ErrNoRows {
487487 return & database.Error {OrigErr : err , Query : []byte (query )}
@@ -491,7 +491,7 @@ func (m *Mysql) ensureVersionTable() (err error) {
491491 }
492492
493493 // if not, create the empty migration table
494- query = "CREATE TABLE `" + m . config . MigrationsTable + "` (version bigint not null primary key, dirty boolean not null)"
494+ query = fmt . Sprintf ( "CREATE TABLE `%s`.`%s` (version bigint not null primary key, dirty boolean not null)" , m . config . DatabaseName , m . config . MigrationsTable )
495495 if _ , err := m .conn .ExecContext (context .Background (), query ); err != nil {
496496 return & database.Error {OrigErr : err , Query : []byte (query )}
497497 }
0 commit comments