k8s: remove dependency on app_mode development (#85474)
* k8s: remove dependency on app_mode development * remove dev conditions on storage server * remove logic to drop entity tables
This commit is contained in:
@@ -17,8 +17,6 @@ There are 2 main tables, the `entity` table stores a "current" view of the objec
|
||||
The minimum config settings required are:
|
||||
|
||||
```ini
|
||||
; dev mode is required
|
||||
app_mode = development
|
||||
; need to specify target here for override to work later
|
||||
target = all
|
||||
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/session"
|
||||
"github.com/grafana/grafana/pkg/services/store/entity/db"
|
||||
)
|
||||
|
||||
@@ -24,51 +20,7 @@ func MigrateEntityStore(db db.EntityDBInterface, features featuremgmt.FeatureTog
|
||||
mg := migrator.NewScopedMigrator(engine, db.GetCfg(), "entity")
|
||||
mg.AddCreateMigration()
|
||||
|
||||
marker := initEntityTables(mg)
|
||||
|
||||
// While this feature is under development, we can completly wipe and recreate
|
||||
// The initial plan is to keep the source of truth in existing SQL tables, and mirrot it
|
||||
// to a kubernetes model. Once the kubernetes model needs to be preserved,
|
||||
// this code should be removed
|
||||
exists, err := engine.IsTableExist("entity_migration_log")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
log, err := mg.GetMigrationLog()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, found := log[marker]
|
||||
if !found && len(log) > 0 {
|
||||
// Remove the migration log (and potential other orphan tables)
|
||||
tables := []string{"entity_migration_log"}
|
||||
|
||||
ctx := context.Background()
|
||||
sess, err := db.GetSession()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = sess.WithTransaction(ctx, func(tx *session.SessionTx) error {
|
||||
for _, t := range tables {
|
||||
_, err := tx.Exec(ctx, fmt.Sprintf("DROP TABLE IF EXISTS %s", t))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// remove old entries from in-memory log
|
||||
for id := range log {
|
||||
mg.RemoveMigrationLogs(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
initEntityTables(mg)
|
||||
|
||||
// since it's a new feature enable migration locking by default
|
||||
return mg.Start(true, 0)
|
||||
|
||||
Reference in New Issue
Block a user