diff --git a/migrator/accounts.go b/migrator/accounts.go index 495a36603c..1bdd1fc686 100755 --- a/migrator/accounts.go +++ b/migrator/accounts.go @@ -20,7 +20,6 @@ package migrator import ( "errors" - "fmt" "log" "strings" "time" @@ -122,17 +121,8 @@ func (m *Migrator) migrateV2Accounts() (v3Acnt *engine.Account, err error) { func (m *Migrator) migrateAccounts() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for Actions") + if vrs, err = m.getVersions(utils.Accounts); err != nil { + return } migrated := true migratedFrom := 0 @@ -202,12 +192,8 @@ func (m *Migrator) migrateAccounts() (err error) { } // All done, update version wtih current one - vrs = engine.Versions{utils.Accounts: engine.CurrentDataDBVersions()[utils.Accounts]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Accounts version into StorDB", err.Error())) + if err = m.setVersions(utils.Accounts); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColAcc) } diff --git a/migrator/accounts2_it_test.go b/migrator/accounts2_it_test.go index 999a619a4e..83e1de7b2f 100755 --- a/migrator/accounts2_it_test.go +++ b/migrator/accounts2_it_test.go @@ -256,5 +256,7 @@ func testAcc2ITMigrate(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", testAccount.BalanceMap, result.BalanceMap) } else if !reflect.DeepEqual(testAccount.UnitCounters, result.UnitCounters) { t.Errorf("Expecting: %+v, received: %+v", testAccount.UnitCounters, result.UnitCounters) + } else if acc2Migrator.stats[utils.Accounts] != 1 { + t.Errorf("Expecting: 1, received: %+v", acc2Migrator.stats[utils.Accounts]) } } diff --git a/migrator/accounts_it_test.go b/migrator/accounts_it_test.go index 8b0918012a..a117bf1731 100755 --- a/migrator/accounts_it_test.go +++ b/migrator/accounts_it_test.go @@ -324,6 +324,8 @@ func testAccITMigrateAndMove(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", testAccount.BalanceMap, result.BalanceMap) } else if !reflect.DeepEqual(testAccount.UnitCounters, result.UnitCounters) { t.Errorf("Expecting: %+v, received: %+v", testAccount.UnitCounters, result.UnitCounters) + } else if accMigrator.stats[utils.Accounts] != 1 { + t.Errorf("Expecting: 1, received: %+v", accMigrator.stats[utils.Accounts]) } case utils.Move: //set an account in dmIN @@ -363,6 +365,8 @@ func testAccITMigrateAndMove(t *testing.T) { result, err = accMigrator.dmIN.DataManager().GetAccount(testAccount.ID) if err != utils.ErrNotFound { t.Error(err) + } else if accMigrator.stats[utils.Accounts] != 1 { + t.Errorf("Expecting: 1, received: %+v", accMigrator.stats[utils.Accounts]) } } diff --git a/migrator/action.go b/migrator/action.go index 6a12a38051..259c90710f 100644 --- a/migrator/action.go +++ b/migrator/action.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "github.com/cgrates/cgrates/engine" @@ -98,17 +97,8 @@ func (m *Migrator) migrateV1Actions() (acts engine.Actions, err error) { func (m *Migrator) migrateActions() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Actions); err != nil { + return } migrated := true var acts engine.Actions @@ -151,12 +141,8 @@ func (m *Migrator) migrateActions() (err error) { // remove old actions // All done, update version wtih current one - vrs = engine.Versions{utils.Actions: engine.CurrentStorDBVersions()[utils.Actions]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Actions version into dataDB", err.Error())) + if err = m.setVersions(utils.Actions); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColAct) diff --git a/migrator/action_it_test.go b/migrator/action_it_test.go index 7a7929cd58..9e56955eea 100644 --- a/migrator/action_it_test.go +++ b/migrator/action_it_test.go @@ -267,6 +267,8 @@ func testActITMigrateAndMove(t *testing.T) { } if !reflect.DeepEqual(act, &result) { t.Errorf("Expecting: %+v, received: %+v", act, &result) + } else if actMigrator.stats[utils.Actions] != 1 { + t.Errorf("Expecting: 1, received: %+v", actMigrator.stats[utils.Actions]) } case utils.Move: if err := actMigrator.dmIN.DataManager().SetActions(v1act.Id, *act, utils.NonTransactional); err != nil { @@ -287,6 +289,8 @@ func testActITMigrateAndMove(t *testing.T) { } if !reflect.DeepEqual(act, &result) { t.Errorf("Expecting: %+v, received: %+v", act, &result) + } else if actMigrator.stats[utils.Actions] != 1 { + t.Errorf("Expecting: 1, received: %+v", actMigrator.stats[utils.Actions]) } } } diff --git a/migrator/action_plan.go b/migrator/action_plan.go index db365c9fd6..13339c9c7b 100644 --- a/migrator/action_plan.go +++ b/migrator/action_plan.go @@ -102,17 +102,8 @@ func (m *Migrator) migrateV1ActionPlans() (v2 []*engine.ActionPlan, err error) { func (m *Migrator) migrateActionPlans() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.ActionPlans); err != nil { + return } if m.dmIN.DataManager().DataDB().GetStorageType() == utils.REDIS { // if redis rebuild action plans indexes redisDB, can := m.dmIN.DataManager().DataDB().(*engine.RedisStorage) @@ -188,12 +179,8 @@ func (m *Migrator) migrateActionPlans() (err error) { } // All done, update version wtih current one - vrs = engine.Versions{utils.ActionPlans: engine.CurrentDataDBVersions()[utils.ActionPlans]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating ActionPlans version into dataDB", err.Error())) + if err = m.setVersions(utils.ActionPlans); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColApl) } diff --git a/migrator/action_plan_it_test.go b/migrator/action_plan_it_test.go index 434d8e856d..3e8a79c331 100644 --- a/migrator/action_plan_it_test.go +++ b/migrator/action_plan_it_test.go @@ -262,6 +262,8 @@ func testActPlnITMigrateAndMove(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", actPln.AccountIDs, result.AccountIDs) } else if !reflect.DeepEqual(actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing) { t.Errorf("Expecting: %+v, received: %+v", actPln.ActionTimings[0].Timing, result.ActionTimings[0].Timing) + } else if actPlnMigrator.stats[utils.ActionPlans] != 1 { + t.Errorf("Expecting: 1, received: %+v", actPlnMigrator.stats[utils.ActionPlans]) } case utils.Move: if err := actPlnMigrator.dmIN.DataManager().SetActionPlan((*v1actPln)[0].Id, actPln, true, utils.NonTransactional); err != nil { @@ -291,6 +293,8 @@ func testActPlnITMigrateAndMove(t *testing.T) { result, err = actPlnMigrator.dmIN.DataManager().GetActionPlan((*v1actPln)[0].Id, true, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if actPlnMigrator.stats[utils.ActionPlans] != 1 { + t.Errorf("Expecting: 1, received: %+v", actPlnMigrator.stats[utils.ActionPlans]) } } } diff --git a/migrator/action_trigger.go b/migrator/action_trigger.go index d7d71e077d..4de9815580 100644 --- a/migrator/action_trigger.go +++ b/migrator/action_trigger.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "time" @@ -70,6 +69,8 @@ func (m *Migrator) migrateCurrentActionTrigger() (err error) { if err := m.dmOut.DataManager().SetActionTriggers(idg, acts, utils.NonTransactional); err != nil { return err } + m.stats[utils.ActionTriggers]++ + } return } @@ -111,17 +112,8 @@ func (m *Migrator) removeV1ActionTriggers() (err error) { func (m *Migrator) migrateActionTriggers() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.ActionTriggers); err != nil { + return } migrated := true migratedFrom := 0 @@ -175,12 +167,8 @@ func (m *Migrator) migrateActionTriggers() (err error) { } // All done, update version wtih current one - vrs = engine.Versions{utils.ActionTriggers: engine.CurrentDataDBVersions()[utils.ActionTriggers]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating ActionTriggers version into DataDB", err.Error())) + if err = m.setVersions(utils.ActionTriggers); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColAtr) diff --git a/migrator/action_trigger_it_test.go b/migrator/action_trigger_it_test.go index 1d6e795fdc..2d8dcc9594 100644 --- a/migrator/action_trigger_it_test.go +++ b/migrator/action_trigger_it_test.go @@ -231,8 +231,9 @@ func testActTrgITMigrateAndMove(t *testing.T) { } if !reflect.DeepEqual(actTrg, result) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(actTrg), utils.ToJSON(result)) + } else if actTrgMigrator.stats[utils.ActionTriggers] != 1 { + t.Errorf("Expecting: 1, received: %+v", actTrgMigrator.stats[utils.ActionTriggers]) } - // utils.tojson si verificat case utils.Move: if err := actTrgMigrator.dmIN.DataManager().SetActionTriggers((*v1actTrg)[0].Id, actTrg, utils.NonTransactional); err != nil { t.Error("Error when setting ActionTriggers ", err.Error()) @@ -253,5 +254,8 @@ func testActTrgITMigrateAndMove(t *testing.T) { if !reflect.DeepEqual(actTrg, result) { t.Errorf("Expecting: %+v, received: %+v", actTrg, result) } + if actTrgMigrator.stats[utils.ActionTriggers] != 1 { + t.Errorf("Expecting: 1, received: %+v", actTrgMigrator.stats[utils.ActionTriggers]) + } } } diff --git a/migrator/alias_it_test.go b/migrator/alias_it_test.go index 248ba58489..70229b1c9f 100644 --- a/migrator/alias_it_test.go +++ b/migrator/alias_it_test.go @@ -231,5 +231,7 @@ func testAlsITMigrateAndMove(t *testing.T) { t.Error(err) } else if !reflect.DeepEqual(expAlsIdx, alsidx) { t.Errorf("Expected %v, recived: %v", utils.ToJSON(expAlsIdx), utils.ToJSON(alsidx)) + } else if alsMigrator.stats[Alias] != 1 { + t.Errorf("Expected 1, recived: %v", alsMigrator.stats[Alias] != 1) } } diff --git a/migrator/attributes.go b/migrator/attributes.go index 152b544864..c712eab016 100644 --- a/migrator/attributes.go +++ b/migrator/attributes.go @@ -162,14 +162,8 @@ func (m *Migrator) migrateV4ToV5AttributeProfile(v4Attr *v4AttributeProfile) (v5 func (m *Migrator) migrateAttributeProfile() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) - if err != nil { - //error getting the current verions - return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, - err.Error(), fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Attributes); err != nil { + return } migrated := true @@ -252,10 +246,8 @@ func (m *Migrator) migrateAttributeProfile() (err error) { return nil } // All done, update version with current one - vrs = engine.Versions{utils.Attributes: engine.CurrentDataDBVersions()[utils.Attributes]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when updating Attributes version into dataDB", err.Error())) + if err = m.setVersions(utils.Attributes); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColAttr) diff --git a/migrator/attributes_it_test.go b/migrator/attributes_it_test.go index 3378e4a244..912254d036 100755 --- a/migrator/attributes_it_test.go +++ b/migrator/attributes_it_test.go @@ -276,6 +276,9 @@ func testAttrITMigrateOnlyVersion(t *testing.T) { } else if vrs[utils.Attributes] != 5 { t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes]) } + if attrMigrator.stats[utils.Attributes] != 0 { + t.Errorf("Expecting: 0, received: %+v", attrMigrator.stats[utils.Attributes]) + } } func testAttrITMigrateAndMove(t *testing.T) { @@ -374,6 +377,8 @@ func testAttrITMigrateAndMove(t *testing.T) { attrPrf.Compile() if !reflect.DeepEqual(result, attrPrf) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result)) + } else if attrMigrator.stats[utils.Attributes] != 1 { + t.Errorf("Expecting: 1, received: %+v", attrMigrator.stats[utils.Attributes]) } case utils.Move: if err := attrMigrator.dmIN.DataManager().SetAttributeProfile(attrPrf, false); err != nil { @@ -431,6 +436,8 @@ func testAttrITMigrateAndMove(t *testing.T) { if _, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.com", "ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) + } else if attrMigrator.stats[utils.Attributes] != 2 { + t.Errorf("Expecting: 2, received: %+v", attrMigrator.stats[utils.Attributes]) } } } @@ -598,6 +605,9 @@ func testAttrITMigrateV3(t *testing.T) { if !reflect.DeepEqual(result, attrPrf) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result)) } + if attrMigrator.stats[utils.Attributes] != 3 { + t.Errorf("Expecting: 3, received: %+v", attrMigrator.stats[utils.Attributes]) + } } func testAttrITMigrateV4(t *testing.T) { @@ -807,6 +817,15 @@ func testAttrITV1ToV5(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut2), utils.ToJSON(result)) } } + if attrAction == utils.Move { + if attrMigrator.stats[utils.Attributes] != 4 { + t.Errorf("Expecting: 4, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } else { + if attrMigrator.stats[utils.Attributes] != 6 { + t.Errorf("Expecting: 6, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } } func testAttrITV2ToV5(t *testing.T) { @@ -1065,6 +1084,15 @@ func testAttrITV3ToV5(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eOut2), utils.ToJSON(result)) } } + if attrAction == utils.Move { + if attrMigrator.stats[utils.Attributes] != 8 { + t.Errorf("Expecting: 8, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } else { + if attrMigrator.stats[utils.Attributes] != 10 { + t.Errorf("Expecting: 10, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } } func testAttrITdryRunV2ToV5(t *testing.T) { @@ -1114,6 +1142,16 @@ func testAttrITdryRunV2ToV5(t *testing.T) { if err != nil && err != utils.ErrNotFound { t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err) } + + if attrAction == utils.Move { + if attrMigrator.stats[utils.Attributes] != 9 { + t.Errorf("Expecting: 9, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } else { + if attrMigrator.stats[utils.Attributes] != 11 { + t.Errorf("Expecting: 11, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } } func testAttrITdryRunV3ToV5(t *testing.T) { @@ -1162,4 +1200,13 @@ func testAttrITdryRunV3ToV5(t *testing.T) { if err != nil && err != utils.ErrNotFound { t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err) } + if attrAction == utils.Move { + if attrMigrator.stats[utils.Attributes] != 10 { + t.Errorf("Expecting: 10, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } else { + if attrMigrator.stats[utils.Attributes] != 12 { + t.Errorf("Expecting: 12, received: %+v", attrMigrator.stats[utils.Attributes]) + } + } } diff --git a/migrator/cdrs.go b/migrator/cdrs.go index e865957a4c..7f11366c1a 100755 --- a/migrator/cdrs.go +++ b/migrator/cdrs.go @@ -20,7 +20,6 @@ package migrator import ( "encoding/json" - "fmt" "time" "github.com/cgrates/cgrates/engine" @@ -39,6 +38,7 @@ func (m *Migrator) migrateCurrentCDRs() (err error) { if err := m.storDBOut.StorDB().SetCDR(cdr, true); err != nil { return err } + m.stats[utils.CDRs]++ } return } @@ -46,17 +46,8 @@ func (m *Migrator) migrateCurrentCDRs() (err error) { func (m *Migrator) migrateCDRs() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions(utils.EmptyString) - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for Actions") + if vrs, err = m.getVersions(utils.CDRs); err != nil { + return } migrated := true var v2 *engine.CDR @@ -92,12 +83,8 @@ func (m *Migrator) migrateCDRs() (err error) { m.stats[utils.CDRs]++ } // All done, update version wtih current one - vrs = engine.Versions{utils.CDRs: engine.CurrentStorDBVersions()[utils.CDRs]} - if err = m.storDBOut.StorDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating CDRs version into StorDB", err.Error())) + if err = m.setVersions(utils.CDRs); err != nil { + return err } return m.ensureIndexesStorDB(engine.ColCDRs) } diff --git a/migrator/cdrs_it_test.go b/migrator/cdrs_it_test.go index 5160b03889..e3609035e9 100755 --- a/migrator/cdrs_it_test.go +++ b/migrator/cdrs_it_test.go @@ -185,4 +185,7 @@ func testCdrITMigrateAndMove(t *testing.T) { } else if vrs[utils.CDRs] != 2 { t.Errorf("Unexpected version returned: %d", vrs[utils.CDRs]) } + // else if cdrMigrator.stats[utils.CDRs] != 1 { + // t.Errorf("Expected 1, recived: %v", cdrMigrator.stats[utils.CDRs]) + // } } diff --git a/migrator/chargers.go b/migrator/chargers.go index 450d3b7d4b..9b2be9cd5f 100755 --- a/migrator/chargers.go +++ b/migrator/chargers.go @@ -59,17 +59,8 @@ func (m *Migrator) migrateCurrentCharger() (err error) { func (m *Migrator) migrateChargers() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ChargerProfile model") + if vrs, err = m.getVersions(utils.Chargers); err != nil { + return } switch vrs[utils.Chargers] { case current[utils.Chargers]: diff --git a/migrator/chargers_it_test.go b/migrator/chargers_it_test.go index aa189d4ad9..0a39392dcd 100755 --- a/migrator/chargers_it_test.go +++ b/migrator/chargers_it_test.go @@ -244,6 +244,8 @@ func testChrgITMigrateAndMove(t *testing.T) { if _, err = chrgMigrator.dmIN.DataManager().GetChargerProfile("cgrates.com", "CHRG_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) + } else if chrgMigrator.stats[utils.Chargers] != 2 { + t.Errorf("Expected 2, recived: %v", chrgMigrator.stats[utils.Chargers]) } } } diff --git a/migrator/derived_chargers_it_test.go b/migrator/derived_chargers_it_test.go index 234aac5cbf..42aed3dc40 100644 --- a/migrator/derived_chargers_it_test.go +++ b/migrator/derived_chargers_it_test.go @@ -257,6 +257,8 @@ func testDCITMigrateAndMove(t *testing.T) { utils.ConcatenatedKey("cgrates.org", utils.MetaChargers), "", true, true); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error %v, recived: %v with reply: %v", utils.ErrNotFound, err, utils.ToJSON(dcidx)) + } else if dcMigrator.stats[utils.DerivedChargersV] != 1 { + t.Errorf("Expected 1, recived: %v", dcMigrator.stats[utils.DerivedChargersV]) } } diff --git a/migrator/destinations.go b/migrator/destinations.go index 471a48edf4..2c1d1c60dd 100644 --- a/migrator/destinations.go +++ b/migrator/destinations.go @@ -52,18 +52,10 @@ func (m *Migrator) migrateCurrentDestinations() (err error) { func (m *Migrator) migrateDestinations() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Destinations); err != nil { + return } + switch vrs[utils.Destinations] { case current[utils.Destinations]: if m.sameDataDB { diff --git a/migrator/dispatchers.go b/migrator/dispatchers.go index f3bbcfd856..7a079d1582 100644 --- a/migrator/dispatchers.go +++ b/migrator/dispatchers.go @@ -88,17 +88,8 @@ func (m *Migrator) migrateCurrentDispatcherHost() (err error) { func (m *Migrator) migrateDispatchers() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for DispatcherProfile model") + if vrs, err = m.getVersions(utils.Dispatchers); err != nil { + return } switch vrs[utils.Dispatchers] { case current[utils.Dispatchers]: diff --git a/migrator/dispatchers_it_test.go b/migrator/dispatchers_it_test.go index 53b6fb69d4..9741d3d945 100644 --- a/migrator/dispatchers_it_test.go +++ b/migrator/dispatchers_it_test.go @@ -247,5 +247,7 @@ func testDspITMigrateAndMove(t *testing.T) { "ALL", false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if dspMigrator.stats[utils.Dispatchers] != 1 { + t.Errorf("Expected 1, recived: %v", dspMigrator.stats[utils.Dispatchers]) } } diff --git a/migrator/filters.go b/migrator/filters.go index 25b625a5a6..f28288fc6c 100644 --- a/migrator/filters.go +++ b/migrator/filters.go @@ -287,17 +287,8 @@ func (m *Migrator) migrateRequestFilterV3() (fltr *engine.Filter, err error) { func (m *Migrator) migrateFilters() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.RQF); err != nil { + return } migrated := true migratedFrom := 0 @@ -378,12 +369,8 @@ func (m *Migrator) migrateFilters() (err error) { } } - vrs = engine.Versions{utils.RQF: engine.CurrentDataDBVersions()[utils.RQF]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Filters version into dataDB", err.Error())) + if err = m.setVersions(utils.RQF); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColFlt) } diff --git a/migrator/filters_it_test.go b/migrator/filters_it_test.go index 48eeb3ef05..56f47ab925 100644 --- a/migrator/filters_it_test.go +++ b/migrator/filters_it_test.go @@ -504,5 +504,7 @@ func testFltrITMigratev3(t *testing.T) { result.Compile() if !reflect.DeepEqual(*expFilters, *result) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expFilters), utils.ToJSON(result)) + } else if fltrMigrator.stats[utils.RQF] != 5 { + t.Errorf("Expected 5, recived: %v", fltrMigrator.stats[utils.RQF]) } } diff --git a/migrator/load_ids.go b/migrator/load_ids.go index 3df31eb0dd..35046c9852 100644 --- a/migrator/load_ids.go +++ b/migrator/load_ids.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -28,23 +26,15 @@ import ( // func (m *Migrator) migrateLoadIDs() (err error) { var vrs engine.Versions - if vrs, err = m.dmIN.DataManager().DataDB().GetVersions(""); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + if vrs, err = m.getVersions(utils.LoadIDsVrs); err != nil { + return } if vrs[utils.LoadIDs] != 1 { if err = m.dmOut.DataManager().DataDB().RemoveLoadIDsDrv(); err != nil { return } - // All done, update version wtih current one - vrs := engine.Versions{utils.LoadIDsVrs: engine.CurrentDataDBVersions()[utils.LoadIDsVrs]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating LoadIDs version into dataDB", err)) + if err = m.setVersions(utils.ActionTriggers); err != nil { + return err } } diff --git a/migrator/migrator_utils.go b/migrator/migrator_utils.go index b51022b083..ce96e65761 100644 --- a/migrator/migrator_utils.go +++ b/migrator/migrator_utils.go @@ -21,6 +21,7 @@ package migrator import ( "errors" "fmt" + "strings" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -83,3 +84,39 @@ func NewMigratorStorDB(db_type, host, port, name, user, pass, marshaler, sslmode } return d, nil } +func (m *Migrator) getVersions(str string) (vrs engine.Versions, err error) { + if str == utils.CDRs || str == utils.SessionSCosts || strings.HasPrefix(str, "Tp") { + vrs, err = m.storDBIn.StorDB().GetVersions(utils.EmptyString) + } else { + vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) + } + if err != nil { + return nil, utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return nil, utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for "+str) + } + return +} + +func (m *Migrator) setVersions(str string) (err error) { + if str == utils.CDRs || str == utils.SessionSCosts || strings.HasPrefix(str, "Tp") { + vrs := engine.Versions{str: engine.CurrentStorDBVersions()[str]} + err = m.storDBOut.StorDB().SetVersions(vrs, false) + } else { + vrs := engine.Versions{str: engine.CurrentDataDBVersions()[str]} + err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false) + } + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when updating %s version into StorDB", err.Error(), str)) + } + return +} diff --git a/migrator/rating_plan.go b/migrator/rating_plan.go index bf3f03e2d5..c867aa75d3 100644 --- a/migrator/rating_plan.go +++ b/migrator/rating_plan.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "github.com/cgrates/cgrates/engine" @@ -55,18 +54,10 @@ func (m *Migrator) migrateCurrentRatingPlans() (err error) { func (m *Migrator) migrateRatingPlans() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.RatingPlan); err != nil { + return } + switch vrs[utils.RatingPlan] { case current[utils.RatingPlan]: if m.sameDataDB { diff --git a/migrator/rating_plan_it_test.go b/migrator/rating_plan_it_test.go index 9d267948c3..5b739e966c 100644 --- a/migrator/rating_plan_it_test.go +++ b/migrator/rating_plan_it_test.go @@ -221,6 +221,8 @@ func testRtPlITMigrateAndMove(t *testing.T) { result, err = rtplMigrator.dmIN.DataManager().GetRatingPlan("RT_PLAN1", true, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if rtplMigrator.stats[utils.RatingPlan] != 1 { + t.Errorf("Expected 1, recived: %v", rtplMigrator.stats[utils.RatingPlan]) } } } diff --git a/migrator/rating_profile.go b/migrator/rating_profile.go index 871bdc910e..f64a240db5 100644 --- a/migrator/rating_profile.go +++ b/migrator/rating_profile.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "github.com/cgrates/cgrates/engine" @@ -55,18 +54,10 @@ func (m *Migrator) migrateCurrentRatingProfiles() (err error) { func (m *Migrator) migrateRatingProfiles() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.RatingProfile); err != nil { + return } + switch vrs[utils.RatingProfile] { case current[utils.RatingProfile]: if m.sameDataDB { diff --git a/migrator/rating_profile_it_test.go b/migrator/rating_profile_it_test.go index 6038540c15..00f339b40f 100644 --- a/migrator/rating_profile_it_test.go +++ b/migrator/rating_profile_it_test.go @@ -219,6 +219,8 @@ func testRtPrfITMigrateAndMove(t *testing.T) { result, err = rtprflMigrator.dmIN.DataManager().GetRatingProfile("RT_Profile", true, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if rtprflMigrator.stats[utils.RatingProfile] != 1 { + t.Errorf("Expected 1, recived: %v", rtprflMigrator.stats[utils.RatingProfile]) } } } diff --git a/migrator/resource.go b/migrator/resource.go index 8bdf99d559..c96da28fe3 100644 --- a/migrator/resource.go +++ b/migrator/resource.go @@ -58,18 +58,10 @@ func (m *Migrator) migrateCurrentResource() (err error) { func (m *Migrator) migrateResources() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Resource); err != nil { + return } + switch vrs[utils.Resource] { case current[utils.Resource]: if m.sameDataDB { diff --git a/migrator/resource_it_test.go b/migrator/resource_it_test.go index 2904681d7a..d34ac1a4cd 100644 --- a/migrator/resource_it_test.go +++ b/migrator/resource_it_test.go @@ -218,6 +218,8 @@ func testResITMigrateAndMove(t *testing.T) { result, err = resMigrator.dmIN.DataManager().GetResourceProfile("cgrates.org", "RES1", false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if resMigrator.stats[utils.Resource] != 1 { + t.Errorf("Expected 1, recived: %v", resMigrator.stats[utils.Resource]) } } } diff --git a/migrator/routes.go b/migrator/routes.go index 094444526d..52d225e3c8 100644 --- a/migrator/routes.go +++ b/migrator/routes.go @@ -139,12 +139,8 @@ func (m *Migrator) migrateCurrentRouteProfile() (err error) { func (m *Migrator) migrateRouteProfiles() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + if vrs, err = m.getVersions(utils.ActionTriggers); err != nil { + return } if routeVersion, has := vrs[utils.Routes]; !has { if vrs[utils.RQF] != current[utils.RQF] { diff --git a/migrator/routes_it_test.go b/migrator/routes_it_test.go index e0bfc955cb..3767db035b 100644 --- a/migrator/routes_it_test.go +++ b/migrator/routes_it_test.go @@ -227,6 +227,8 @@ func testSupITMigrateAndMove(t *testing.T) { result, err = supMigrator.dmIN.DataManager().GetRouteProfile("cgrates.org", "SUP1", false, false, utils.NonTransactional) if err != utils.ErrNotFound { t.Error(err) + } else if supMigrator.stats[utils.Routes] != 1 { + t.Errorf("Expected 1, recived: %v", supMigrator.stats[utils.Routes]) } } } diff --git a/migrator/session_costs.go b/migrator/session_costs.go index 6103be31f0..2bd77e2773 100644 --- a/migrator/session_costs.go +++ b/migrator/session_costs.go @@ -121,12 +121,8 @@ func (m *Migrator) migrateV2SessionSCosts() (err error) { return } // All done, update version wtih current one - vrs := engine.Versions{utils.SessionSCosts: engine.CurrentStorDBVersions()[utils.SessionSCosts]} - if err = m.storDBOut.StorDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating SessionSCosts version into StorDB", err.Error())) + if err = m.setVersions(utils.SessionSCosts); err != nil { + return err } return } diff --git a/migrator/session_costs_it_test.go b/migrator/session_costs_it_test.go index 27c25000f0..d253c81953 100755 --- a/migrator/session_costs_it_test.go +++ b/migrator/session_costs_it_test.go @@ -140,6 +140,8 @@ func testSessionCostITRename(t *testing.T) { t.Error(err) } else if vrs[utils.SessionSCosts] != 2 { t.Errorf("Unexpected version returned: %d", vrs[utils.SessionSCosts]) + } else if sCostMigrator.stats[utils.SessionSCosts] != 0 { + t.Errorf("Expected 0, recived: %v", sCostMigrator.stats[utils.SessionSCosts]) } } diff --git a/migrator/sharedgroup.go b/migrator/sharedgroup.go index 18f97dcc17..d2ba96e928 100644 --- a/migrator/sharedgroup.go +++ b/migrator/sharedgroup.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "github.com/cgrates/cgrates/engine" @@ -50,6 +49,7 @@ func (m *Migrator) migrateCurrentSharedGroups() (err error) { if err := m.dmOut.DataManager().SetSharedGroup(sgs, utils.NonTransactional); err != nil { return err } + m.stats[utils.SharedGroups] += 1 } return } @@ -74,12 +74,8 @@ func (m *Migrator) migrateV1SharedGroups() (err error) { m.stats[utils.SharedGroups] += 1 } // All done, update version wtih current one - vrs := engine.Versions{utils.SharedGroups: engine.CurrentStorDBVersions()[utils.SharedGroups]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating SharedGroups version into dataDB", err.Error())) + if err = m.setVersions(utils.SharedGroups); err != nil { + return err } return } @@ -87,17 +83,8 @@ func (m *Migrator) migrateV1SharedGroups() (err error) { func (m *Migrator) migrateSharedGroups() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.SharedGroups); err != nil { + return } switch vrs[utils.SharedGroups] { case current[utils.SharedGroups]: diff --git a/migrator/sharedgroup_it_test.go b/migrator/sharedgroup_it_test.go index dc82a47790..31a56a7d3d 100644 --- a/migrator/sharedgroup_it_test.go +++ b/migrator/sharedgroup_it_test.go @@ -222,6 +222,8 @@ func testShrGrpITMigrateAndMove(t *testing.T) { } if !reflect.DeepEqual(shrGrp, result) { t.Errorf("Expecting: %+v, received: %+v", shrGrp, result) + } else if shrGrpMigrator.stats[utils.SharedGroups] != 1 { + t.Errorf("Expected 1, recived: %v", shrGrpMigrator.stats[utils.SharedGroups]) } case utils.Move: if err := shrGrpMigrator.dmIN.DataManager().SetSharedGroup(shrGrp, utils.NonTransactional); err != nil { @@ -242,6 +244,8 @@ func testShrGrpITMigrateAndMove(t *testing.T) { } if !reflect.DeepEqual(shrGrp, result) { t.Errorf("Expecting: %+v, received: %+v", shrGrp, result) + } else if shrGrpMigrator.stats[utils.SharedGroups] != 1 { + t.Errorf("Expected 1, recived: %v", shrGrpMigrator.stats[utils.SharedGroups]) } } } diff --git a/migrator/stats.go b/migrator/stats.go index 10021ae122..f78d909b08 100644 --- a/migrator/stats.go +++ b/migrator/stats.go @@ -174,15 +174,8 @@ func (m *Migrator) migrateV2Stats(v2Stats *engine.StatQueue) (v3Stats *engine.St func (m *Migrator) migrateStats() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.StatS); err != nil { + return } migrated := true var filter *engine.Filter @@ -246,12 +239,8 @@ func (m *Migrator) migrateStats() (err error) { // call the remove function here // All done, update version wtih current one - vrs = engine.Versions{utils.StatS: engine.CurrentDataDBVersions()[utils.StatS]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Stats version into dataDB", err.Error())) + if err = m.setVersions(utils.StatS); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColSqs) } diff --git a/migrator/subscribers.go b/migrator/subscribers.go index cae1ee3ec6..ac0806b151 100644 --- a/migrator/subscribers.go +++ b/migrator/subscribers.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -46,17 +44,8 @@ import ( func (m *Migrator) migrateSubscribers() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Subscribers); err != nil { + return } switch vrs[utils.Subscribers] { case current[utils.Subscribers]: diff --git a/migrator/thresholds.go b/migrator/thresholds.go index 14417b9105..3cb2f44950 100644 --- a/migrator/thresholds.go +++ b/migrator/thresholds.go @@ -146,17 +146,8 @@ func (m *Migrator) migrateV2Thresholds() (v3 *engine.ThresholdProfile, err error func (m *Migrator) migrateThresholds() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString) - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Thresholds); err != nil { + return } migrated := true migratedFrom := 0 @@ -229,12 +220,8 @@ func (m *Migrator) migrateThresholds() (err error) { } } // All done, update version wtih current one - vrs = engine.Versions{utils.Thresholds: engine.CurrentDataDBVersions()[utils.Thresholds]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Thresholds version into dataDB", err.Error())) + if err = m.setVersions(utils.Thresholds); err != nil { + return err } return m.ensureIndexesDataDB(engine.ColTps) } diff --git a/migrator/thresholds_it_test.go b/migrator/thresholds_it_test.go index 921b2b11b9..45df3b1f60 100644 --- a/migrator/thresholds_it_test.go +++ b/migrator/thresholds_it_test.go @@ -355,7 +355,9 @@ func testTrsITMigrateAndMove(t *testing.T) { if !reflect.DeepEqual(tresProf3, result) { t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(tresProf3), utils.ToJSON(result)) } - + if trsMigrator.stats[utils.Thresholds] != 4 { + t.Errorf("Expected 4, recived: %v", trsMigrator.stats[utils.Thresholds]) + } case utils.Move: if err := trsMigrator.dmIN.DataManager().SetThresholdProfile(tresProf, false); err != nil { t.Error("Error when setting Thresholds ", err.Error()) diff --git a/migrator/timings.go b/migrator/timings.go index 04fd4a4a97..e31f49a58d 100644 --- a/migrator/timings.go +++ b/migrator/timings.go @@ -19,7 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" "strings" "github.com/cgrates/cgrates/engine" @@ -52,17 +51,8 @@ func (m *Migrator) migrateCurrentTiming() (err error) { func (m *Migrator) migrateTimings() (err error) { var vrs engine.Versions current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.Timing); err != nil { + return } switch vrs[utils.Timing] { case current[utils.Timing]: diff --git a/migrator/tp_account_actions.go b/migrator/tp_account_actions.go index de9ec4e394..45514a6292 100644 --- a/migrator/tp_account_actions.go +++ b/migrator/tp_account_actions.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -56,17 +54,8 @@ func (m *Migrator) migrateCurrentTPaccountAcction() (err error) { func (m *Migrator) migrateTPaccountacction() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpAccountActionsV); err != nil { + return } switch vrs[utils.TpAccountActionsV] { case current[utils.TpAccountActionsV]: diff --git a/migrator/tp_action_plans.go b/migrator/tp_action_plans.go index 51ab2a485a..061da902ef 100644 --- a/migrator/tp_action_plans.go +++ b/migrator/tp_action_plans.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -63,17 +61,8 @@ func (m *Migrator) migrateCurrentTPactionplans() (err error) { func (m *Migrator) migrateTPactionplans() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpActionPlans); err != nil { + return } switch vrs[utils.TpActionPlans] { case current[utils.TpActionPlans]: diff --git a/migrator/tp_action_triggers.go b/migrator/tp_action_triggers.go index 97814a99ee..c2c9382fea 100644 --- a/migrator/tp_action_triggers.go +++ b/migrator/tp_action_triggers.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -62,17 +60,8 @@ func (m *Migrator) migrateCurrentTPactiontriggers() (err error) { func (m *Migrator) migrateTPactiontriggers() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpActionTriggers); err != nil { + return } switch vrs[utils.TpActionTriggers] { case current[utils.TpActionTriggers]: diff --git a/migrator/tp_actions.go b/migrator/tp_actions.go index 0c3950cfd8..0929d3101d 100644 --- a/migrator/tp_actions.go +++ b/migrator/tp_actions.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -61,17 +59,8 @@ func (m *Migrator) migrateCurrentTPactions() (err error) { func (m *Migrator) migrateTPactions() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpActions); err != nil { + return } switch vrs[utils.TpActions] { case current[utils.TpActions]: diff --git a/migrator/tp_chargers.go b/migrator/tp_chargers.go index 85b05c3cfd..df7b80b011 100755 --- a/migrator/tp_chargers.go +++ b/migrator/tp_chargers.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -63,17 +61,8 @@ func (m *Migrator) migrateCurrentTPChargers() (err error) { func (m *Migrator) migrateTPChargers() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for TPChargers model") + if vrs, err = m.getVersions(utils.TpChargers); err != nil { + return } switch vrs[utils.TpChargers] { case current[utils.TpChargers]: diff --git a/migrator/tp_destination_rates.go b/migrator/tp_destination_rates.go index d8d241512b..52201546ae 100644 --- a/migrator/tp_destination_rates.go +++ b/migrator/tp_destination_rates.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -61,17 +59,8 @@ func (m *Migrator) migrateCurrentTPdestinationrates() (err error) { func (m *Migrator) migrateTPdestinationrates() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpDestinationRates); err != nil { + return } switch vrs[utils.TpDestinationRates] { case current[utils.TpDestinationRates]: diff --git a/migrator/tp_destinations.go b/migrator/tp_destinations.go index b8921d5321..219a54f907 100644 --- a/migrator/tp_destinations.go +++ b/migrator/tp_destinations.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -61,17 +59,8 @@ func (m *Migrator) migrateCurrentTPDestinations() (err error) { func (m *Migrator) migrateTPDestinations() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpDestinations); err != nil { + return } switch vrs[utils.TpDestinations] { case current[utils.TpDestinations]: diff --git a/migrator/tp_dispatchers.go b/migrator/tp_dispatchers.go index 6d3520c7e5..15f6500b0e 100644 --- a/migrator/tp_dispatchers.go +++ b/migrator/tp_dispatchers.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -97,17 +95,8 @@ func (m *Migrator) migrateCurrentTPDispatcherHosts() (err error) { func (m *Migrator) migrateTPDispatchers() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for TPDispatcher model") + if vrs, err = m.getVersions(utils.TpDispatchers); err != nil { + return } switch vrs[utils.TpDispatchers] { case current[utils.TpDispatchers]: diff --git a/migrator/tp_filters.go b/migrator/tp_filters.go index 776049782d..76fc34dbc2 100644 --- a/migrator/tp_filters.go +++ b/migrator/tp_filters.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -62,17 +60,8 @@ func (m *Migrator) migrateCurrentTPfilters() (err error) { func (m *Migrator) migrateTPfilters() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpFilters); err != nil { + return } switch vrs[utils.TpFilters] { case current[utils.TpFilters]: diff --git a/migrator/tp_rates.go b/migrator/tp_rates.go index deeba853c4..370c216921 100644 --- a/migrator/tp_rates.go +++ b/migrator/tp_rates.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -62,17 +60,8 @@ func (m *Migrator) migrateCurrentTPrates() (err error) { func (m *Migrator) migrateTPrates() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpRates); err != nil { + return } switch vrs[utils.TpRates] { case current[utils.TpRates]: diff --git a/migrator/tp_rating_plans.go b/migrator/tp_rating_plans.go index b98f10bc94..7b9b1cd025 100644 --- a/migrator/tp_rating_plans.go +++ b/migrator/tp_rating_plans.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -63,17 +61,8 @@ func (m *Migrator) migrateCurrentTPratingplans() (err error) { func (m *Migrator) migrateTPratingplans() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpRatingPlans); err != nil { + return } switch vrs[utils.TpRatingPlans] { case current[utils.TpRatingPlans]: diff --git a/migrator/tp_rating_profiles.go b/migrator/tp_rating_profiles.go index 50a2d5e544..7423197388 100644 --- a/migrator/tp_rating_profiles.go +++ b/migrator/tp_rating_profiles.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -60,17 +58,8 @@ func (m *Migrator) migrateCurrentTPratingprofiles() (err error) { func (m *Migrator) migrateTPratingprofiles() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpRatingProfiles); err != nil { + return } switch vrs[utils.TpRatingProfiles] { case current[utils.TpRatingProfiles]: diff --git a/migrator/tp_resources.go b/migrator/tp_resources.go index 286fbb6c8a..5cc25cfa10 100644 --- a/migrator/tp_resources.go +++ b/migrator/tp_resources.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -64,17 +62,8 @@ func (m *Migrator) migrateCurrentTPresources() (err error) { func (m *Migrator) migrateTPresources() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpResources); err != nil { + return } switch vrs[utils.TpResources] { case current[utils.TpResources]: diff --git a/migrator/tp_routes.go b/migrator/tp_routes.go index 4d77d407ea..64ad5295a3 100644 --- a/migrator/tp_routes.go +++ b/migrator/tp_routes.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -64,17 +62,8 @@ func (m *Migrator) migrateCurrentTPRoutes() (err error) { func (m *Migrator) migrateTPRoutes() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpRoutes); err != nil { + return } switch vrs[utils.TpRoutes] { case current[utils.TpRoutes]: diff --git a/migrator/tp_shared_groups.go b/migrator/tp_shared_groups.go index e03daf3a90..f840316fe5 100644 --- a/migrator/tp_shared_groups.go +++ b/migrator/tp_shared_groups.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -64,17 +62,8 @@ func (m *Migrator) migrateCurrentTPsharedgroups() (err error) { func (m *Migrator) migrateTPsharedgroups() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpSharedGroups); err != nil { + return } switch vrs[utils.TpSharedGroups] { case current[utils.TpSharedGroups]: diff --git a/migrator/tp_stats.go b/migrator/tp_stats.go index 5805aad8b4..9cc299408a 100644 --- a/migrator/tp_stats.go +++ b/migrator/tp_stats.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -63,17 +61,8 @@ func (m *Migrator) migrateCurrentTPstats() (err error) { func (m *Migrator) migrateTPstats() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpStats); err != nil { + return } switch vrs[utils.TpStats] { case current[utils.TpStats]: diff --git a/migrator/tp_thresholds.go b/migrator/tp_thresholds.go index c540a664e0..b2eb33f021 100644 --- a/migrator/tp_thresholds.go +++ b/migrator/tp_thresholds.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -63,17 +61,8 @@ func (m *Migrator) migrateCurrentTPthresholds() (err error) { func (m *Migrator) migrateTPthresholds() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpThresholds); err != nil { + return } switch vrs[utils.TpThresholds] { case current[utils.TpThresholds]: diff --git a/migrator/tp_timings.go b/migrator/tp_timings.go index 65cb76431b..fd3756fdd5 100644 --- a/migrator/tp_timings.go +++ b/migrator/tp_timings.go @@ -19,8 +19,6 @@ along with this program. If not, see package migrator import ( - "fmt" - "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -64,17 +62,8 @@ func (m *Migrator) migrateCurrentTPTiming() (err error) { func (m *Migrator) migrateTpTimings() (err error) { var vrs engine.Versions current := engine.CurrentStorDBVersions() - vrs, err = m.storDBIn.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") + if vrs, err = m.getVersions(utils.TpTiming); err != nil { + return } switch vrs[utils.TpTiming] { case current[utils.TpTiming]: diff --git a/migrator/user.go b/migrator/user.go index 4197adb8db..0f89493580 100644 --- a/migrator/user.go +++ b/migrator/user.go @@ -136,12 +136,8 @@ func (m *Migrator) migrateV1User2AttributeProfile() (err error) { return } // All done, update version wtih current one - vrs := engine.Versions{utils.User: engine.CurrentDataDBVersions()[utils.User]} - if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when updating Alias version into dataDB", err.Error())) + if err = m.setVersions(utils.User); err != nil { + return err } return }