From 6149cdb5f863c270b6e7052f5da2b47e0b0e26e0 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 23 Oct 2015 19:28:15 +0300 Subject: [PATCH] set *default Id for default balances --- cmd/cgr-loader/migrator_rc8.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/cgr-loader/migrator_rc8.go b/cmd/cgr-loader/migrator_rc8.go index 45a29a7a5..0ba41f568 100644 --- a/cmd/cgr-loader/migrator_rc8.go +++ b/cmd/cgr-loader/migrator_rc8.go @@ -60,6 +60,16 @@ type Balance struct { dirty bool } +func (b *Balance) IsDefault() bool { + return (b.DestinationIds == "" || b.DestinationIds == utils.ANY) && + b.RatingSubject == "" && + b.Category == "" && + b.ExpirationDate.IsZero() && + b.SharedGroup == "" && + b.Weight == 0 && + b.Disabled == false +} + type UnitsCounter struct { Direction string BalanceType string @@ -146,6 +156,10 @@ func (mig MigratorRC8) migrateAccounts() error { newBalDirection := "*" + keyElements[2] newAcc.BalanceMap[newBalKey] = make(engine.BalanceChain, len(oldBalChain)) for index, oldBal := range oldBalChain { + // check default to set new id + if oldBal.IsDefault() { + oldBal.Id = utils.META_DEFAULT + } newAcc.BalanceMap[newBalKey][index] = &engine.Balance{ Uuid: oldBal.Uuid, Id: oldBal.Id, @@ -226,7 +240,9 @@ func (mig MigratorRC8) migrateAccounts() error { } // delete old data utils.Logger.Info(fmt.Sprintf("Deleting old accounts: %s...", OLD_ACCOUNT_PREFIX+"*")) - _, err = mig.db.Del(OLD_ACCOUNT_PREFIX + "*") + for _, key := range keys { + _, err = mig.db.Del(key) + } return err }