mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQLStore: Prevent migration_id duplicates (#47774)
* SQLStore: Prevent migration_id duplicates * Migrations: Remove non-executed migration (duplicated id) Co-authored-by: Leonard Gram <leo@xlson.com>
This commit is contained in:
parent
12ba2d6b8b
commit
219e848e73
@ -75,26 +75,6 @@ func addDataSourceMigration(mg *Migrator) {
|
||||
// add v2 indíces
|
||||
addTableIndicesMigrations(mg, "v2", tableV2)
|
||||
|
||||
//------- copy data from v1 to v2 -------------------
|
||||
mg.AddMigration("copy data_source v1 to v2", NewCopyTableDataMigration("data_source", "data_source_v1", map[string]string{
|
||||
"id": "id",
|
||||
"org_id": "account_id",
|
||||
"version": "version",
|
||||
"type": "type",
|
||||
"name": "name",
|
||||
"access": "access",
|
||||
"url": "url",
|
||||
"user": "user",
|
||||
"password": "password",
|
||||
"database": "database",
|
||||
"basic_auth": "basic_auth",
|
||||
"basic_auth_user": "basic_auth_user",
|
||||
"basic_auth_password": "basic_auth_password",
|
||||
"is_default": "is_default",
|
||||
"created": "created",
|
||||
"updated": "updated",
|
||||
}))
|
||||
|
||||
mg.AddMigration("Drop old table data_source_v1 #2", NewDropTableMigration("data_source_v1"))
|
||||
|
||||
// add column to activate withCredentials option
|
||||
|
@ -21,12 +21,13 @@ var (
|
||||
)
|
||||
|
||||
type Migrator struct {
|
||||
DBEngine *xorm.Engine
|
||||
Dialect Dialect
|
||||
migrations []Migration
|
||||
Logger log.Logger
|
||||
Cfg *setting.Cfg
|
||||
isLocked atomic.Bool
|
||||
DBEngine *xorm.Engine
|
||||
Dialect Dialect
|
||||
migrations []Migration
|
||||
migrationIds map[string]struct{}
|
||||
Logger log.Logger
|
||||
Cfg *setting.Cfg
|
||||
isLocked atomic.Bool
|
||||
}
|
||||
|
||||
type MigrationLog struct {
|
||||
@ -43,6 +44,7 @@ func NewMigrator(engine *xorm.Engine, cfg *setting.Cfg) *Migrator {
|
||||
mg.DBEngine = engine
|
||||
mg.Logger = log.New("migrator")
|
||||
mg.migrations = make([]Migration, 0)
|
||||
mg.migrationIds = make(map[string]struct{})
|
||||
mg.Dialect = NewDialect(mg.DBEngine)
|
||||
mg.Cfg = cfg
|
||||
return mg
|
||||
@ -53,8 +55,13 @@ func (mg *Migrator) MigrationsCount() int {
|
||||
}
|
||||
|
||||
func (mg *Migrator) AddMigration(id string, m Migration) {
|
||||
if _, ok := mg.migrationIds[id]; ok {
|
||||
panic(fmt.Sprintf("migration id conflict: %s", id))
|
||||
}
|
||||
|
||||
m.SetId(id)
|
||||
mg.migrations = append(mg.migrations, m)
|
||||
mg.migrationIds[id] = struct{}{}
|
||||
}
|
||||
|
||||
func (mg *Migrator) GetMigrationIDs(excludeNotLogged bool) []string {
|
||||
|
Loading…
Reference in New Issue
Block a user