mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
changing db type constants with leading *
This commit is contained in:
committed by
Dan Christian Bogos
parent
f9b8fe38b8
commit
5c4bf0e538
@@ -27,6 +27,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -314,11 +315,12 @@ func InitStorDb(cfg *config.CGRConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbPath := strings.Trim(cfg.StorDbCfg().Type, "*")
|
||||
if err := storDb.Flush(path.Join(cfg.DataFolderPath, "storage",
|
||||
cfg.StorDbCfg().Type)); err != nil {
|
||||
dbPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
if utils.IsSliceMember([]string{utils.Mongo, utils.MySQL, utils.Postgres},
|
||||
if utils.IsSliceMember([]string{utils.MetaMongo, utils.MetaMySQL, utils.MetaPostgres},
|
||||
cfg.StorDbCfg().Type) {
|
||||
if err := SetDBVersions(storDb); err != nil {
|
||||
return err
|
||||
|
||||
@@ -1598,5 +1598,5 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) {
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetStorageType() string {
|
||||
return utils.Mongo
|
||||
return utils.MetaMongo
|
||||
}
|
||||
|
||||
@@ -109,5 +109,5 @@ func (msqlS *MySQLStorage) notExtraFieldsValueQry(field, value string) string {
|
||||
}
|
||||
|
||||
func (msqlS *MySQLStorage) GetStorageType() string {
|
||||
return utils.MySQL
|
||||
return utils.MetaMySQL
|
||||
}
|
||||
|
||||
@@ -98,5 +98,5 @@ func (poS *PostgresStorage) notExtraFieldsValueQry(field, value string) string {
|
||||
}
|
||||
|
||||
func (poS *PostgresStorage) GetStorageType() string {
|
||||
return utils.Postgres
|
||||
return utils.MetaPostgres
|
||||
}
|
||||
|
||||
@@ -1124,7 +1124,7 @@ func (rs *RedisStorage) RemoveDispatcherHostDrv(tenant, id string) (err error) {
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetStorageType() string {
|
||||
return utils.Redis
|
||||
return utils.MetaRedis
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) {
|
||||
|
||||
@@ -35,7 +35,7 @@ func NewDataDBConn(dbType, host, port, name, user,
|
||||
pass, marshaler string, opts *config.DataDBOpts,
|
||||
itmsCfg map[string]*config.ItemOpt) (d DataDB, err error) {
|
||||
switch dbType {
|
||||
case utils.Redis:
|
||||
case utils.MetaRedis:
|
||||
var dbNo int
|
||||
dbNo, err = strconv.Atoi(name)
|
||||
if err != nil {
|
||||
@@ -49,9 +49,9 @@ func NewDataDBConn(dbType, host, port, name, user,
|
||||
opts.RedisSentinel, opts.RedisCluster, opts.RedisClusterSync, opts.RedisClusterOndownDelay,
|
||||
opts.RedisConnectTimeout, opts.RedisReadTimeout, opts.RedisWriteTimeout, opts.RedisTLS,
|
||||
opts.RedisClientCertificate, opts.RedisClientKey, opts.RedisCACertificate)
|
||||
case utils.Mongo:
|
||||
case utils.MetaMongo:
|
||||
d, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.DataDB, nil, opts.MongoQueryTimeout)
|
||||
case utils.Internal:
|
||||
case utils.MetaInternal:
|
||||
d = NewInternalDB(nil, nil, true, itmsCfg)
|
||||
default:
|
||||
err = fmt.Errorf("unsupported db_type <%s>", dbType)
|
||||
@@ -64,19 +64,19 @@ func NewStorDBConn(dbType, host, port, name, user, pass, marshaler string,
|
||||
stringIndexedFields, prefixIndexedFields []string,
|
||||
opts *config.StorDBOpts, itmsCfg map[string]*config.ItemOpt) (db StorDB, err error) {
|
||||
switch dbType {
|
||||
case utils.Mongo:
|
||||
case utils.MetaMongo:
|
||||
db, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.StorDB, stringIndexedFields, opts.MongoQueryTimeout)
|
||||
case utils.Postgres:
|
||||
case utils.MetaPostgres:
|
||||
db, err = NewPostgresStorage(host, port, name, user, pass, opts.PgSSLMode,
|
||||
opts.SQLMaxOpenConns, opts.SQLMaxIdleConns, opts.SQLConnMaxLifetime)
|
||||
case utils.MySQL:
|
||||
case utils.MetaMySQL:
|
||||
db, err = NewMySQLStorage(host, port, name, user, pass, opts.SQLMaxOpenConns, opts.SQLMaxIdleConns,
|
||||
opts.SQLConnMaxLifetime, opts.MySQLLocation, opts.MySQLDSNParams)
|
||||
case utils.Internal:
|
||||
case utils.MetaInternal:
|
||||
db = NewInternalDB(stringIndexedFields, prefixIndexedFields, false, itmsCfg)
|
||||
default:
|
||||
err = fmt.Errorf("unknown db '%s' valid options are [%s, %s, %s, %s]",
|
||||
dbType, utils.MySQL, utils.Mongo, utils.Postgres, utils.Internal)
|
||||
err = fmt.Errorf("unknown db 1'%s' valid options are [%s, %s, %s, %s]",
|
||||
dbType, utils.MetaMySQL, utils.MetaMongo, utils.MetaPostgres, utils.MetaInternal)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -123,17 +123,17 @@ func OverwriteDBVersions(storage Storage) (err error) {
|
||||
func (vers Versions) Compare(curent Versions, storType string, isDataDB bool) string {
|
||||
var message map[string]string
|
||||
switch storType {
|
||||
case utils.Mongo:
|
||||
case utils.MetaMongo:
|
||||
if isDataDB {
|
||||
message = dataDBVers
|
||||
} else {
|
||||
message = storDBVers
|
||||
}
|
||||
case utils.Internal:
|
||||
case utils.MetaInternal:
|
||||
message = allVers
|
||||
case utils.Postgres, utils.MySQL:
|
||||
case utils.MetaPostgres, utils.MetaMySQL:
|
||||
message = storDBVers
|
||||
case utils.Redis:
|
||||
case utils.MetaRedis:
|
||||
message = dataDBVers
|
||||
}
|
||||
for subsis, reason := range message {
|
||||
@@ -217,16 +217,16 @@ func CurrentAllDBVersions() Versions {
|
||||
// CurrentDBVersions returns versions based on dbType
|
||||
func CurrentDBVersions(storType string, isDataDB bool) Versions {
|
||||
switch storType {
|
||||
case utils.Mongo:
|
||||
case utils.MetaMongo:
|
||||
if isDataDB {
|
||||
return CurrentDataDBVersions()
|
||||
}
|
||||
return CurrentStorDBVersions()
|
||||
case utils.Internal:
|
||||
case utils.MetaInternal:
|
||||
return CurrentAllDBVersions()
|
||||
case utils.Postgres, utils.MySQL:
|
||||
case utils.MetaPostgres, utils.MetaMySQL:
|
||||
return CurrentStorDBVersions()
|
||||
case utils.Redis:
|
||||
case utils.MetaRedis:
|
||||
return CurrentDataDBVersions()
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -49,37 +49,37 @@ func TestVersionCompare(t *testing.T) {
|
||||
utils.SharedGroups: 2, utils.CostDetails: 2,
|
||||
utils.SessionSCosts: 2}
|
||||
|
||||
message1 := y.Compare(x, utils.Mongo, true)
|
||||
message1 := y.Compare(x, utils.MetaMongo, true)
|
||||
if message1 != "cgr-migrator -exec=*accounts" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*accounts", message1)
|
||||
}
|
||||
message2 := z.Compare(x, utils.Mongo, true)
|
||||
message2 := z.Compare(x, utils.MetaMongo, true)
|
||||
if message2 != "cgr-migrator -exec=*action_plans" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*action_plans", message2)
|
||||
}
|
||||
message3 := q.Compare(x, utils.Mongo, true)
|
||||
message3 := q.Compare(x, utils.MetaMongo, true)
|
||||
if message3 != "cgr-migrator -exec=*shared_groups" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*shared_groups", message3)
|
||||
}
|
||||
message4 := c.Compare(x, utils.Mongo, false)
|
||||
message4 := c.Compare(x, utils.MetaMongo, false)
|
||||
if message4 != "cgr-migrator -exec=*cost_details" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*cost_details", message4)
|
||||
}
|
||||
message5 := a.Compare(b, utils.MySQL, false)
|
||||
message5 := a.Compare(b, utils.MetaMySQL, false)
|
||||
if message5 != "cgr-migrator -exec=*sessions_costs" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*sessions_costs", message5)
|
||||
}
|
||||
message6 := a.Compare(b, utils.Postgres, false)
|
||||
message6 := a.Compare(b, utils.MetaPostgres, false)
|
||||
if message6 != "cgr-migrator -exec=*sessions_costs" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*sessions_costs", message6)
|
||||
}
|
||||
message7 := y.Compare(x, utils.Redis, true)
|
||||
message7 := y.Compare(x, utils.MetaRedis, true)
|
||||
if message7 != "cgr-migrator -exec=*accounts" {
|
||||
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -exec=*accounts", message7)
|
||||
}
|
||||
|
||||
y[utils.Accounts] = 2
|
||||
message8 := y.Compare(x, utils.Redis, true)
|
||||
message8 := y.Compare(x, utils.MetaRedis, true)
|
||||
if message8 != utils.EmptyString {
|
||||
t.Errorf("Expected %+v, received %+v", utils.EmptyString, message8)
|
||||
}
|
||||
@@ -105,19 +105,19 @@ func TestCurrentDBVersions(t *testing.T) {
|
||||
utils.TpResource: 1, utils.TpDestinations: 1, utils.TpRatingPlan: 1,
|
||||
utils.TpRatingProfile: 1, utils.TpChargers: 1, utils.TpDispatchers: 1,
|
||||
}
|
||||
if vrs := CurrentDBVersions(utils.Mongo, true); !reflect.DeepEqual(expVersDataDB, vrs) {
|
||||
if vrs := CurrentDBVersions(utils.MetaMongo, true); !reflect.DeepEqual(expVersDataDB, vrs) {
|
||||
t.Errorf("Expectred %+v, received %+v", expVersDataDB, vrs)
|
||||
}
|
||||
|
||||
if vrs := CurrentDBVersions(utils.Mongo, false); !reflect.DeepEqual(expVersStorDB, vrs) {
|
||||
if vrs := CurrentDBVersions(utils.MetaMongo, false); !reflect.DeepEqual(expVersStorDB, vrs) {
|
||||
t.Errorf("Expectred %+v, received %+v", expVersStorDB, vrs)
|
||||
}
|
||||
|
||||
if vrs := CurrentDBVersions(utils.Postgres, false); !reflect.DeepEqual(expVersStorDB, vrs) {
|
||||
if vrs := CurrentDBVersions(utils.MetaPostgres, false); !reflect.DeepEqual(expVersStorDB, vrs) {
|
||||
t.Errorf("Expectred %+v, received %+v", expVersStorDB, vrs)
|
||||
}
|
||||
|
||||
if vrs := CurrentDBVersions(utils.Redis, true); !reflect.DeepEqual(expVersDataDB, vrs) {
|
||||
if vrs := CurrentDBVersions(utils.MetaRedis, true); !reflect.DeepEqual(expVersDataDB, vrs) {
|
||||
t.Errorf("Expectred %+v, received %+v", expVersDataDB, vrs)
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestCurrentDBVersions(t *testing.T) {
|
||||
|
||||
//Compare AllVersions
|
||||
expStr := "cgr-migrator"
|
||||
if rcv := expVersDataDB.Compare(expVersStorDB, utils.Internal, true); !strings.Contains(rcv, expStr) {
|
||||
if rcv := expVersDataDB.Compare(expVersStorDB, utils.MetaInternal, true); !strings.Contains(rcv, expStr) {
|
||||
t.Errorf("Expected %+v, received %+v", expStr, rcv)
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func (sM *storageMock) SelectDatabase(dbName string) (err error) {
|
||||
func (sM *storageMock) GetStorageType() string {
|
||||
switch sM.testcase {
|
||||
case "Compare returns non-nil message":
|
||||
return utils.Postgres
|
||||
return utils.MetaPostgres
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -130,14 +130,14 @@ func TestStorDBit(t *testing.T) {
|
||||
func testStorDBitIsDBEmpty(t *testing.T) {
|
||||
x := storDB.GetStorageType()
|
||||
switch x {
|
||||
case utils.Mongo:
|
||||
case utils.MetaMongo:
|
||||
test, err := storDB.IsDBEmpty()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if test != true {
|
||||
t.Errorf("Expecting: true got :%+v", test)
|
||||
}
|
||||
case utils.Postgres, utils.MySQL:
|
||||
case utils.MetaPostgres, utils.MetaMySQL:
|
||||
test, err := storDB.IsDBEmpty()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -152,7 +152,7 @@ func testVersion(t *testing.T) {
|
||||
testVersion = allVersions
|
||||
testVersion[utils.Accounts] = 1
|
||||
test = "Migration needed: please backup cgr data and run : <cgr-migrator -exec=*accounts>"
|
||||
case utils.Mongo, utils.Redis:
|
||||
case utils.MetaMongo, utils.MetaRedis:
|
||||
currentVersion = dataDbVersions
|
||||
testVersion = dataDbVersions
|
||||
testVersion[utils.Accounts] = 1
|
||||
@@ -189,12 +189,12 @@ func testVersion(t *testing.T) {
|
||||
}
|
||||
storType = storageDb.GetStorageType()
|
||||
switch storType {
|
||||
case utils.Internal:
|
||||
case utils.MetaInternal:
|
||||
currentVersion = allVersions
|
||||
testVersion = allVersions
|
||||
testVersion[utils.Accounts] = 1
|
||||
test = "Migration needed: please backup cgr data and run : <cgr-migrator -exec=*accounts>"
|
||||
case utils.Mongo, utils.Postgres, utils.MySQL:
|
||||
case utils.MetaMongo, utils.MetaPostgres, utils.MetaMySQL:
|
||||
currentVersion = storDbVersions
|
||||
testVersion = allVersions
|
||||
testVersion[utils.CostDetails] = 1
|
||||
|
||||
Reference in New Issue
Block a user