mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update name for table struct and csv (tp_alias and Alias.csv)
This commit is contained in:
committed by
Dan Christian Bogos
parent
6b0dba5ad7
commit
234771b435
@@ -23,16 +23,16 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type ApierAliasProfile struct {
|
||||
type ExternalAliasProfile struct {
|
||||
Tenant string
|
||||
ID string
|
||||
FilterIDs []string
|
||||
ActivationInterval *utils.ActivationInterval // Activation interval
|
||||
Aliases []*ApierAliasEntry
|
||||
Aliases []*ExternalAliasEntry
|
||||
Weight float64
|
||||
}
|
||||
|
||||
type ApierAliasEntry struct {
|
||||
type ExternalAliasEntry struct {
|
||||
FieldName string
|
||||
Initial string
|
||||
Alias string
|
||||
@@ -55,7 +55,7 @@ func (apierV1 *ApierV1) GetAliasProfile(arg utils.TenantID, reply *engine.AliasP
|
||||
}
|
||||
|
||||
//SetAliasProfile add a new Alias Profile
|
||||
func (apierV1 *ApierV1) SetAliasProfile(alsPrf *ApierAliasProfile, reply *string) error {
|
||||
func (apierV1 *ApierV1) SetAliasProfile(alsPrf *ExternalAliasProfile, reply *string) error {
|
||||
if missing := utils.MissingStructFields(alsPrf, []string{"Tenant", "ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
|
||||
@@ -1791,7 +1791,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
path.Join(attrs.FolderPath, utils.ThresholdsCsv),
|
||||
path.Join(attrs.FolderPath, utils.FiltersCsv),
|
||||
path.Join(attrs.FolderPath, utils.SuppliersCsv),
|
||||
path.Join(attrs.FolderPath, utils.AliasProfileCsv),
|
||||
path.Join(attrs.FolderPath, utils.AliasCsv),
|
||||
), "", self.Config.DefaultTimezone)
|
||||
if err := loader.LoadAll(); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -65,7 +65,7 @@ func (self *ApierV1) GetTPAliasProfileIds(attrs AttrGetTPAliasProfileIds, reply
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAliasProfiles, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAlias, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else if ids == nil {
|
||||
return utils.ErrNotFound
|
||||
@@ -86,7 +86,7 @@ func (self *ApierV1) RemTPAliasProfile(attrs AttrRemTPAliasProfiles, reply *stri
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPAliasProfiles, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
if err := self.StorDb.RemTpData(utils.TBLTPAlias, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
|
||||
@@ -145,7 +145,7 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
|
||||
path.Join(attrs.FolderPath, utils.ThresholdsCsv),
|
||||
path.Join(attrs.FolderPath, utils.FiltersCsv),
|
||||
path.Join(attrs.FolderPath, utils.SuppliersCsv),
|
||||
path.Join(attrs.FolderPath, utils.AliasProfileCsv),
|
||||
path.Join(attrs.FolderPath, utils.AliasCsv),
|
||||
), "", self.Config.DefaultTimezone)
|
||||
if err := loader.LoadAll(); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -150,7 +150,7 @@ func main() {
|
||||
path.Join(*dataPath, utils.ThresholdsCsv),
|
||||
path.Join(*dataPath, utils.FiltersCsv),
|
||||
path.Join(*dataPath, utils.SuppliersCsv),
|
||||
path.Join(*dataPath, utils.AliasProfileCsv),
|
||||
path.Join(*dataPath, utils.AliasCsv),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -520,12 +520,12 @@ CREATE TABLE tp_suppliers (
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `tp_alias_profiles`
|
||||
-- Table structure for table `tp_alias`
|
||||
--
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS tp_alias_profiles;
|
||||
CREATE TABLE tp_alias_profiles (
|
||||
DROP TABLE IF EXISTS tp_alias;
|
||||
CREATE TABLE tp_alias (
|
||||
`pk` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`tenant` varchar(64) NOT NULL,
|
||||
@@ -539,7 +539,7 @@ CREATE TABLE tp_alias_profiles (
|
||||
`created_at` TIMESTAMP,
|
||||
PRIMARY KEY (`pk`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_tp_alias_profiles` (`tpid`,`tenant`,
|
||||
UNIQUE KEY `unique_tp_alias` (`tpid`,`tenant`,
|
||||
`id`,`filter_ids`,`field_name`,`initial`,`alias` )
|
||||
);
|
||||
|
||||
|
||||
@@ -514,8 +514,8 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id",
|
||||
-- Table structure for table `tp_alias_profiles`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS tp_alias_profiles;
|
||||
CREATE TABLE tp_alias_profiles (
|
||||
DROP TABLE IF EXISTS tp_alias;
|
||||
CREATE TABLE tp_alias (
|
||||
"pk" SERIAL PRIMARY KEY,
|
||||
"tpid" varchar(64) NOT NULL,
|
||||
"tenant"varchar(64) NOT NULL,
|
||||
@@ -528,8 +528,8 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id",
|
||||
"weight" decimal(8,2) NOT NULL,
|
||||
"created_at" TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
CREATE INDEX tp_alias_profiles_ids ON tp_alias_profiles (tpid);
|
||||
CREATE INDEX tp_alias_profiles_unique ON tp_alias_profiles ("tpid", "tenant", "id",
|
||||
CREATE INDEX tp_alias_ids ON tp_alias (tpid);
|
||||
CREATE INDEX tp_alias_unique ON tp_alias ("tpid", "tenant", "id",
|
||||
"filter_ids","field_name","initial","alias");
|
||||
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ func LoadTariffPlanFromFolder(tpPath, timezone string, dm *DataManager, disable_
|
||||
path.Join(tpPath, utils.ThresholdsCsv),
|
||||
path.Join(tpPath, utils.FiltersCsv),
|
||||
path.Join(tpPath, utils.SuppliersCsv),
|
||||
path.Join(tpPath, utils.AliasProfileCsv),
|
||||
path.Join(tpPath, utils.AliasCsv),
|
||||
), "", timezone)
|
||||
if err := loader.LoadAll(); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
|
||||
@@ -109,7 +109,7 @@ func TestLoaderITLoadFromCSV(t *testing.T) {
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AliasProfileCsv),
|
||||
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AliasCsv),
|
||||
), "", "")
|
||||
|
||||
if err = loader.LoadDestinations(); err != nil {
|
||||
|
||||
@@ -556,5 +556,5 @@ type TPAlias struct {
|
||||
}
|
||||
|
||||
func (t TPAlias) TableName() string {
|
||||
return utils.TBLTPAliasProfiles
|
||||
return utils.TBLTPAlias
|
||||
}
|
||||
|
||||
@@ -1266,7 +1266,7 @@ func (ms *MongoStorage) GetTPAliasProfiles(tpid, id string) ([]*utils.TPAlias, e
|
||||
filter["id"] = id
|
||||
}
|
||||
var results []*utils.TPAlias
|
||||
session, col := ms.conn(utils.TBLTPAliasProfiles)
|
||||
session, col := ms.conn(utils.TBLTPAlias)
|
||||
defer session.Close()
|
||||
err := col.Find(filter).All(&results)
|
||||
if len(results) == 0 {
|
||||
@@ -1279,7 +1279,7 @@ func (ms *MongoStorage) SetTPAliasProfiles(tpSPs []*utils.TPAlias) (err error) {
|
||||
if len(tpSPs) == 0 {
|
||||
return
|
||||
}
|
||||
session, col := ms.conn(utils.TBLTPAliasProfiles)
|
||||
session, col := ms.conn(utils.TBLTPAlias)
|
||||
defer session.Close()
|
||||
tx := col.Bulk()
|
||||
for _, tp := range tpSPs {
|
||||
|
||||
@@ -108,7 +108,7 @@ func (self *SQLStorage) IsDBEmpty() (resp bool, err error) {
|
||||
utils.TBLTPActionTriggers, utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, utils.TBLTPUsers,
|
||||
utils.TBLTPAliases, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPThresholds,
|
||||
utils.TBLTPFilters, utils.SMCostsTBL, utils.CDRsTBL, utils.TBLTPActionPlans,
|
||||
utils.TBLVersions, utils.TBLTPSuppliers, utils.TBLTPAliasProfiles,
|
||||
utils.TBLVersions, utils.TBLTPSuppliers, utils.TBLTPAlias,
|
||||
}
|
||||
for _, tbl := range tbls {
|
||||
if self.db.HasTable(tbl) {
|
||||
@@ -149,7 +149,7 @@ func (self *SQLStorage) GetTpIds(colName string) ([]string, error) {
|
||||
utils.TBLTPFilters,
|
||||
utils.TBLTPActionPlans,
|
||||
utils.TBLTPSuppliers,
|
||||
utils.TBLTPAliasProfiles)
|
||||
utils.TBLTPAlias)
|
||||
}
|
||||
rows, err = self.Db.Query(qryStr)
|
||||
if err != nil {
|
||||
@@ -235,9 +235,11 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er
|
||||
tx := self.db.Begin()
|
||||
|
||||
if len(table) == 0 { // Remove tpid out of all tables
|
||||
for _, tblName := range []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, utils.TBLTPFilters, utils.TBLTPSuppliers, utils.TBLTPAliasProfiles} {
|
||||
for _, tblName := range []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, utils.TBLTPFilters, utils.TBLTPSuppliers, utils.TBLTPAlias} {
|
||||
if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
||||
@@ -291,7 +291,7 @@ func (self *TPExporter) Run() error {
|
||||
for _, sd := range storDataAlias {
|
||||
sdModels := APItoModelTPAlias(sd)
|
||||
for _, sdModel := range sdModels {
|
||||
toExportMap[utils.AliasProfileCsv] = append(toExportMap[utils.AliasProfileCsv], sdModel)
|
||||
toExportMap[utils.AliasCsv] = append(toExportMap[utils.AliasCsv], sdModel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{
|
||||
utils.ThresholdsCsv: (*TPCSVImporter).importThresholds,
|
||||
utils.FiltersCsv: (*TPCSVImporter).importFilters,
|
||||
utils.SuppliersCsv: (*TPCSVImporter).importSuppliers,
|
||||
utils.AliasProfileCsv: (*TPCSVImporter).importAliasProfiles,
|
||||
utils.AliasCsv: (*TPCSVImporter).importAliasProfiles,
|
||||
}
|
||||
|
||||
func (self *TPCSVImporter) Run() error {
|
||||
@@ -88,7 +88,7 @@ func (self *TPCSVImporter) Run() error {
|
||||
path.Join(self.DirPath, utils.ThresholdsCsv),
|
||||
path.Join(self.DirPath, utils.FiltersCsv),
|
||||
path.Join(self.DirPath, utils.SuppliersCsv),
|
||||
path.Join(self.DirPath, utils.AliasProfileCsv),
|
||||
path.Join(self.DirPath, utils.AliasCsv),
|
||||
)
|
||||
files, _ := ioutil.ReadDir(self.DirPath)
|
||||
for _, f := range files {
|
||||
|
||||
@@ -117,7 +117,7 @@ const (
|
||||
SMCostsTBL = "sm_costs"
|
||||
CDRsTBL = "cdrs"
|
||||
TBLTPSuppliers = "tp_suppliers"
|
||||
TBLTPAliasProfiles = "tp_alias_profiles"
|
||||
TBLTPAlias = "tp_alias"
|
||||
TBLVersions = "versions"
|
||||
TIMINGS_CSV = "Timings.csv"
|
||||
DESTINATIONS_CSV = "Destinations.csv"
|
||||
@@ -140,7 +140,7 @@ const (
|
||||
ThresholdsCsv = "Thresholds.csv"
|
||||
FiltersCsv = "Filters.csv"
|
||||
SuppliersCsv = "Suppliers.csv"
|
||||
AliasProfileCsv = "AliasProfiles.csv"
|
||||
AliasCsv = "Alias.csv"
|
||||
ROUNDING_UP = "*up"
|
||||
ROUNDING_MIDDLE = "*middle"
|
||||
ROUNDING_DOWN = "*down"
|
||||
|
||||
Reference in New Issue
Block a user