mirror of https://github.com/grafana/grafana.git
				
				
				
			Skip noop migrations, instead of executing SELECT 0. (#103086)
* Skip noop migrations, instead of executing SELECT 0.
This commit is contained in:
		
							parent
							
								
									f0a6327edc
								
							
						
					
					
						commit
						f7f28757f6
					
				|  | @ -74,7 +74,6 @@ type Dialect interface { | |||
| 
 | ||||
| 	CleanDB(engine *xorm.Engine) error | ||||
| 	TruncateDBTables(engine *xorm.Engine) error | ||||
| 	NoOpSQL() string | ||||
| 	// CreateDatabaseFromSnapshot is called when migration log table is not found.
 | ||||
| 	// Dialect can recreate all tables from existing snapshot. After successful (nil error) return,
 | ||||
| 	// migrator will list migrations from the log, and apply all missing migrations.
 | ||||
|  | @ -353,10 +352,6 @@ func (b *BaseDialect) CreateDatabaseFromSnapshot(ctx context.Context, engine *xo | |||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (b *BaseDialect) NoOpSQL() string { | ||||
| 	return "SELECT 0;" | ||||
| } | ||||
| 
 | ||||
| func (b *BaseDialect) TruncateDBTables(engine *xorm.Engine) error { | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
|  | @ -53,7 +53,7 @@ func (m *RawSQLMigration) SQL(dialect Dialect) string { | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return dialect.NoOpSQL() | ||||
| 	return "" | ||||
| } | ||||
| 
 | ||||
| func (m *RawSQLMigration) Set(dialect string, sql string) *RawSQLMigration { | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ import ( | |||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| 
 | ||||
| 	_ "github.com/go-sql-driver/mysql" | ||||
|  | @ -392,8 +393,12 @@ func (mg *Migrator) exec(ctx context.Context, m Migration, sess *xorm.Session) e | |||
| 		err = codeMigration.Exec(sess, mg) | ||||
| 	} else { | ||||
| 		sql := m.SQL(mg.Dialect) | ||||
| 		logger.Debug("Executing sql migration", "id", m.Id(), "sql", sql) | ||||
| 		_, err = sess.Exec(sql) | ||||
| 		if strings.TrimSpace(sql) == "" { | ||||
| 			logger.Debug("Skipping empty sql migration", "id", m.Id()) | ||||
| 		} else { | ||||
| 			logger.Debug("Executing sql migration", "id", m.Id(), "sql", sql) | ||||
| 			_, err = sess.Exec(sql) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if err != nil { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue