diff --git a/engine/storage_map.go b/engine/storage_map.go index 0313ded67..4dcda86e7 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -295,38 +295,7 @@ func (ms *MapStorage) CacheDataFromDB(prefix string, IDs []string, mustBeCached func (ms *MapStorage) IsDBEmpty() (resp bool, err error) { ms.mu.RLock() defer ms.mu.RUnlock() - var keys []string - prefixes := []string{ - utils.DESTINATION_PREFIX, - utils.REVERSE_DESTINATION_PREFIX, - utils.RATING_PLAN_PREFIX, - utils.RATING_PROFILE_PREFIX, - utils.ACTION_PREFIX, - utils.ACTION_PLAN_PREFIX, - utils.ACTION_TRIGGER_PREFIX, - utils.SHARED_GROUP_PREFIX, - utils.DERIVEDCHARGERS_PREFIX, - utils.LCR_PREFIX, - utils.ACCOUNT_PREFIX, - utils.ALIASES_PREFIX, - utils.REVERSE_ALIASES_PREFIX, - utils.ResourceProfilesPrefix, - utils.ResourcesPrefix, - utils.StatQueuePrefix, // used with CDRStatS - utils.StatQueueProfilePrefix, - utils.AccountActionPlansPrefix, - utils.TimingsPrefix, - } - for _, key := range prefixes { - keys, err = ms.GetKeysForPrefix(key) - if err != nil { - return - } - if len(keys) != 0 { - return false, nil - } - } - return true, nil + return len(ms.dict) == 0, nil } func (ms *MapStorage) GetKeysForPrefix(prefix string) ([]string, error) { diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 287886393..a934fa0dd 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -1246,7 +1246,7 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { } else { return err } - return + return nil } func (ms *MongoStorage) GetStorageType() string { diff --git a/engine/storage_redis.go b/engine/storage_redis.go index ad5193bbc..8dc8707f9 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -120,37 +120,13 @@ func (rs *RedisStorage) SelectDatabase(dbName string) (err error) { } func (rs *RedisStorage) IsDBEmpty() (resp bool, err error) { - var keys []string - prefixes := []string{ - utils.DESTINATION_PREFIX, - utils.REVERSE_DESTINATION_PREFIX, - utils.RATING_PLAN_PREFIX, - utils.RATING_PROFILE_PREFIX, - utils.ACTION_PREFIX, - utils.ACTION_PLAN_PREFIX, - utils.ACTION_TRIGGER_PREFIX, - utils.SHARED_GROUP_PREFIX, - utils.DERIVEDCHARGERS_PREFIX, - utils.LCR_PREFIX, - utils.ACCOUNT_PREFIX, - utils.ALIASES_PREFIX, - utils.REVERSE_ALIASES_PREFIX, - utils.ResourceProfilesPrefix, - utils.ResourcesPrefix, - utils.StatQueuePrefix, // used with CDRStatS - utils.StatQueueProfilePrefix, - utils.AccountActionPlansPrefix, - utils.TimingsPrefix, + keys, err = rs.GetKeysForPrefix("") + if err != nil { + return } - for _, key := range prefixes { - keys, err = rs.GetKeysForPrefix(key) - if err != nil { - return - } - if len(keys) != 0 { - return false, nil - } + if len(keys) != 0 { + return false, nil } return true, nil } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index ba2fc5b04..6c680fedb 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -103,14 +103,16 @@ func (self *SQLStorage) CreateTablesFromScript(scriptPath string) error { } func (self *SQLStorage) IsDBEmpty() (resp bool, err error) { - tbls := []string{utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, - utils.TBLTPSharedGroups, utils.TBLTPCdrStats, utils.TBLTPLcrs, utils.TBLTPActions, utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, + tbls := []string{utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, + utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, + utils.TBLTPSharedGroups, utils.TBLTPCdrStats, utils.TBLTPLcrs, utils.TBLTPActions, + utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, utils.TBLTPAliases, utils.TBLTPUsers, utils.TBLTPResources, utils.TBLTPStats} for _, tbl := range tbls { - resp = self.db.HasTable(tbl) - if resp != false { + if self.db.HasTable(tbl) { return false, nil } + } return true, nil } diff --git a/engine/version.go b/engine/version.go index 09c2f11e6..980b2b27b 100644 --- a/engine/version.go +++ b/engine/version.go @@ -35,7 +35,7 @@ func CheckVersions(storage Storage) error { return err } if !empty { - msg := "Migration needed: please backup cgr data and run : " + storType + msg := "Migration needed: please backup cgrates data and run : " return errors.New(msg) } // no data, write version @@ -107,7 +107,11 @@ func (vers Versions) Compare(curent Versions, storType string) string { func CurrentDBVersions(storType string) Versions { dataDbVersions := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} storDbVersions := Versions{utils.COST_DETAILS: 2} - allVersions := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2} + allVersions := dataDbVersions + for k, v := range storDbVersions { + allVersions[k] = v + } + switch storType { case utils.MONGO, utils.MAPSTOR: return allVersions