mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
id->tag, tbid->id for more SQL best practices
This commit is contained in:
@@ -76,7 +76,7 @@ func (self *ApierV1) GetTPActionIds(attrs AttrGetTPActionIds, reply *[]string) e
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTIONS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTIONS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -74,7 +74,7 @@ func (self *ApierV1) GetTPActionPlanIds(attrs AttrGetTPActionPlanIds, reply *[]s
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTION_PLANS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTION_PLANS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -72,7 +72,7 @@ func (self *ApierV1) GetTPActionTriggerIds(attrs AttrGetTPActionTriggerIds, repl
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTION_TRIGGERS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_ACTION_TRIGGERS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -76,7 +76,7 @@ func (self *ApierV1) GetTPCdrStatsIds(attrs AttrGetTPCdrStatIds, reply *[]string
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_CDR_STATS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_CDR_STATS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -70,7 +70,7 @@ func (self *ApierV1) GetTPDestinationRateIds(attrs AttrGetTPRateIds, reply *[]st
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_DESTINATION_RATES, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_DESTINATION_RATES, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -71,7 +71,7 @@ func (self *ApierV1) GetTPDestinationIds(attrs AttrGetTPDestinationIds, reply *[
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_DESTINATIONS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_DESTINATIONS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -69,7 +69,7 @@ func (self *ApierV1) GetTPRateIds(attrs AttrGetTPRateIds, reply *[]string) error
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_RATES, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_RATES, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -70,7 +70,7 @@ func (self *ApierV1) GetTPRatingPlanIds(attrs AttrGetTPRatingPlanIds, reply *[]s
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_RATING_PLANS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_RATING_PLANS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -76,7 +76,7 @@ func (self *ApierV1) GetTPSharedGroupIds(attrs AttrGetTPSharedGroupIds, reply *[
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_SHARED_GROUPS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_SHARED_GROUPS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -67,7 +67,7 @@ func (self *ApierV1) GetTPTimingIds(attrs AttrGetTPTimingIds, reply *[]string) e
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_TIMINGS, utils.TPDistinctIds{"id"}, nil, &attrs.Paginator); err != nil {
|
||||
if ids, err := self.StorDb.GetTPTableIds(attrs.TPid, utils.TBL_TP_TIMINGS, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else if ids == nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
DROP TABLE IF EXISTS cdrs_primary;
|
||||
CREATE TABLE cdrs_primary (
|
||||
tbid int(11) NOT NULL AUTO_INCREMENT,
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
cgrid char(40) NOT NULL,
|
||||
tor varchar(16) NOT NULL,
|
||||
accid varchar(64) NOT NULL,
|
||||
@@ -21,7 +21,7 @@ CREATE TABLE cdrs_primary (
|
||||
setup_time datetime NOT NULL,
|
||||
answer_time datetime NOT NULL,
|
||||
`usage` DECIMAL(30,9) NOT NULL,
|
||||
PRIMARY KEY (tbid),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY cgrid (cgrid)
|
||||
);
|
||||
|
||||
@@ -31,10 +31,10 @@ CREATE TABLE cdrs_primary (
|
||||
|
||||
DROP TABLE IF EXISTS cdrs_extra;
|
||||
CREATE TABLE cdrs_extra (
|
||||
tbid int(11) NOT NULL AUTO_INCREMENT,
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
cgrid char(40) NOT NULL,
|
||||
extra_fields text NOT NULL,
|
||||
PRIMARY KEY (tbid),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY cgrid (cgrid)
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ CREATE TABLE cdrs_extra (
|
||||
|
||||
DROP TABLE IF EXISTS cost_details;
|
||||
CREATE TABLE cost_details (
|
||||
tbid int(11) NOT NULL AUTO_INCREMENT,
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
cost_time datetime NOT NULL,
|
||||
cost_source varchar(64) NOT NULL,
|
||||
cgrid char(40) NOT NULL,
|
||||
@@ -58,7 +58,7 @@ CREATE TABLE cost_details (
|
||||
destination varchar(128) NOT NULL,
|
||||
cost DECIMAL(20,4) NOT NULL,
|
||||
timespans text,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `costid` (`cgrid`,`runid`)
|
||||
);
|
||||
|
||||
@@ -67,7 +67,7 @@ CREATE TABLE cost_details (
|
||||
--
|
||||
DROP TABLE IF EXISTS rated_cdrs;
|
||||
CREATE TABLE `rated_cdrs` (
|
||||
tbid int(11) NOT NULL AUTO_INCREMENT,
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
mediation_time datetime NOT NULL,
|
||||
cgrid char(40) NOT NULL,
|
||||
runid varchar(64) NOT NULL,
|
||||
@@ -83,6 +83,6 @@ CREATE TABLE `rated_cdrs` (
|
||||
`usage` DECIMAL(30,9) NOT NULL,
|
||||
cost DECIMAL(20,4) DEFAULT NULL,
|
||||
extra_info text,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `costid` (`cgrid`,`runid`)
|
||||
);
|
||||
@@ -3,18 +3,18 @@
|
||||
--
|
||||
DROP TABLE IF EXISTS `tp_timings`;
|
||||
CREATE TABLE `tp_timings` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`years` varchar(255) NOT NULL,
|
||||
`months` varchar(255) NOT NULL,
|
||||
`month_days` varchar(255) NOT NULL,
|
||||
`week_days` varchar(255) NOT NULL,
|
||||
`time` varchar(16) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
KEY `tpid_tmid` (`tpid`,`id`),
|
||||
UNIQUE KEY `tpid_id` (`tpid`,`id`)
|
||||
KEY `tpid_tmid` (`tpid`,`tag`),
|
||||
UNIQUE KEY `tpid_id` (`tpid`,`tag`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -23,14 +23,14 @@ CREATE TABLE `tp_timings` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_destinations`;
|
||||
CREATE TABLE `tp_destinations` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`prefix` varchar(24) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
KEY `tpid_dstid` (`tpid`,`id`),
|
||||
UNIQUE KEY `tpid_dest_prefix` (`tpid`,`id`,`prefix`)
|
||||
KEY `tpid_dstid` (`tpid`,`tag`),
|
||||
UNIQUE KEY `tpid_dest_prefix` (`tpid`,`tag`,`prefix`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -39,18 +39,18 @@ CREATE TABLE `tp_destinations` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_rates`;
|
||||
CREATE TABLE `tp_rates` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`connect_fee` decimal(7,4) NOT NULL,
|
||||
`rate` decimal(7,4) NOT NULL,
|
||||
`rate_unit` varchar(16) NOT NULL,
|
||||
`rate_increment` varchar(16) NOT NULL,
|
||||
`group_interval_start` varchar(16) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
UNIQUE KEY `unique_tprate` (`tpid`,`id`,`group_interval_start`),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_tprate` (`tpid`,`tag`,`group_interval_start`),
|
||||
KEY `tpid` (`tpid`),
|
||||
KEY `tpid_rtid` (`tpid`,`id`)
|
||||
KEY `tpid_rtid` (`tpid`,`tag`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -59,17 +59,17 @@ CREATE TABLE `tp_rates` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_destination_rates`;
|
||||
CREATE TABLE `tp_destination_rates` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`destinations_id` varchar(64) NOT NULL,
|
||||
`rates_id` varchar(64) NOT NULL,
|
||||
`rounding_method` varchar(255) NOT NULL,
|
||||
`rounding_decimals` tinyint(4) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
KEY `tpid_drid` (`tpid`,`id`),
|
||||
UNIQUE KEY `tpid_drid_dstid` (`tpid`,`id`,`destinations_id`)
|
||||
KEY `tpid_drid` (`tpid`,`tag`),
|
||||
UNIQUE KEY `tpid_drid_dstid` (`tpid`,`tag`,`destinations_id`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -78,16 +78,16 @@ CREATE TABLE `tp_destination_rates` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_rating_plans`;
|
||||
CREATE TABLE `tp_rating_plans` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`destrates_id` varchar(64) NOT NULL,
|
||||
`timing_id` varchar(64) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
KEY `tpid_rpl` (`tpid`,`id`),
|
||||
UNIQUE KEY `tpid_rplid_destrates_timings_weight` (`tpid`,`id`,`destrates_id`,`timing_id`)
|
||||
KEY `tpid_rpl` (`tpid`,`tag`),
|
||||
UNIQUE KEY `tpid_rplid_destrates_timings_weight` (`tpid`,`tag`,`destrates_id`,`timing_id`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -96,7 +96,7 @@ CREATE TABLE `tp_rating_plans` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_rating_profiles`;
|
||||
CREATE TABLE `tp_rating_profiles` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`loadid` varchar(64) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
@@ -106,7 +106,7 @@ CREATE TABLE `tp_rating_profiles` (
|
||||
`activation_time` varchar(24) NOT NULL,
|
||||
`rating_plan_id` varchar(64) NOT NULL,
|
||||
`fallback_subjects` varchar(64),
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid_loadid` (`tpid`, `loadid`),
|
||||
UNIQUE KEY `tpid_loadid_tenant_category_dir_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`direction`,`subject`,`activation_time`)
|
||||
);
|
||||
@@ -117,15 +117,15 @@ CREATE TABLE `tp_rating_profiles` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_shared_groups`;
|
||||
CREATE TABLE `tp_shared_groups` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`account` varchar(24) NOT NULL,
|
||||
`strategy` varchar(24) NOT NULL,
|
||||
`rating_subject` varchar(24) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_shared_group` (`tpid`,`id`,`account`,`strategy`,`rating_subject`)
|
||||
UNIQUE KEY `unique_shared_group` (`tpid`,`tag`,`account`,`strategy`,`rating_subject`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -134,9 +134,9 @@ CREATE TABLE `tp_shared_groups` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_actions`;
|
||||
CREATE TABLE `tp_actions` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`action` varchar(24) NOT NULL,
|
||||
`balance_type` varchar(24) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
@@ -149,9 +149,9 @@ CREATE TABLE `tp_actions` (
|
||||
`balance_weight` double(8,2) NOT NULL,
|
||||
`extra_parameters` varchar(256) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_action` (`tpid`,`id`,`action`,`balance_type`,`direction`,`expiry_time`,`destination_id`,`shared_group`,`balance_weight`,`weight`)
|
||||
UNIQUE KEY `unique_action` (`tpid`,`tag`,`action`,`balance_type`,`direction`,`expiry_time`,`destination_id`,`shared_group`,`balance_weight`,`weight`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -160,15 +160,15 @@ CREATE TABLE `tp_actions` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_action_plans`;
|
||||
CREATE TABLE `tp_action_plans` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`actions_id` varchar(64) NOT NULL,
|
||||
`timing_id` varchar(64) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_action_schedule` (`tpid`,`id`,`actions_id`)
|
||||
UNIQUE KEY `unique_action_schedule` (`tpid`,`tag`,`actions_id`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -177,9 +177,9 @@ CREATE TABLE `tp_action_plans` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_action_triggers`;
|
||||
CREATE TABLE `tp_action_triggers` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`balance_type` varchar(24) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
`threshold_type` char(12) NOT NULL,
|
||||
@@ -195,9 +195,9 @@ CREATE TABLE `tp_action_triggers` (
|
||||
`min_queued_items` int(11) NOT NULL,
|
||||
`actions_id` varchar(64) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_trigger_definition` (`tpid`,`id`,`balance_type`,`direction`,`threshold_type`,`threshold_value`,`destination_id`,`actions_id`)
|
||||
UNIQUE KEY `unique_trigger_definition` (`tpid`,`tag`,`balance_type`,`direction`,`threshold_type`,`threshold_value`,`destination_id`,`actions_id`)
|
||||
);
|
||||
|
||||
--
|
||||
@@ -206,7 +206,7 @@ CREATE TABLE `tp_action_triggers` (
|
||||
|
||||
DROP TABLE IF EXISTS `tp_account_actions`;
|
||||
CREATE TABLE `tp_account_actions` (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`loadid` varchar(64) NOT NULL,
|
||||
`tenant` varchar(64) NOT NULL,
|
||||
@@ -214,7 +214,7 @@ CREATE TABLE `tp_account_actions` (
|
||||
`direction` varchar(8) NOT NULL,
|
||||
`action_plan_id` varchar(64),
|
||||
`action_triggers_id` varchar(64),
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`),
|
||||
UNIQUE KEY `unique_tp_account` (`tpid`,`loadid`,`tenant`,`account`,`direction`)
|
||||
);
|
||||
@@ -225,7 +225,7 @@ CREATE TABLE `tp_account_actions` (
|
||||
|
||||
DROP TABLE IF EXISTS tp_lcr_rules;
|
||||
CREATE TABLE tp_lcr_rules (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
`tenant` varchar(64) NOT NULL,
|
||||
@@ -236,7 +236,7 @@ CREATE TABLE tp_lcr_rules (
|
||||
`suppliers` varchar(64) NOT NULL,
|
||||
`activation_time` varchar(24) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
|
||||
@@ -246,7 +246,7 @@ CREATE TABLE tp_lcr_rules (
|
||||
|
||||
DROP TABLE IF EXISTS tp_derived_chargers;
|
||||
CREATE TABLE tp_derived_chargers (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`loadid` varchar(64) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
@@ -266,7 +266,7 @@ CREATE TABLE tp_derived_chargers (
|
||||
`setup_time_field` varchar(24) NOT NULL,
|
||||
`answer_time_field` varchar(24) NOT NULL,
|
||||
`usage_field` varchar(24) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
|
||||
@@ -277,9 +277,9 @@ CREATE TABLE tp_derived_chargers (
|
||||
|
||||
DROP TABLE IF EXISTS tp_cdr_stats;
|
||||
CREATE TABLE tp_cdr_stats (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`id` varchar(64) NOT NULL,
|
||||
`tag` varchar(64) NOT NULL,
|
||||
`queue_length` int(11) NOT NULL,
|
||||
`time_window` varchar(8) NOT NULL,
|
||||
`metrics` varchar(64) NOT NULL,
|
||||
@@ -300,6 +300,6 @@ CREATE TABLE tp_cdr_stats (
|
||||
`rated_subject` varchar(64) NOT NULL,
|
||||
`cost_interval` varchar(24) NOT NULL,
|
||||
`action_triggers` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `tpid` (`tpid`)
|
||||
);
|
||||
|
||||
@@ -205,3 +205,7 @@ func TestCallCostToDataCost(t *testing.T) {
|
||||
t.Error("Error coverting to data cost: ", string(js))
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
callcost_test.go:205: Error coverting to data cost: {"Direction":"*out","Category":"data","Tenant":"cgrates.org","Subject":"rif","Account":"","Destination":"*any","TOR":"*data","Cost":65,"DataSpans":[{"DataStart":0,"DataEnd":60,"Cost":60,"RateInterval":{"Timing":{"Years":null,"Months":[],"MonthDays":null,"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"RoundingMethod":"*middle","RoundingDecimals":4,"Rates":[{"GroupIntervalStart":0,"Value":1,"RateIncrement":60000000000,"RateUnit":1000000000},{"GroupIntervalStart":60000000000,"Value":1,"RateIncrement":1000000000,"RateUnit":1000000000}]},"Weight":10},"DataIndex":60,"Increments":[],"MatchedSubject":"","MatchedPrefix":"","MatchedDestId":""},{"DataStart":60,"DataEnd":65,"Cost":5,"RateInterval":{"Timing":{"Years":null,"Months":[],"MonthDays":null,"WeekDays":[],"StartTime":"00:00:00","EndTime":""},"Rating":{"ConnectFee":0,"RoundingMethod":"*middle","RoundingDecimals":4,"Rates":[{"GroupIntervalStart":0,"Value":1,"RateIncrement":60000000000,"RateUnit":1000000000},{"GroupIntervalStart":60000000000,"Value":1,"RateIncrement":1000000000,"RateUnit":1000000000}]},"Weight":10},"DataIndex":65,"Increments":[],"MatchedSubject":"*out:cgrates.org:data:rif","MatchedPrefix":"*any","MatchedDestId":"*any"}]}
|
||||
*/
|
||||
|
||||
@@ -29,9 +29,9 @@ import (
|
||||
// to be used by gorm orm
|
||||
|
||||
type TpTiming struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
Years string
|
||||
Months string
|
||||
MonthDays string
|
||||
@@ -40,16 +40,16 @@ type TpTiming struct {
|
||||
}
|
||||
|
||||
type TpDestination struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
Prefix string
|
||||
}
|
||||
|
||||
type TpRate struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
ConnectFee float64
|
||||
Rate float64
|
||||
RateUnit string
|
||||
@@ -58,9 +58,9 @@ type TpRate struct {
|
||||
}
|
||||
|
||||
type TpDestinationRate struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
DestinationsId string
|
||||
RatesId string
|
||||
RoundingMethod string
|
||||
@@ -68,16 +68,16 @@ type TpDestinationRate struct {
|
||||
}
|
||||
|
||||
type TpRatingPlan struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
DestratesId string
|
||||
TimingId string
|
||||
Weight float64
|
||||
}
|
||||
|
||||
type TpRatingProfile struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Loadid string
|
||||
Direction string
|
||||
@@ -103,7 +103,7 @@ func (rpf *TpRatingProfile) SetRatingProfileId(id string) error {
|
||||
}
|
||||
|
||||
type TpLcrRules struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Direction string
|
||||
Tenant string
|
||||
@@ -117,9 +117,9 @@ type TpLcrRules struct {
|
||||
}
|
||||
|
||||
type TpAction struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
Action string
|
||||
BalanceType string
|
||||
Direction string
|
||||
@@ -135,18 +135,18 @@ type TpAction struct {
|
||||
}
|
||||
|
||||
type TpActionPlan struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
ActionsId string
|
||||
TimingId string
|
||||
Weight float64
|
||||
}
|
||||
|
||||
type TpActionTrigger struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
BalanceType string
|
||||
Direction string
|
||||
ThresholdType string
|
||||
@@ -165,7 +165,7 @@ type TpActionTrigger struct {
|
||||
}
|
||||
|
||||
type TpAccountAction struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Loadid string
|
||||
Direction string
|
||||
@@ -188,16 +188,16 @@ func (aa *TpAccountAction) SetAccountActionId(id string) error {
|
||||
}
|
||||
|
||||
type TpSharedGroup struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
Account string
|
||||
Strategy string
|
||||
RatingSubject string
|
||||
}
|
||||
|
||||
type TpDerivedCharger struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Loadid string
|
||||
Direction string
|
||||
@@ -234,9 +234,9 @@ func (tpdc *TpDerivedCharger) SetDerivedChargersId(id string) error {
|
||||
}
|
||||
|
||||
type TpCdrStat struct {
|
||||
Tbid int64 `gorm:"primary_key:yes"`
|
||||
Id int64
|
||||
Tpid string
|
||||
Id string
|
||||
Tag string
|
||||
QueueLength int
|
||||
TimeWindow string
|
||||
Metrics string
|
||||
|
||||
@@ -171,7 +171,7 @@ func (self *SQLStorage) SetTPTiming(tm *utils.ApierTPTiming) error {
|
||||
if tm == nil {
|
||||
return nil //Nothing to set
|
||||
}
|
||||
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, id, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s') ON DUPLICATE KEY UPDATE years=values(years), months=values(months), month_days=values(month_days), week_days=values(week_days), time=values(time)",
|
||||
if _, err := self.Db.Exec(fmt.Sprintf("INSERT INTO %s (tpid, tag, years, months, month_days, week_days, time) VALUES('%s','%s','%s','%s','%s','%s','%s') ON DUPLICATE KEY UPDATE years=values(years), months=values(months), month_days=values(month_days), week_days=values(week_days), time=values(time)",
|
||||
utils.TBL_TP_TIMINGS, tm.TPid, tm.TimingId, tm.Years, tm.Months, tm.MonthDays, tm.WeekDays, tm.Time)); err != nil {
|
||||
|
||||
return err
|
||||
@@ -196,7 +196,7 @@ func (self *SQLStorage) RemTPData(table, tpid string, args ...string) error {
|
||||
tx = tx.Table(table).Where("tpid = ?", tpid)
|
||||
switch table {
|
||||
default:
|
||||
tx = tx.Where("id = ?", args[0])
|
||||
tx = tx.Where("tag = ?", args[0])
|
||||
case utils.TBL_TP_RATE_PROFILES:
|
||||
tx = tx.Where("loadid = ?", args[0]).Where("direction = ?", args[1]).Where("tenant = ?", args[2]).Where("category = ?", args[3]).Where("subject = ?", args[4])
|
||||
case utils.TBL_TP_ACCOUNT_ACTIONS:
|
||||
@@ -217,11 +217,11 @@ func (self *SQLStorage) SetTPDestination(tpid string, dest *Destination) error {
|
||||
return nil
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", dest.Id).Delete(TpDestination{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", dest.Id).Delete(TpDestination{})
|
||||
for _, prefix := range dest.Prefixes {
|
||||
db := tx.Save(TpDestination{
|
||||
Tpid: tpid,
|
||||
Id: dest.Id,
|
||||
Tag: dest.Id,
|
||||
Prefix: prefix,
|
||||
})
|
||||
if db.Error != nil {
|
||||
@@ -239,11 +239,11 @@ func (self *SQLStorage) SetTPRates(tpid string, rts map[string][]*utils.RateSlot
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for rtId, rSlots := range rts {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", rtId).Delete(TpRate{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", rtId).Delete(TpRate{})
|
||||
for _, rs := range rSlots {
|
||||
tx.Save(TpRate{
|
||||
Tpid: tpid,
|
||||
Id: rtId,
|
||||
Tag: rtId,
|
||||
ConnectFee: rs.ConnectFee,
|
||||
Rate: rs.Rate,
|
||||
RateUnit: rs.RateUnit,
|
||||
@@ -263,11 +263,11 @@ func (self *SQLStorage) SetTPDestinationRates(tpid string, drs map[string][]*uti
|
||||
|
||||
tx := self.db.Begin()
|
||||
for drId, dRates := range drs {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", drId).Delete(TpDestinationRate{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", drId).Delete(TpDestinationRate{})
|
||||
for _, dr := range dRates {
|
||||
tx.Save(TpDestinationRate{
|
||||
Tpid: tpid,
|
||||
Id: drId,
|
||||
Tag: drId,
|
||||
DestinationsId: dr.DestinationId,
|
||||
RatesId: dr.RateId,
|
||||
RoundingMethod: dr.RoundingMethod,
|
||||
@@ -285,11 +285,11 @@ func (self *SQLStorage) SetTPRatingPlans(tpid string, drts map[string][]*utils.T
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for rpId, rPlans := range drts {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", rpId).Delete(TpRatingPlan{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", rpId).Delete(TpRatingPlan{})
|
||||
for _, rp := range rPlans {
|
||||
tx.Save(TpRatingPlan{
|
||||
Tpid: tpid,
|
||||
Id: rpId,
|
||||
Tag: rpId,
|
||||
DestratesId: rp.DestinationRatesId,
|
||||
TimingId: rp.TimingId,
|
||||
Weight: rp.Weight,
|
||||
@@ -338,11 +338,11 @@ func (self *SQLStorage) SetTPSharedGroups(tpid string, sgs map[string][]*utils.T
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for sgId, sGroups := range sgs {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", sgId).Delete(TpSharedGroup{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", sgId).Delete(TpSharedGroup{})
|
||||
for _, sg := range sGroups {
|
||||
tx.Save(TpSharedGroup{
|
||||
Tpid: tpid,
|
||||
Id: sgId,
|
||||
Tag: sgId,
|
||||
Account: sg.Account,
|
||||
Strategy: sg.Strategy,
|
||||
RatingSubject: sg.RatingSubject,
|
||||
@@ -359,12 +359,12 @@ func (self *SQLStorage) SetTPCdrStats(tpid string, css map[string][]*utils.TPCdr
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for csId, cStats := range css {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", csId).Delete(TpCdrStat{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", csId).Delete(TpCdrStat{})
|
||||
for _, cs := range cStats {
|
||||
ql, _ := strconv.Atoi(cs.QueueLength)
|
||||
tx.Save(TpCdrStat{
|
||||
Tpid: tpid,
|
||||
Id: csId,
|
||||
Tag: csId,
|
||||
QueueLength: ql,
|
||||
TimeWindow: cs.TimeWindow,
|
||||
Metrics: cs.Metrics,
|
||||
@@ -471,11 +471,11 @@ func (self *SQLStorage) SetTPActions(tpid string, acts map[string][]*utils.TPAct
|
||||
|
||||
tx := self.db.Begin()
|
||||
for acId, acs := range acts {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", acId).Delete(TpAction{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", acId).Delete(TpAction{})
|
||||
for _, ac := range acs {
|
||||
tx.Save(TpAction{
|
||||
Tpid: tpid,
|
||||
Id: acId,
|
||||
Tag: acId,
|
||||
Action: ac.Identifier,
|
||||
BalanceType: ac.BalanceType,
|
||||
Direction: ac.Direction,
|
||||
@@ -496,7 +496,7 @@ func (self *SQLStorage) SetTPActions(tpid string, acts map[string][]*utils.TPAct
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTPActions(tpid, actsId string) (*utils.TPActions, error) {
|
||||
rows, err := self.Db.Query(fmt.Sprintf("SELECT action,balance_type,direction,units,expiry_time,destination_id,rating_subject,category,shared_group,balance_weight,extra_parameters,weight FROM %s WHERE tpid='%s' AND id='%s'", utils.TBL_TP_ACTIONS, tpid, actsId))
|
||||
rows, err := self.Db.Query(fmt.Sprintf("SELECT action,balance_type,direction,units,expiry_time,destination_id,rating_subject,category,shared_group,balance_weight,extra_parameters,weight FROM %s WHERE tpid='%s' AND tag='%s'", utils.TBL_TP_ACTIONS, tpid, actsId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -537,11 +537,11 @@ func (self *SQLStorage) SetTPActionTimings(tpid string, ats map[string][]*utils.
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for apId, aPlans := range ats {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", apId).Delete(TpActionPlan{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", apId).Delete(TpActionPlan{})
|
||||
for _, ap := range aPlans {
|
||||
tx.Save(TpActionPlan{
|
||||
Tpid: tpid,
|
||||
Id: apId,
|
||||
Tag: apId,
|
||||
ActionsId: ap.ActionsId,
|
||||
TimingId: ap.TimingId,
|
||||
Weight: ap.Weight,
|
||||
@@ -558,14 +558,14 @@ func (self *SQLStorage) GetTPActionTimings(tpid, tag string) (map[string][]*util
|
||||
var tpActionPlans []TpActionPlan
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpActionPlans).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tpAp := range tpActionPlans {
|
||||
ats[tpAp.Id] = append(ats[tpAp.Id], &utils.TPActionTiming{ActionsId: tpAp.ActionsId, TimingId: tpAp.TimingId, Weight: tpAp.Weight})
|
||||
ats[tpAp.Tag] = append(ats[tpAp.Tag], &utils.TPActionTiming{ActionsId: tpAp.ActionsId, TimingId: tpAp.TimingId, Weight: tpAp.Weight})
|
||||
}
|
||||
return ats, nil
|
||||
}
|
||||
@@ -576,7 +576,7 @@ func (self *SQLStorage) SetTPActionTriggers(tpid string, ats map[string][]*utils
|
||||
}
|
||||
tx := self.db.Begin()
|
||||
for atId, aTriggers := range ats {
|
||||
tx.Where("tpid = ?", tpid).Where("id = ?", atId).Delete(TpActionTrigger{})
|
||||
tx.Where("tpid = ?", tpid).Where("tag = ?", atId).Delete(TpActionTrigger{})
|
||||
for _, at := range aTriggers {
|
||||
recurrent := 0
|
||||
if at.Recurrent {
|
||||
@@ -584,7 +584,7 @@ func (self *SQLStorage) SetTPActionTriggers(tpid string, ats map[string][]*utils
|
||||
}
|
||||
tx.Save(TpActionTrigger{
|
||||
Tpid: tpid,
|
||||
Id: atId,
|
||||
Tag: atId,
|
||||
BalanceType: at.BalanceType,
|
||||
Direction: at.Direction,
|
||||
ThresholdType: at.ThresholdType,
|
||||
@@ -763,7 +763,7 @@ func (self *SQLStorage) GetStoredCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources
|
||||
var cdrs []*utils.StoredCdr
|
||||
var q *bytes.Buffer // Need to query differently since in case of primary, unmediated CDRs some values will be missing
|
||||
if ignoreDerived {
|
||||
q = bytes.NewBufferString(fmt.Sprintf("SELECT %s.cgrid,%s.tbid,%s.tor,%s.accid,%s.cdrhost,%s.cdrsource,%s.reqtype,%s.direction,%s.tenant,%s.category,%s.account,%s.subject,%s.destination,%s.setup_time,%s.answer_time,%s.`usage`,%s.extra_fields,%s.runid,%s.account,%s.subject,%s.cost FROM %s LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid AND %s.runid=%s.runid",
|
||||
q = bytes.NewBufferString(fmt.Sprintf("SELECT %s.cgrid,%s.id,%s.tor,%s.accid,%s.cdrhost,%s.cdrsource,%s.reqtype,%s.direction,%s.tenant,%s.category,%s.account,%s.subject,%s.destination,%s.setup_time,%s.answer_time,%s.`usage`,%s.extra_fields,%s.runid,%s.account,%s.subject,%s.cost FROM %s LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid AND %s.runid=%s.runid",
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
@@ -798,7 +798,7 @@ func (self *SQLStorage) GetStoredCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources
|
||||
utils.TBL_RATED_CDRS,
|
||||
utils.TBL_COST_DETAILS))
|
||||
} else {
|
||||
q = bytes.NewBufferString(fmt.Sprintf("SELECT %s.cgrid,%s.tbid,%s.tor,%s.accid,%s.cdrhost,%s.cdrsource,%s.reqtype,%s.direction,%s.tenant,%s.category,%s.account,%s.subject,%s.destination,%s.setup_time,%s.answer_time,%s.`usage`,%s.extra_fields,%s.runid,%s.account,%s.subject,%s.cost FROM %s LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid AND %s.runid=%s.runid",
|
||||
q = bytes.NewBufferString(fmt.Sprintf("SELECT %s.cgrid,%s.id,%s.tor,%s.accid,%s.cdrhost,%s.cdrsource,%s.reqtype,%s.direction,%s.tenant,%s.category,%s.account,%s.subject,%s.destination,%s.setup_time,%s.answer_time,%s.`usage`,%s.extra_fields,%s.runid,%s.account,%s.subject,%s.cost FROM %s LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid LEFT JOIN %s ON %s.cgrid=%s.cgrid AND %s.runid=%s.runid",
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
utils.TBL_CDRS_PRIMARY,
|
||||
@@ -1034,13 +1034,13 @@ func (self *SQLStorage) GetStoredCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources
|
||||
if fltr.Len() != 0 {
|
||||
fltr.WriteString(" AND")
|
||||
}
|
||||
fltr.WriteString(fmt.Sprintf(" %s.tbid>=%d", utils.TBL_CDRS_PRIMARY, orderIdStart))
|
||||
fltr.WriteString(fmt.Sprintf(" %s.id>=%d", utils.TBL_CDRS_PRIMARY, orderIdStart))
|
||||
}
|
||||
if orderIdEnd != 0 {
|
||||
if fltr.Len() != 0 {
|
||||
fltr.WriteString(" AND")
|
||||
}
|
||||
fltr.WriteString(fmt.Sprintf(" %s.tbid<%d", utils.TBL_CDRS_PRIMARY, orderIdEnd))
|
||||
fltr.WriteString(fmt.Sprintf(" %s.id<%d", utils.TBL_CDRS_PRIMARY, orderIdEnd))
|
||||
}
|
||||
if !timeStart.IsZero() {
|
||||
if fltr.Len() != 0 {
|
||||
@@ -1150,7 +1150,7 @@ func (self *SQLStorage) GetTpDestinations(tpid, tag string) (map[string]*Destina
|
||||
var tpDests []TpDestination
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpDests).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -1159,9 +1159,9 @@ func (self *SQLStorage) GetTpDestinations(tpid, tag string) (map[string]*Destina
|
||||
for _, tpDest := range tpDests {
|
||||
var dest *Destination
|
||||
var found bool
|
||||
if dest, found = dests[tpDest.Id]; !found {
|
||||
dest = &Destination{Id: tpDest.Id}
|
||||
dests[tpDest.Id] = dest
|
||||
if dest, found = dests[tpDest.Tag]; !found {
|
||||
dest = &Destination{Id: tpDest.Tag}
|
||||
dests[tpDest.Tag] = dest
|
||||
}
|
||||
dest.AddPrefix(tpDest.Prefix)
|
||||
}
|
||||
@@ -1173,7 +1173,7 @@ func (self *SQLStorage) GetTpRates(tpid, tag string) (map[string]*utils.TPRate,
|
||||
var tpRates []TpRate
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpRates).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -1186,19 +1186,19 @@ func (self *SQLStorage) GetTpRates(tpid, tag string) (map[string]*utils.TPRate,
|
||||
}
|
||||
r := &utils.TPRate{
|
||||
TPid: tpid,
|
||||
RateId: tr.Id,
|
||||
RateId: tr.Tag,
|
||||
RateSlots: []*utils.RateSlot{rs},
|
||||
}
|
||||
|
||||
// same tag only to create rate groups
|
||||
er, exists := rts[tr.Id]
|
||||
er, exists := rts[tr.Tag]
|
||||
if exists {
|
||||
if err := ValidNextGroup(er.RateSlots[len(er.RateSlots)-1], r.RateSlots[0]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
er.RateSlots = append(er.RateSlots, r.RateSlots[0])
|
||||
} else {
|
||||
rts[tr.Id] = r
|
||||
rts[tr.Tag] = r
|
||||
}
|
||||
}
|
||||
return rts, nil
|
||||
@@ -1209,7 +1209,7 @@ func (self *SQLStorage) GetTpDestinationRates(tpid, tag string, pagination *util
|
||||
var tpDestinationRates []TpDestinationRate
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if pagination != nil {
|
||||
limLow, limHigh := pagination.GetLimits()
|
||||
@@ -1223,7 +1223,7 @@ func (self *SQLStorage) GetTpDestinationRates(tpid, tag string, pagination *util
|
||||
for _, tpDr := range tpDestinationRates {
|
||||
dr := &utils.TPDestinationRate{
|
||||
TPid: tpid,
|
||||
DestinationRateId: tpDr.Id,
|
||||
DestinationRateId: tpDr.Tag,
|
||||
DestinationRates: []*utils.DestinationRate{
|
||||
&utils.DestinationRate{
|
||||
DestinationId: tpDr.DestinationsId,
|
||||
@@ -1233,13 +1233,13 @@ func (self *SQLStorage) GetTpDestinationRates(tpid, tag string, pagination *util
|
||||
},
|
||||
},
|
||||
}
|
||||
existingDR, exists := rts[tpDr.Id]
|
||||
existingDR, exists := rts[tpDr.Tag]
|
||||
if exists {
|
||||
existingDR.DestinationRates = append(existingDR.DestinationRates, dr.DestinationRates[0])
|
||||
} else {
|
||||
existingDR = dr
|
||||
}
|
||||
rts[tpDr.Id] = existingDR
|
||||
rts[tpDr.Tag] = existingDR
|
||||
|
||||
}
|
||||
return rts, nil
|
||||
@@ -1250,13 +1250,13 @@ func (self *SQLStorage) GetTpTimings(tpid, tag string) (map[string]*utils.ApierT
|
||||
var tpTimings []TpTiming
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpTimings).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, tpTm := range tpTimings {
|
||||
tms[tpTm.Id] = &utils.ApierTPTiming{TPid: tpTm.Tpid, TimingId: tpTm.Id, Years: tpTm.Years, Months: tpTm.Months, MonthDays: tpTm.MonthDays, WeekDays: tpTm.WeekDays, Time: tpTm.Time}
|
||||
tms[tpTm.Tag] = &utils.ApierTPTiming{TPid: tpTm.Tpid, TimingId: tpTm.Tag, Years: tpTm.Years, Months: tpTm.Months, MonthDays: tpTm.MonthDays, WeekDays: tpTm.WeekDays, Time: tpTm.Time}
|
||||
}
|
||||
return tms, nil
|
||||
}
|
||||
@@ -1267,7 +1267,7 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string, pagination *utils.Pag
|
||||
var tpRatingPlans []TpRatingPlan
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpRatingPlans).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -1285,10 +1285,10 @@ func (self *SQLStorage) GetTpRatingPlans(tpid, tag string, pagination *utils.Pag
|
||||
TimingId: tpRp.TimingId,
|
||||
Weight: tpRp.Weight,
|
||||
}
|
||||
if _, exists := rpbns[tpRp.Id]; exists {
|
||||
rpbns[tpRp.Id] = append(rpbns[tpRp.Id], rpb)
|
||||
if _, exists := rpbns[tpRp.Tag]; exists {
|
||||
rpbns[tpRp.Tag] = append(rpbns[tpRp.Tag], rpb)
|
||||
} else { // New
|
||||
rpbns[tpRp.Id] = []*utils.TPRatingPlanBinding{rpb}
|
||||
rpbns[tpRp.Tag] = []*utils.TPRatingPlanBinding{rpb}
|
||||
}
|
||||
}
|
||||
return rpbns, nil
|
||||
@@ -1349,14 +1349,14 @@ func (self *SQLStorage) GetTpSharedGroups(tpid, tag string) (map[string][]*utils
|
||||
var tpCdrStats []TpSharedGroup
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpCdrStats).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tpSg := range tpCdrStats {
|
||||
sgs[tpSg.Id] = append(sgs[tpSg.Id], &utils.TPSharedGroup{
|
||||
sgs[tpSg.Tag] = append(sgs[tpSg.Tag], &utils.TPSharedGroup{
|
||||
Account: tpSg.Account,
|
||||
Strategy: tpSg.Strategy,
|
||||
RatingSubject: tpSg.RatingSubject,
|
||||
@@ -1371,14 +1371,14 @@ func (self *SQLStorage) GetTpCdrStats(tpid, tag string) (map[string][]*utils.TPC
|
||||
var tpCdrStats []TpCdrStat
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpCdrStats).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, tpCs := range tpCdrStats {
|
||||
css[tpCs.Id] = append(css[tpCs.Id], &utils.TPCdrStat{
|
||||
css[tpCs.Tag] = append(css[tpCs.Tag], &utils.TPCdrStat{
|
||||
QueueLength: strconv.Itoa(tpCs.QueueLength),
|
||||
TimeWindow: tpCs.TimeWindow,
|
||||
Metrics: tpCs.Metrics,
|
||||
@@ -1458,7 +1458,7 @@ func (self *SQLStorage) GetTpLCRs(tpid, tag string) (map[string]*LCR, error) {
|
||||
lcrs := make(map[string]*LCR)
|
||||
q := fmt.Sprintf("SELECT * FROM %s WHERE tpid='%s'", utils.TBL_TP_LCRS, tpid)
|
||||
if tag != "" {
|
||||
q += fmt.Sprintf(" AND id='%s'", tag)
|
||||
q += fmt.Sprintf(" AND tag='%s'", tag)
|
||||
}
|
||||
rows, err := self.Db.Query(q)
|
||||
if err != nil {
|
||||
@@ -1513,7 +1513,7 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*utils.TPAc
|
||||
var tpActions []TpAction
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpActions).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -1534,7 +1534,7 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*utils.TPAc
|
||||
ExtraParameters: tpAc.ExtraParameters,
|
||||
Weight: tpAc.Weight,
|
||||
}
|
||||
as[tpAc.Id] = append(as[tpAc.Id], a)
|
||||
as[tpAc.Tag] = append(as[tpAc.Tag], a)
|
||||
}
|
||||
return as, nil
|
||||
}
|
||||
@@ -1544,7 +1544,7 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti
|
||||
var tpActionTriggers []TpActionTrigger
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("id = ?", tag)
|
||||
q = q.Where("tag = ?", tag)
|
||||
}
|
||||
if err := q.Find(&tpActionTriggers).Error; err != nil {
|
||||
return nil, err
|
||||
@@ -1569,7 +1569,7 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti
|
||||
ActionsId: tpAt.ActionsId,
|
||||
MinQueuedItems: tpAt.MinQueuedItems,
|
||||
}
|
||||
ats[tpAt.Id] = append(ats[tpAt.Id], at)
|
||||
ats[tpAt.Tag] = append(ats[tpAt.Tag], at)
|
||||
}
|
||||
return ats, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user