mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-19 22:28:45 +05:00
Refactored sql,redis and data methods for isDbEmpty and modified a message in versioncheck f
This commit is contained in:
committed by
Dan Christian Bogos
parent
7e3821bc94
commit
b19364aaf6
@@ -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) {
|
||||
|
||||
@@ -1246,7 +1246,7 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) {
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetStorageType() string {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func CheckVersions(storage Storage) error {
|
||||
return err
|
||||
}
|
||||
if !empty {
|
||||
msg := "Migration needed: please backup cgr data and run : <cgr-migrator>" + storType
|
||||
msg := "Migration needed: please backup cgrates data and run : <cgr-migrator>"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user