id->tag, tbid->id for more SQL best practices

This commit is contained in:
DanB
2014-11-03 16:18:09 +01:00
parent 74b1574e64
commit d7dd56035f
15 changed files with 152 additions and 148 deletions

View File

@@ -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`)
);

View File

@@ -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`)
);