Commit 07aa9566 by Tom Wilkie Committed by GitHub

Add option in database config to skip migrations for faster startup. (#30146)

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
parent bfcb8a47
...@@ -87,18 +87,20 @@ func (ss *SQLStore) Init() error { ...@@ -87,18 +87,20 @@ func (ss *SQLStore) Init() error {
x = ss.engine x = ss.engine
dialect = ss.Dialect dialect = ss.Dialect
migrator := migrator.NewMigrator(ss.engine) if !ss.dbCfg.SkipMigrations {
migrations.AddMigrations(migrator) migrator := migrator.NewMigrator(ss.engine)
migrations.AddMigrations(migrator)
for _, descriptor := range registry.GetServices() {
sc, ok := descriptor.Instance.(registry.DatabaseMigrator) for _, descriptor := range registry.GetServices() {
if ok { sc, ok := descriptor.Instance.(registry.DatabaseMigrator)
sc.AddMigration(migrator) if ok {
sc.AddMigration(migrator)
}
} }
}
if err := migrator.Start(); err != nil { if err := migrator.Start(); err != nil {
return err return err
}
} }
// Init repo instances // Init repo instances
...@@ -388,6 +390,7 @@ func (ss *SQLStore) readConfig() { ...@@ -388,6 +390,7 @@ func (ss *SQLStore) readConfig() {
ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db") ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db")
ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private") ss.dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
ss.dbCfg.SkipMigrations = sec.Key("skip_migrations").MustBool()
} }
// ITestDB is an interface of arguments for testing db // ITestDB is an interface of arguments for testing db
...@@ -525,4 +528,5 @@ type DatabaseConfig struct { ...@@ -525,4 +528,5 @@ type DatabaseConfig struct {
ConnMaxLifetime int ConnMaxLifetime int
CacheMode string CacheMode string
UrlQueryParams map[string][]string UrlQueryParams map[string][]string
SkipMigrations bool
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment