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

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
Tom Wilkie 2021-01-13 13:46:16 +00:00 committed by GitHub
parent bfcb8a477d
commit 07aa956667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,18 +87,20 @@ func (ss *SQLStore) Init() error {
x = ss.engine
dialect = ss.Dialect
migrator := migrator.NewMigrator(ss.engine)
migrations.AddMigrations(migrator)
if !ss.dbCfg.SkipMigrations {
migrator := migrator.NewMigrator(ss.engine)
migrations.AddMigrations(migrator)
for _, descriptor := range registry.GetServices() {
sc, ok := descriptor.Instance.(registry.DatabaseMigrator)
if ok {
sc.AddMigration(migrator)
for _, descriptor := range registry.GetServices() {
sc, ok := descriptor.Instance.(registry.DatabaseMigrator)
if ok {
sc.AddMigration(migrator)
}
}
}
if err := migrator.Start(); err != nil {
return err
if err := migrator.Start(); err != nil {
return err
}
}
// Init repo instances
@ -388,6 +390,7 @@ func (ss *SQLStore) readConfig() {
ss.dbCfg.Path = sec.Key("path").MustString("data/grafana.db")
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
@ -525,4 +528,5 @@ type DatabaseConfig struct {
ConnMaxLifetime int
CacheMode string
UrlQueryParams map[string][]string
SkipMigrations bool
}