mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Migrator in cgr-loader, *set_versions implementation
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/migrator"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
@@ -37,7 +38,7 @@ var (
|
||||
//separator = flag.String("separator", ",", "Default field separator")
|
||||
cgrConfig, _ = config.NewDefaultCGRConfig()
|
||||
migrateRC8 = flag.String("migrate_rc8", "", "Migrate Accounts, Actions, ActionTriggers, DerivedChargers, ActionPlans and SharedGroups to RC8 structures, possible values: *all,*enforce,acc,atr,act,dcs,apl,shg")
|
||||
migrate = flag.String("migrate", "", "Fire up automatic migration <*all|*cost_details>")
|
||||
migrate = flag.String("migrate", "", "Fire up automatic migration <*cost_details|*set_versions>")
|
||||
tpdb_type = flag.String("tpdb_type", cgrConfig.TpDbType, "The type of the TariffPlan database <redis>")
|
||||
tpdb_host = flag.String("tpdb_host", cgrConfig.TpDbHost, "The TariffPlan host to connect to.")
|
||||
tpdb_port = flag.String("tpdb_port", cgrConfig.TpDbPort, "The TariffPlan port to bind to.")
|
||||
@@ -208,6 +209,18 @@ func main() {
|
||||
log.Print("Done!")
|
||||
return
|
||||
}
|
||||
if migrate != nil { // Run migrator
|
||||
storDB, err := engine.ConfigureStorStorage(*stor_db_type, *stor_db_host, *stor_db_port, *stor_db_name, *stor_db_user, *stor_db_pass, *dbdata_encoding,
|
||||
cgrConfig.StorDBMaxOpenConns, cgrConfig.StorDBMaxIdleConns, cgrConfig.StorDBCDRSIndexes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := migrator.NewMigrator(storDB).Migrate(*migrate); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Print("Done migrating!")
|
||||
return
|
||||
}
|
||||
// Init necessary db connections, only if not already
|
||||
if !*dryRun { // make sure we do not need db connections on dry run, also not importing into any stordb
|
||||
if *fromStorDb {
|
||||
|
||||
@@ -26,13 +26,12 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewMigrator(storDB engine.StorDB, storDBType string) *Migrator {
|
||||
return &Migrator{storDB: storDB, storDBType: storDBType}
|
||||
func NewMigrator(storDB engine.Storage) *Migrator {
|
||||
return &Migrator{storDB: storDB}
|
||||
}
|
||||
|
||||
type Migrator struct {
|
||||
storDB engine.StorDB
|
||||
storDBType string // Useful to convert back to real
|
||||
storDB engine.Storage
|
||||
}
|
||||
|
||||
func (m *Migrator) Migrate(taskID string) (err error) {
|
||||
@@ -42,6 +41,13 @@ func (m *Migrator) Migrate(taskID string) (err error) {
|
||||
utils.MandatoryIEMissingCaps,
|
||||
utils.UnsupportedMigrationTask,
|
||||
fmt.Sprintf("task <%s> is not a supported migration task", taskID))
|
||||
case utils.MetaSetVersions:
|
||||
if err := m.storDB.SetVersions(engine.CurrentStorDBVersions()); err != nil {
|
||||
return utils.NewCGRError(utils.Migrator,
|
||||
utils.ServerErrorCaps,
|
||||
err.Error(),
|
||||
fmt.Sprintf("error: <%s> when updating CostDetails version into StorDB", err.Error()))
|
||||
}
|
||||
case utils.MetaCostDetails:
|
||||
err = m.migrateCostDetails()
|
||||
}
|
||||
@@ -55,9 +61,6 @@ func (m *Migrator) migrateCostDetails() (err error) {
|
||||
utils.NoStorDBConnection,
|
||||
"no connection to StorDB")
|
||||
}
|
||||
if !utils.IsSliceMember([]string{utils.MYSQL, utils.POSTGRES}, m.storDBType) {
|
||||
return // CostDetails are migrated only for MySQL and Postgres
|
||||
}
|
||||
vrs, err := m.storDB.GetVersions(utils.COST_DETAILS)
|
||||
if err != nil {
|
||||
return utils.NewCGRError(utils.Migrator,
|
||||
|
||||
@@ -327,4 +327,5 @@ const (
|
||||
UnsupportedMigrationTask = "unsupported migration task"
|
||||
NoStorDBConnection = "not connected to StorDB"
|
||||
UndefinedVersion = "undefined version"
|
||||
MetaSetVersions = "*set_versions"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user