From 98d084e009ba4163b2a1eb6386874e58bc3e51ed Mon Sep 17 00:00:00 2001 From: adragusin Date: Tue, 30 Jun 2020 17:55:44 +0300 Subject: [PATCH] Added set/get versions functions in migrator --- migrator/accounts.go | 22 ++++--------------- migrator/action.go | 22 ++++--------------- migrator/action_plan.go | 21 ++++-------------- migrator/action_trigger.go | 22 ++++--------------- migrator/attributes.go | 16 ++++---------- migrator/cdrs.go | 22 ++++--------------- migrator/chargers.go | 13 ++--------- migrator/destinations.go | 14 +++--------- migrator/dispatchers.go | 13 ++--------- migrator/filters.go | 21 ++++-------------- migrator/load_ids.go | 18 ++++------------ migrator/migrator_utils.go | 37 ++++++++++++++++++++++++++++++++ migrator/rating_plan.go | 15 +++---------- migrator/rating_profile.go | 15 +++---------- migrator/resource.go | 14 +++--------- migrator/routes.go | 8 ++----- migrator/session_costs.go | 8 ++----- migrator/sharedgroup.go | 22 ++++--------------- migrator/stats.go | 19 ++++------------ migrator/subscribers.go | 15 ++----------- migrator/thresholds.go | 21 ++++-------------- migrator/timings.go | 14 ++---------- migrator/tp_account_actions.go | 15 ++----------- migrator/tp_action_plans.go | 15 ++----------- migrator/tp_action_triggers.go | 15 ++----------- migrator/tp_actions.go | 15 ++----------- migrator/tp_chargers.go | 15 ++----------- migrator/tp_destination_rates.go | 15 ++----------- migrator/tp_destinations.go | 15 ++----------- migrator/tp_dispatchers.go | 15 ++----------- migrator/tp_filters.go | 15 ++----------- migrator/tp_rates.go | 15 ++----------- migrator/tp_rating_plans.go | 15 ++----------- migrator/tp_rating_profiles.go | 15 ++----------- migrator/tp_resources.go | 15 ++----------- migrator/tp_routes.go | 15 ++----------- migrator/tp_shared_groups.go | 15 ++----------- migrator/tp_stats.go | 15 ++----------- migrator/tp_thresholds.go | 15 ++----------- migrator/tp_timings.go | 15 ++----------- migrator/user.go | 8 ++----- 41 files changed, 143 insertions(+), 527 deletions(-) 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/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_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_trigger.go b/migrator/action_trigger.go index 22d284e6df..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" @@ -113,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 @@ -177,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/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/cdrs.go b/migrator/cdrs.go index 74f1d5c102..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" @@ -47,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 @@ -93,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/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/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/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/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_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/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/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/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/sharedgroup.go b/migrator/sharedgroup.go index 78721724e2..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" @@ -75,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 } @@ -88,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/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/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 }