ALTER TABLE providers ADD COLUMN periodic_check TINYINT default 0;
ALTER TABLE alerts ADD COLUMN clear_after INT(10) unsigned default 0;
ALTER TABLE alerts ADD COLUMN enable_provider_in_lcr tinyint(3) unsigned NOT NULL default 0;
ALTER TABLE alerts ADD COLUMN disable_provider_in_lcr tinyint(3) unsigned NOT NULL default 0;
ALTER TABLE acc_permissions CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_dst_new_score CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_dst_scoring CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_ip_new_score CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_ip_scoring CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_src_new_score CONVERT TO CHARACTER SET utf8;
ALTER TABLE bl_src_scoring CONVERT TO CHARACTER SET utf8;
CREATE TABLE IF NOT EXISTS `blanks` (`id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(255), `date` DATETIME, `description` TEXT, `value1` INT, `value2` DECIMAL(8,4), `value3` ENUM('yes', 'no') DEFAULT 'no') ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS active_calls_data (   id INT(11) AUTO_INCREMENT,   time timestamp,   count INT(10),   PRIMARY KEY(id),   INDEX USING BTREE(time) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS pbx_pools (id INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), comment TEXT, owner_id INT(11)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN pbx_pool_id int(11) NOT NULL DEFAULT 0;
ALTER TABLE devices MODIFY transport enum('udp','tcp','udp,tcp','tcp,udp','tls') default 'udp';
ALTER TABLE cron_settings ADD COLUMN inv_from SMALLINT DEFAULT NULL;
ALTER TABLE cron_settings ADD COLUMN inv_till SMALLINT DEFAULT NULL;
ALTER TABLE cron_settings ADD COLUMN inv_issue_day SMALLINT DEFAULT NULL;
ALTER TABLE cron_settings ADD COLUMN inv_send_after TINYINT DEFAULT NULL;
ALTER TABLE rates ADD COLUMN effective_from DATETIME DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `routing_groups` (`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `comment` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE IF NOT EXISTS `rgroup_dpeers` (`id` int UNSIGNED NOT NULL AUTO_INCREMENT, `routing_group_id` INT UNSIGNED NOT NULL, `dial_peer_id` INT UNSIGNED NOT NULL, `dial_peer_priority` INT UNSIGNED NOT NULL DEFAULT 1, PRIMARY KEY (`id`), INDEX `rgroup_dpeer_index` (`routing_group_id` ASC, `dial_peer_id` ASC)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE users ADD COLUMN hide_non_answered_calls TINYINT NOT NULL DEFAULT 0;
ALTER TABLE devices ADD COLUMN op TINYINT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN op_active TINYINT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN op_tech_prefix VARCHAR(50) NOT NULL DEFAULT '',ADD COLUMN op_routing_algorithm ENUM('lcr','quality','profit','weight','percent','by_dialpeer') NOT NULL DEFAULT 'lcr',ADD COLUMN op_routing_group_id INT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN op_tariff_id INT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN op_capacity INT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN op_src_regexp VARCHAR(1024) NOT NULL DEFAULT '.*',ADD COLUMN op_src_deny_regexp VARCHAR(1024) NOT NULL DEFAULT '',ADD COLUMN tp TINYINT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN tp_active TINYINT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN tp_tech_prefix VARCHAR(50) NOT NULL DEFAULT '',ADD COLUMN tp_tariff_id INT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN tp_capacity INT UNSIGNED NOT NULL DEFAULT 0,ADD COLUMN tp_src_regexp VARCHAR(1024) NOT NULL DEFAULT '.*',ADD COLUMN tp_src_deny_regexp VARCHAR(1024) NOT NULL DEFAULT '';
CREATE TABLE IF NOT EXISTS dpeer_tpoints (id INT UNSIGNED NOT NULL AUTO_INCREMENT,dial_peer_id INT UNSIGNED NOT NULL,device_id INT UNSIGNED NOT NULL,tp_percent INT UNSIGNED NOT NULL DEFAULT 100,tp_weight INT UNSIGNED NOT NULL DEFAULT 1,PRIMARY KEY (id),INDEX dial_peer_index USING BTREE (dial_peer_id ASC))ENGINE = InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS dial_peers (id INT UNSIGNED NOT NULL AUTO_INCREMENT, active TINYINT UNSIGNED NOT NULL DEFAULT 1, name VARCHAR(100) NOT NULL, comment VARCHAR(255) NOT NULL, dst_regexp VARCHAR(1024) NOT NULL, dst_deny_regexp VARCHAR(1024) NOT NULL, src_regexp VARCHAR(1024) NOT NULL, src_deny_regexp VARCHAR(1024) NOT NULL, weight INT UNSIGNED NOT NULL DEFAULT 1, stop_hunting TINYINT UNSIGNED NOT NULL DEFAULT 1, delta_price DECIMAL(8,4) NOT NULL DEFAULT 0, tp_priority ENUM('weight','percent','price') NOT NULL DEFAULT 'weight', PRIMARY KEY (id)) ENGINE = InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE invoices ADD COLUMN invoice_exchange_rate decimal(30,15) DEFAULT 1;
ALTER TABLE invoices ADD COLUMN invoice_currency varchar(255);
ALTER TABLE alerts MODIFY disable_provider_in_lcr INT(11) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE callerids DROP FOREIGN KEY device_id;
ALTER TABLE users  ADD COLUMN balance_min DECIMAL(10,4) DEFAULT 0;
ALTER TABLE users  ADD COLUMN balance_max DECIMAL(10,4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `m2_payments` (`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` INT(11) UNSIGNED DEFAULT NULL, `comment` varchar(255) DEFAULT NULL, `date` DATETIME DEFAULT NULL, `amount` decimal(30,15) DEFAULT '0.000000000000000', `amount_with_tax` decimal(30,15) DEFAULT '0.000000000000000', `currency_id` INT(11) UNSIGNED NOT NULL DEFAULT 1, `exchange_rate` decimal(30,15) NOT NULL DEFAULT 1, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE blanks ADD balance decimal(30,15) NOT NULL DEFAULT '0.0000';
ALTER TABLE users ADD COLUMN main_email VARCHAR(50);
ALTER TABLE users ADD COLUMN noc_email VARCHAR(50);
ALTER TABLE users ADD COLUMN billing_email VARCHAR(50);
ALTER TABLE users ADD COLUMN rates_email VARCHAR(50);
ALTER TABLE users ADD COLUMN warning_email_balance_admin decimal(30,15) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN warning_email_balance_manager decimal(30,15) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN `billing_period` ENUM ('weekly', 'bi-weekly', 'monthly') NOT NULL DEFAULT 'monthly';
ALTER TABLE users ADD COLUMN `invoice_grace_period` TINYINT(3) NOT NULL DEFAULT 15;
ALTER TABLE alerts ADD COLUMN clear_on_date DATETIME DEFAULT NULL;
ALTER TABLE users ADD COLUMN warning_email_sent_admin tinyint(4) DEFAULT 0;
ALTER TABLE users ADD COLUMN warning_email_sent_manager tinyint(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `aggregates` (`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,`uniqueid` bigint(11) unsigned NOT NULL DEFAULT 0, `direction` varchar(255) DEFAULT NULL, `destination` varchar(255) DEFAULT NULL, `prefix` varchar(255) DEFAULT NULL, `terminator_id` int(11) DEFAULT NULL, `user_id` int(11) DEFAULT NULL, `reseller_id` int(11) DEFAULT NULL, `time_period_id` int(11) NOT NULL DEFAULT 0, `user_billed` decimal(30,15) DEFAULT '0.000000000000000', `user_billed_with_tax` decimal(30,15) DEFAULT '0.000000000000000', `terminator_billed` decimal(30,15) DEFAULT '0.000000000000000', `user_billed_billsec` int(11) NOT NULL DEFAULT '0', `terminator_billed_billsec` int(11) NOT NULL DEFAULT '0', `billsec` int(11) NOT NULL DEFAULT '0', `real_billsec` decimal(30,15) DEFAULT '0.000000000000000',`answered_calls` int(11) NOT NULL DEFAULT '0', `total_calls` int(11) NOT NULL DEFAULT '0', `total_calls_for_user` int(11) NOT NULL DEFAULT '0', `variation` int(11) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`),UNIQUE KEY `uniqueid` (`uniqueid`), KEY `time_period_id_index` (`time_period_id`), KEY `user_id_index` (`user_id`), KEY `terminator_id_index` (`terminator_id`), KEY `reseller_id_index` (`reseller_id`), KEY `variation_index` (`variation`), KEY `prefix_index` (`prefix`(4)), KEY `direction_index` (`direction`), KEY `destination_index` (`destination`(6)) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `time_periods` (`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,`from_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `period_type` enum('hour', 'day', 'month', 'year'), PRIMARY KEY (`id`), KEY `from_date_index` (`from_date`),UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `m2_invoices` (`id` SERIAL, `number` VARCHAR(255) NOT NULL, `user_id` INT(11) UNSIGNED DEFAULT NULL, `status` ENUM ('In process', 'Sent through Email', 'Sent Manually', 'Accepted', 'Protested', 'Paid', 'Closed', 'Deleted', 'Changed')  NOT NULL DEFAULT 'In process', `status_changed` DATETIME NOT NULL, `created_at` DATETIME NOT NULL, `updated_at` DATETIME, `issue_date` DATETIME, `period_start` DATETIME NOT NULL, `period_end` DATETIME NOT NULL, `due_date` DATETIME, `timezone` VARCHAR(255) NOT NULL DEFAULT 'UTC', `client_name` VARCHAR(255) DEFAULT NULL, `client_details1` VARCHAR(255) DEFAULT NULL, `client_details2` VARCHAR(255) DEFAULT NULL, `client_details3` VARCHAR(255) DEFAULT NULL, `client_details4` VARCHAR(255) DEFAULT NULL, `client_details5` VARCHAR(255) DEFAULT NULL, `client_details6` VARCHAR(255) DEFAULT NULL, `currency` VARCHAR(50) NOT NULL DEFAULT 'eur', `currency_exchange_rate` DECIMAL(30,15), `total_amount` DECIMAL(30,15) DEFAULT '0.000000000000000', `total_amount_with_taxes` DECIMAL(30,15) DEFAULT '0.000000000000000', `comment` TEXT, `mailed_to_user` TINYINT(1) UNSIGNED DEFAULT NULL, `notified_admin` TINYINT(1) UNSIGNED DEFAULT NULL, `notified_manager` TINYINT(1) UNSIGNED DEFAULT NULL, PRIMARY KEY  (`id`), KEY `period_start_index` (`period_start`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `m2_invoice_lines` ( `id` SERIAL, `m2_invoice_id` INT(11) UNSIGNED DEFAULT NULL, `destination` VARCHAR(50) DEFAULT NULL, `name` VARCHAR(255) DEFAULT NULL, `rate` DECIMAL(30,15) DEFAULT '1.000000000000000', `calls` INT(50) UNSIGNED DEFAULT NULL, `total_time` INT(50) UNSIGNED DEFAULT NULL, `price` DECIMAL(30,15) DEFAULT '0.000000000000000', PRIMARY KEY  (`id`), KEY `m2_invoice_id_index` (`m2_invoice_id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN comment text;
ALTER TABLE `dial_peers` CHANGE `delta_price` `delta_price` DECIMAL(30,15) NOT NULL DEFAULT 0.000000000000000;
ALTER TABLE users ADD column routing_threshold_2 INT(11) NOT NULL DEFAULT -1;
ALTER TABLE users ADD column blacklist_lcr_2 INT(11) NOT NULL DEFAULT -1;
ALTER TABLE users ADD column routing_threshold_3 INT(11) NOT NULL DEFAULT -1;
ALTER TABLE users ADD column blacklist_lcr_3 INT(11) NOT NULL DEFAULT -1;
CREATE TABLE IF NOT EXISTS `timezones` (`id` int(11) NOT NULL AUTO_INCREMENT, `zone` varchar(100) NOT NULL UNIQUE, `offset` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `zone_index` (`zone`(4))) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE IF NOT EXISTS `code_decks` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `description` varchar(255) NOT NULL DEFAULT '', `owner_id` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE IF NOT EXISTS `code_deck_dest_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code_deck_id` int(11) NOT NULL DEFAULT 0, `destination_group_id` int(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE tariffs ADD COLUMN code_deck_id int(11) NOT NULL DEFAULT 1;
ALTER TABLE code_deck_dest_groups ADD INDEX code_deck_id_index ( code_deck_id );
ALTER TABLE code_deck_dest_groups ADD INDEX destination_group_id_index ( destination_group_id );
ALTER TABLE aggregates CHANGE user_id op_user_id int(11) DEFAULT '0';
ALTER TABLE aggregates CHANGE terminator_id tp_user_id int(11) DEFAULT '0';
ALTER TABLE aggregates CHANGE user_billed_billsec op_user_billed_billsec int(11) NOT NULL DEFAULT '0';
ALTER TABLE aggregates CHANGE terminator_billed_billsec tp_user_billed_billsec int(11) NOT NULL DEFAULT '0';
ALTER TABLE aggregates CHANGE user_billed op_user_billed decimal(30,15) DEFAULT '0.000000000000000';
ALTER TABLE aggregates CHANGE user_billed_with_tax op_user_billed_with_tax decimal(30,15) DEFAULT '0.000000000000000';
ALTER TABLE aggregates CHANGE terminator_billed tp_user_billed decimal(30,15) DEFAULT '0.000000000000000';
ALTER TABLE alerts ADD COLUMN notify_to_user INT(11) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN warning_balance_increases TINYINT NOT NULL DEFAULT 0;
ALTER TABLE alerts ADD COLUMN hgc INT(11) NOT NULL DEFAULT 0;
CREATE TABLE IF NOT EXISTS `dg_destinations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dg_id` int(11) NOT NULL, `destination_id` int(11) NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
DROP TABLE invoices;
DROP TABLE invoicedetails;
ALTER TABLE dpeer_tpoints ADD COLUMN active tinyint NOT NULL DEFAULT '1';
ALTER TABLE `callerids` DROP `email_callback`;
ALTER TABLE dg_destinations ADD INDEX name_index ( name );
DELETE FROM acc_rights WHERE nice_name = 'Manage_Services';
DELETE FROM acc_rights WHERE nice_name = 'Manage_subscriptions';
DROP TABLE services;
ALTER TABLE dg_destinations ADD INDEX dg_id_index ( dg_id );
INSERT IGNORE INTO dg_destinations (dg_id, destination_id, name) (SELECT destinations.destinationgroup_id, destinations.id, destinations.name FROM destinations LEFT JOIN dg_destinations ON dg_destinations.dg_id = destinations.destinationgroup_id AND dg_destinations.destination_id = destinations.id WHERE dg_destinations.id IS NULL AND destinations.destinationgroup_id > 0);
CREATE TABLE IF NOT EXISTS `alert_dependencies` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `owner_alert_id` bigint(20) unsigned NOT NULL, `alert_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE alerts MODIFY COLUMN alert_type ENUM('asr','acd','pdd','ttc','billsec_sum','calls_total','calls_answered','calls_not_answered','price_sum','sim_calls','hgc_absolute','hgc_percent', 'group');
ALTER TABLE alerts ADD COLUMN alert_when_more_than int(11) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE alerts ADD COLUMN clear_when_less_than int(11) UNSIGNED NOT NULL DEFAULT '0';
ALTER TABLE alerts ADD COLUMN name varchar(30) NOT NULL DEFAULT '';
ALTER TABLE alerts CHANGE action_clear_change_lcr_id action_clear_change_routing_group_id int(11) NOT NULL DEFAULT '0' COMMENT '->lcrs.id (-1 to restore original)';
ALTER TABLE alerts CHANGE action_alert_change_lcr_id action_alert_change_routing_group_id int(10) unsigned NOT NULL DEFAULT '0' COMMENT '->lcrs.id';
ALTER TABLE alerts CHANGE enable_provider_in_lcr enable_tp_in_dial_peer tinyint unsigned NOT NULL DEFAULT 0;
ALTER TABLE alerts CHANGE disable_provider_in_lcr disable_tp_in_dial_peer int(11) NOT NULL DEFAULT 0;
ALTER TABLE alerts CHANGE action_clear_restore_original_lcr action_clear_restore_original_dial_peer tinyint(3) unsigned NOT NULL DEFAULT '0';
ALTER TABLE alerts CHANGE before_alert_original_lcr_id before_alert_original_routing_group_id int(10) unsigned NOT NULL DEFAULT '0' COMMENT '->lcrs.id';
ALTER TABLE alerts MODIFY COLUMN check_type  enum('user','termination_point','origination_point','destination','destination_group') NOT NULL DEFAULT 'user';
ALTER TABLE `alert_contact_groups` ADD CONSTRAINT fk_alert_groups_id FOREIGN KEY fk_alert_groups(alert_group_id) REFERENCES alert_groups(id) ON DELETE CASCADE;
ALTER TABLE activecalls ADD COLUMN active TINYINT DEFAULT 0;
ALTER TABLE users ADD COLUMN ignore_global_alerts TINYINT DEFAULT 0;
ALTER TABLE server_loadstats ADD COLUMN cpu_freeswitch_load decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE server_loadstats ADD COLUMN cpu_media_load decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE server_loadstats ADD COLUMN cpu_b2bua_load decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE server_loadstats ADD COLUMN cpu_kamailio_load decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE numbers ADD INDEX number_pool_index ( number , number_pool_id );
ALTER TABLE devices CHANGE `op_src_regexp` `op_src_regexp` VARCHAR( 1024 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '.*';
ALTER TABLE aggregates ADD COLUMN dg_id INT(11);
ALTER TABLE dial_peers ADD COLUMN dst_dg_id INT(11);
ALTER TABLE devices ADD COLUMN custom_sip_header VARCHAR(255) DEFAULT NULL;
DROP TABLE voicemail_boxes;
DROP TABLE mohs;
DROP TABLE pbx_pools;
DROP TABLE pbxfunctions;
DROP TABLE vouchers;
DROP TABLE common_use_providers;
DROP TABLE cc_invoices;
DROP TABLE ccorders;
DROP TABLE cclineitems;
DROP TABLE cc_gmps;
DROP TABLE ringgroups;
DROP TABLE ringgroups_devices;
DROP TABLE ivrs;
DROP TABLE ivr_actions;
DROP TABLE ivr_action_logs;
DROP TABLE ivr_blocks;
DROP TABLE ivr_extensions;
DROP TABLE ivr_sound_files;
DROP TABLE ivr_timeperiods;
DROP TABLE ivr_voices;
DROP TABLE dialplans;
DROP TABLE queues;
DROP TABLE queue_agents;
DROP TABLE queue_periodic_announcements;
DROP TABLE quickforwarddids;
DROP TABLE quickforwards_rules;
DROP TABLE callflows;
DROP TABLE flatrate_data;
DROP TABLE flatrate_destinations;
DROP TABLE c2c_calls;
DROP TABLE c2c_campaigns;
DROP TABLE c2c_comments;
DROP TABLE c2c_commfields;
DROP TABLE c2c_invoicedetails;
DROP TABLE c2c_invoices;
DROP TABLE terminators;
DROP TABLE didrates;
ALTER TABLE rates ADD prefix VARCHAR( 60 ) NOT NULL DEFAULT '' AFTER tariff_id;
ALTER TABLE rates ADD INDEX prefix ( prefix ( 10 ) );
ALTER TABLE dial_peers ADD COLUMN tariff_id int(10) unsigned NOT NULL DEFAULT 0;
ALTER TABLE dial_peers CHANGE COLUMN dst_dg_id dst_mask varchar(255) NOT NULL DEFAULT '';
ALTER TABLE servers DROP COLUMN server_id;
CREATE TABLE IF NOT EXISTS `manager_groups` (`id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '', `comment` TEXT, UNIQUE (name)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
#ALTER TABLE users CHANGE acc_group_id manager_group_id INT NOT NULL DEFAULT 0; # total KO
ALTER TABLE users ADD COLUMN manager_group_id INT NOT NULL DEFAULT 0;
DROP TABLE acc_group_rights;
DROP TABLE acc_groups;
DROP TABLE acc_rights;
DROP TABLE acc_permissions;
ALTER TABLE users ADD COLUMN phone VARCHAR(30) NOT NULL DEFAULT '';
CREATE TABLE `manager_group_rights` (`id` int(11) NOT NULL AUTO_INCREMENT, `manager_group_id` int(11) NOT NULL, `manager_right_id` int(11) NOT NULL, `value` tinyint(4) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `manager_rights` (`id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', `nice_name` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE dial_peers CHANGE delta_price minimal_rate_margin DECIMAL(30,15);
ALTER TABLE dial_peers ADD COLUMN minimal_rate_margin_percent DECIMAL(30,15);
ALTER TABLE m2_invoices ADD confirmed_to_send_to_user TINYINT NOT NULL DEFAULT '0' COMMENT 'admin/manager confirms in GUI' AFTER comment;
ALTER TABLE devices ADD COLUMN register smallint NOT NULL DEFAULT 0;
CREATE TABLE hgc_mappings (id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, device_id BIGINT NOT NULL , hgc_incoming_id BIGINT NOT NULL DEFAULT '0' COMMENT 'hangupcausecodes.id', hgc_outgoing_id BIGINT NOT NULL DEFAULT '0' COMMENT 'hangupcausecodes.id', INDEX (device_id, hgc_incoming_id)) ENGINE = InnoDB DEFAULT CHARSET=utf8;
DROP TABLE code_decks;
DROP TABLE code_deck_dest_groups;
DROP TABLE dg_destinations;
ALTER TABLE `dial_peers` ADD COLUMN `no_follow` SMALLINT NOT NULL DEFAULT 0;
ALTER TABLE `routing_groups` ADD COLUMN `parent_routing_group_id` INT(11) DEFAULT -1;
ALTER TABLE time_periods ADD COLUMN last_call_id BIGINT(11) UNSIGNED DEFAULT NULL;
ALTER TABLE users ADD COLUMN enable_static_list enum('no', 'blacklist', 'whitelist') NOT NULL DEFAULT 'no';
ALTER TABLE users ADD static_list_id int(11) DEFAULT NULL;
ALTER TABLE users ADD COLUMN hide_non_answered_calls TINYINT NOT NULL DEFAULT 0;
ALTER TABLE devices ADD interpret_busy_as_failed TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD interpret_noanswer_as_failed TINYINT(4) DEFAULT 0;
ALTER TABLE call_logs MODIFY uniqueid VARCHAR(255) DEFAULT NULL;
ALTER TABLE rates DROP name;
# make sure subcode is not NULL
UPDATE destinations SET subcode = "" WHERE subcode IS NULL;
ALTER TABLE destinations CHANGE subcode subcode VARCHAR(5) NOT NULL DEFAULT '';
DROP TABLE cards;
DROP TABLE cardgroups;
DROP TABLE pdffaxes;
DROP TABLE pdffaxemails;
DROP TABLE phonebooks;
DROP TABLE recordings;
ALTER TABLE users CHANGE recording_enabled recording_enabled TINYINT(4) DEFAULT NULL;
ALTER TABLE users CHANGE recording_forced_enabled recording_forced_enabled TINYINT(4) DEFAULT NULL;
ALTER TABLE users CHANGE recording_hdd_quota recording_hdd_quota INT(11) DEFAULT NULL;
ALTER TABLE destinations DROP subcode, DROP city, DROP state, DROP lata, DROP tier, DROP ocn;
ALTER TABLE devices ADD COLUMN sticky_contact TINYINT(4) DEFAULT 0;
ALTER TABLE servers ADD COLUMN hdd_free_space INT(11) DEFAULT NULL;
ALTER TABLE destinationgroups DROP COLUMN desttype;
ALTER TABLE users ADD COLUMN enable_static_source_list enum('no', 'blacklist', 'whitelist') NOT NULL DEFAULT 'no';
ALTER TABLE users ADD static_source_list_id int(11) DEFAULT NULL;
ALTER TABLE rgroup_dpeers ADD COLUMN active tinyint(4) DEFAULT '1';
ALTER TABLE m2_invoices ADD COLUMN client_details7 VARCHAR(255) DEFAULT NULL;
ALTER TABLE devices ADD periodic_check tinyint(4) DEFAULT 0;
ALTER TABLE devices ADD alive tinyint(4) DEFAULT 0;
ALTER TABLE devices ADD op_custom_tariff_id INTEGER;
ALTER TABLE call_details ADD pcap BLOB DEFAULT NULL;
ALTER TABLE call_details ADD pcap_text TEXT DEFAULT NULL;
ALTER TABLE call_details ADD pcap_graph BLOB DEFAULT NULL;
ALTER TABLE background_tasks ADD COLUMN `data7` VARCHAR(255) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS blocked_ips (id INT(11) NOT NULL AUTO_INCREMENT, server_id INT(11) DEFAULT 0, blocked_ip VARCHAR(255) DEFAULT NULL, chain VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id));
ALTER table blocked_ips ADD COLUMN unblock int(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN ipaddr_range_start INT UNSIGNED DEFAULT 0;
ALTER TABLE devices ADD COLUMN ipaddr_range_end INT UNSIGNED DEFAULT 0;
ALTER TABLE call_logs ADD COLUMN radius_log TEXT DEFAULT NULL;
ALTER TABLE call_logs ADD COLUMN freeswitch_log TEXT DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `iplocations` (`id` int(11) NOT NULL AUTO_INCREMENT,`ip` varchar(255) NOT NULL,`latitude` decimal(30,15) DEFAULT '0.000000000000000',`longitude` decimal(30,15) DEFAULT '0.000000000000000',`country` varchar(255) DEFAULT NULL,`city` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN generate_invoice_manually INT DEFAULT 0;
ALTER TABLE devices MODIFY COLUMN op_routing_algorithm ENUM('lcr','quality','profit','weight','percent','by_dialpeer') NOT NULL DEFAULT 'lcr';
ALTER TABLE dial_peers MODIFY COLUMN tp_priority ENUM('weight','percent','price') NOT NULL DEFAULT 'weight';
ALTER TABLE devices ADD COLUMN op_destination_transformation VARCHAR(255) DEFAULT '';
ALTER TABLE dial_peers ADD INDEX active_index (active);
ALTER TABLE alerts MODIFY COLUMN alert_if_less DECIMAL(30,15) DEFAULT 0;
ALTER TABLE alerts MODIFY COLUMN alert_if_more DECIMAL(30,15) DEFAULT 0;
ALTER TABLE alerts MODIFY COLUMN value_at_alert DECIMAL(30,15) DEFAULT 0;
ALTER TABLE alerts MODIFY COLUMN value_at_clear DECIMAL(30,15) DEFAULT 0;
ALTER TABLE alerts MODIFY COLUMN clear_if_less DECIMAL(30,15) DEFAULT 0;
ALTER TABLE alerts MODIFY COLUMN clear_if_more DECIMAL(30,15) DEFAULT 0;
DROP TABLE lcr_partials;
DROP TABLE lcr_timeperiods;
DROP TABLE lcrproviders;
DROP TABLE lcrs;
DROP TABLE sms_adactions;
DROP TABLE sms_adnumbers;
DROP TABLE sms_campaigns;
DROP TABLE sms_lcrproviders;
DROP TABLE sms_lcrs;
DROP TABLE sms_messages;
DROP TABLE sms_providers;
DROP TABLE sms_rates;
DROP TABLE sms_tariffs;
DROP TABLE locationrules;
DROP TABLE locations;
DROP TABLE devicerules;
DROP TABLE providerrules;
DROP TABLE aratedetails;
DROP TABLE acustratedetails;
DROP TABLE customrates;
ALTER TABLE users ADD COLUMN show_hangupcause TINYINT DEFAULT 0;
CREATE TABLE IF NOT EXISTS cdr_export_templates (`id` BIGINT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL DEFAULT '', `columns` TEXT, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE background_tasks MODIFY COLUMN data6 TEXT;
ALTER TABLE cdr_export_templates ADD COLUMN nice_columns TEXT;
ALTER TABLE users MODIFY noc_email varchar(250);
ALTER TABLE users MODIFY main_email varchar(250);
ALTER TABLE users MODIFY billing_email varchar(250);
ALTER TABLE users MODIFY rates_email varchar(250);
ALTER TABLE addresses MODIFY email varchar(250);
CREATE TABLE IF NOT EXISTS `quality_routings` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`formula` varchar(255) DEFAULT NULL,`asr_calls` int(11) DEFAULT 50,`acd_calls` int(11) DEFAULT 50,`total_calls` int(11) DEFAULT 50,`total_answered_calls` int(11) DEFAULT 50,`total_failed_calls` int(11) DEFAULT 50,`total_billsec_calls` int(11) DEFAULT 50,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN quality_routing_id INT DEFAULT 0;
CREATE TABLE IF NOT EXISTS `quality_routing_stats` (`id` INT(11) NOT NULL AUTO_INCREMENT,`dp_id` INT(11) DEFAULT 0,`quality_routing_id` INT(11) DEFAULT 0,`csv` TEXT,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN op_source_transformation VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN tp_source_transformation VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN `disable_q850` TINYINT DEFAULT 0;
ALTER TABLE devices ADD COLUMN `forward_rpid` TINYINT DEFAULT 1;
ALTER TABLE devices ADD COLUMN `forward_pai` TINYINT DEFAULT 1;
ALTER TABLE devices ADD COLUMN bypass_media TINYINT DEFAULT 0;
ALTER TABLE dial_peers ADD INDEX active_index(active);
ALTER TABLE dial_peers ADD INDEX dst_regexp_index(dst_regexp);
ALTER TABLE dial_peers ADD INDEX dst_deny_regexp_index(dst_deny_regexp);
ALTER TABLE dial_peers ADD INDEX src_regexp_index(src_regexp);
ALTER TABLE dial_peers ADD INDEX src_deny_regexp_index(src_deny_regexp);
ALTER TABLE dial_peers ADD INDEX tariff_id_index(tariff_id);
ALTER TABLE dial_peers ADD INDEX dst_mask_index(dst_mask);
ALTER TABLE routing_groups ADD INDEX parent_routing_group_id_index(parent_routing_group_id);
ALTER TABLE devices MODIFY COLUMN op_capacity INT UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE devices MODIFY COLUMN tp_capacity INT UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE users MODIFY COLUMN balance_min DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users MODIFY COLUMN balance_max DECIMAL(30,15) DEFAULT 0;
ALTER TABLE devices ADD COLUMN disable_sip_uri_encoding TINYINT DEFAULT 1;
ALTER TABLE `directions` ADD COLUMN `iso3166code` VARCHAR(2) NOT NULL DEFAULT '00';
CREATE TABLE IF NOT EXISTS `blocked_countries` (`id` INT(11) NOT NULL auto_increment, `direction_id` INT(11) NOT NULL, `state` TINYINT(4) DEFAULT 0, PRIMARY KEY (`id`)) ENGINE=innodb DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS automatic_cdr_exports (`id` BIGINT NOT NULL AUTO_INCREMENT, `active` INT(11) DEFAULT 1, `user_id` INT(11) DEFAULT 0, `template_id` INT(11) DEFAULT 0, `name` VARCHAR(255) DEFAULT '', `period` VARCHAR(255) DEFAULT '', `timezone` VARCHAR(255) DEFAULT 'UTC', `send_to_user_id` INT(11) DEFAULT -1, `send_to_email` VARCHAR(255) DEFAULT '', `created_at` datetime DEFAULT NULL, `last_run_at` datetime DEFAULT NULL, `next_run_at` datetime DEFAULT NULL, `cdr_sql` TEXT, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE automatic_cdr_exports ADD COLUMN s_user VARCHAR(255) DEFAULT '', ADD COLUMN s_user_id INT(11) DEFAULT -2, ADD COLUMN s_origination_point VARCHAR(255) DEFAULT 'all', ADD COLUMN s_call_type VARCHAR(255) DEFAULT 'all', ADD COLUMN s_hgc INT(11) DEFAULT 0, ADD COLUMN s_destination_group VARCHAR(255) DEFAULT 'all', ADD COLUMN s_termination_point VARCHAR(255) DEFAULT 'all', ADD COLUMN s_source VARCHAR(255) DEFAULT '', ADD COLUMN s_destination VARCHAR(255) DEFAULT '', ADD COLUMN s_from DATETIME, ADD COLUMN s_till DATETIME, ADD COLUMN cdr_export_at_datetime DATETIME, ADD COLUMN cdr_export_at_time TIME;
ALTER TABLE iplocations ADD COLUMN approved TINYINT(4) DEFAULT 0, ADD COLUMN created_at DATETIME DEFAULT NULL, ADD COLUMN uniquehash VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN use_invite_dst TINYINT DEFAULT 0;
ALTER TABLE iplocations ADD COLUMN hostname VARCHAR(255), ADD COLUMN postal_code VARCHAR(255), ADD COLUMN state VARCHAR(255), ADD COLUMN continent VARCHAR(255), ADD COLUMN isp VARCHAR(255);
ALTER TABLE devices ADD COLUMN inherit_codec TINYINT DEFAULT 0;
ALTER TABLE devices ADD COLUMN enforce_lega_codecs TINYINT DEFAULT 0;
ALTER TABLE users ADD COLUMN max_call_rate DECIMAL(30,15) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `disputes`(`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `user_id` INT(11), `direction` TINYINT(4) DEFAULT 1, `period_start` DATETIME, `period_end` DATETIME, `time_zone` INT(11) DEFAULT 0, `time_shift` INT(11) DEFAULT 0, `billsec_tolerance`INT(11) DEFAULT 1, `cost_tolerance` DECIMAL(30,15) DEFAULT 0.0001, `cmp_last_src_digits`INT(11) DEFAULT 8, `cmp_last_dst_digits`INT(11) DEFAULT 8, `currency_id` INT(11) DEFAULT 0, `dispute_template_id` INT(11), `exchange_rate` DECIMAL(30,15) DEFAULT 1, `status` enum('WAITING','IN PROGRESS','DONE','FAILED') DEFAULT 'WAITING') engine=innodb DEFAULT charset=utf8;
CREATE TABLE IF NOT EXISTS `dispute_templates`(`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(255), `billsec_tolerance`INT(11) DEFAULT 1, `cost_tolerance` DECIMAL(30,15) DEFAULT 0.0001, `cmp_last_src_digits`INT(11) DEFAULT 8, `cmp_last_dst_digits`INT(11) DEFAULT 8, `currency_id` INT(11) DEFAULT 0) engine=innodb DEFAULT charset=utf8;
CREATE TABLE IF NOT EXISTS `disputed_cdrs`(`id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, `start_time` DATETIME, `answer_time` DATETIME, `end_time` DATETIME, `src` VARCHAR(80), `dst` VARCHAR(80), `billsec` INT(11) DEFAULT 0, `cost` DECIMAL(30,15) DEFAULT 0, `disposition` enum('ANSWERED','FAILED','BUSY','NO ANSWER'), `call_id` BIGINT, `dispute_id` INT(11), `mismatch_type` VARCHAR(2) DEFAULT '00') engine=innodb DEFAULT charset=utf8;
CREATE INDEX call_id_index ON disputed_cdrs (call_id);
CREATE INDEX dispute_id_index ON disputed_cdrs (dispute_id);
CREATE INDEX mismatch_type_index ON disputed_cdrs (mismatch_type);
ALTER TABLE `disputed_cdrs` ADD COLUMN `is_placeholder` INT DEFAULT 0;
ALTER TABLE `disputes` ADD COLUMN `message` TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS cdr_import_templates (id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(255), decimal_seperator CHAR(1) DEFAULT '.', column_seperator CHAR(1) DEFAULT ',', skip_n_first_lines TINYINT(4) DEFAULT 1, date_format VARCHAR(64), start_time_col TINYINT(4), answer_time_col TINYINT(4), end_time_col TINYINT(4), clid_col TINYINT(4), src_name_col TINYINT(4), src_number_col TINYINT(4), dst_col TINYINT(4), duration_col TINYINT(4), billsec_col TINYINT(4), disposition_col TINYINT(4), accountcode_col TINYINT(4), provider_id_col TINYINT(4), cost_col TINYINT(4), PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `dial_peers` ADD COLUMN `skip_failover_routing_group` INT DEFAULT 0;
ALTER TABLE `dial_peers` ADD COLUMN `secondary_tp_priority` VARCHAR(30) DEFAULT '';
ALTER TABLE servers MODIFY COLUMN server_type VARCHAR(50) DEFAULT '';
ALTER TABLE blanks ADD value4 enum('yes', 'no') DEFAULT 'no';
ALTER TABLE blanks ADD value5 enum('first', 'second', 'third') DEFAULT 'first';
ALTER TABLE blanks ADD value6 int(11);
CREATE TABLE IF NOT EXISTS `tp_deviations` (`id` INT(11) NOT NULL auto_increment, `device_id` INT(11), `dial_peer_id` INT(11), `check_period` INT(11) DEFAULT 10, `check_since` INT(11) DEFAULT 60, `asr_deviation` INT(11) DEFAULT 0, `acd_deviation` INT(11) DEFAULT 0, `user_id` INT(11),`email_id` INT(11), PRIMARY KEY (`id`)) ENGINE=innodb DEFAULT CHARSET=utf8;
ALTER TABLE `dpeer_tpoints` ADD COLUMN `warn_about_quality` INT(11) DEFAULT 0;
ALTER TABLE `users` ADD COLUMN `password_changed_at` INT(11);
ALTER TABLE users ADD COLUMN show_only_assigned_users TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN use_pai_if_cid_anonymous TINYINT(4) DEFAULT 0;
ALTER TABLE `cdr_import_templates` ADD `hangupcause_col` TINYINT;
ALTER TABLE devices ADD COLUMN ring_instead_progress TINYINT DEFAULT 0;
ALTER TABLE users MODIFY username VARCHAR(255) NOT NULL;
ALTER TABLE users MODIFY first_name VARCHAR(255) NOT NULL;
ALTER TABLE users MODIFY last_name VARCHAR(255) NOT NULL;
ALTER TABLE blocked_ips MODIFY COLUMN id BIGINT unsigned NOT NULL AUTO_INCREMENT;
ALTER TABLE devices ADD COLUMN set_sip_contact TINYINT DEFAULT 0;
ALTER TABLE activecalls ADD COLUMN provider_rate DECIMAL(30,15) DEFAULT 0;
ALTER TABLE server_loadstats ADD COLUMN `cpu_java_load` decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE disputes ADD COLUMN check_only_answered_calls TINYINT(4) DEFAULT 0;
ALTER TABLE dispute_templates ADD COLUMN check_only_answered_calls TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN hidden_device TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN change_rpidpai_host TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN progress_timeout INT(11) DEFAULT 0;
ALTER TABLE users ADD COLUMN billing_dynamic_from datetime DEFAULT '2008-01-01';
ALTER TABLE users ADD COLUMN billing_dynamic_days int(11) DEFAULT 0;
ALTER TABLE users CHANGE billing_period billing_period enum('weekly','bi-weekly','monthly','bimonthly','quarterly','halfyearly','dynamic') DEFAULT 'monthly';
ALTER TABLE users ADD COLUMN billing_run_at datetime DEFAULT '2008-01-01 00:00:00';
ALTER TABLE ratedetails ADD COLUMN blocked TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_match_tariff_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_use_pai_as_number TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_callerid_matches TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_dst_matches TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_dst_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE backups ADD COLUMN file_on_ftp TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN ignore_183nosdp INT(11) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `aggregate_templates` (`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `s_originator_id` INT(11), `s_originator` VARCHAR(100) DEFAULT '', `s_op_device` INT(11), `s_tp_device` INT(11), `s_terminator` VARCHAR(100), `s_terminator_id` INT(11), `src` VARCHAR(100) DEFAULT '',  `dst` VARCHAR(100) DEFAULT '', `s_duration` VARCHAR(100) DEFAULT '', `answered_calls` VARCHAR(100) DEFAULT '',`dst_group` VARCHAR(100) DEFAULT '', `price_orig_show` INT(11), `price_term_show` INT(11), `billed_time_orig_show` INT(11), `billed_time_term_show` INT(11), `duration_show` INT(11), `acd_show` INT(11), `calls_answered_show` INT(11), `asr_show` INT(11), `calls_total_show` INT(11), `profit_show` INT(11), `group_by_op` INT(11), `group_by_originator` INT(11), `group_by_terminator` INT(11), `group_by_tp` INT(11), `group_by_dst_group` INT(11), `group_by_dst` INT(11), `use_real_billsec` INT(11), `from_user_perspective` INT(11), `pdd_show` INT(11), `name` VARCHAR(100) DEFAULT '', `user_id` INT(11)) engine=innodb DEFAULT charset=utf8;
CREATE TABLE IF NOT EXISTS `auto_aggregate_exports` (`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `template_id` INT(11), `from` DATETIME DEFAULT '2008-01-01 00:00:00', `till` DATETIME DEFAULT '2008-01-01 00:00:00', `user_id` INT(11), `recurrence_type` VARCHAR(100) DEFAULT '', `frequency` INT(11) DEFAULT 0, `day_of_week` INT(11) DEFAULT 1, `day` INT(11) DEFAULT 1, `month` INT(11) DEFAULT 1, `frequency_type` INT(11) DEFAULT 0, `name` VARCHAR(100) DEFAULT '', `email` VARCHAR(512) DEFAULT '', `next_run_at` DATETIME DEFAULT '2008-01-01 00:00:00', `last_run_at` DATETIME DEFAULT '2008-01-01 00:00:00') engine=innodb DEFAULT charset=utf8;
ALTER TABLE auto_aggregate_exports ADD COLUMN owner_id INT(11) DEFAULT 0;
ALTER TABLE auto_aggregate_exports ADD COLUMN completed TINYINT(4) DEFAULT 0;
ALTER TABLE auto_aggregate_exports ADD COLUMN period INT(11) DEFAULT 0;
ALTER TABLE auto_aggregate_exports ADD COLUMN period_type INT(11) DEFAULT 0;
ALTER TABLE auto_aggregate_exports ADD COLUMN from_time INT(11) DEFAULT 0;
ALTER TABLE auto_aggregate_exports ADD COLUMN till_time INT(11) DEFAULT 23;
ALTER TABLE auto_aggregate_exports ADD COLUMN email_send_time INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_fake_ring TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `location` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,`username` char(64) NOT NULL DEFAULT '',`ruid` char(64) NOT NULL DEFAULT '',`domain` char(64) NOT NULL DEFAULT '',`contact` char(255) NOT NULL DEFAULT '',`received` char(128) DEFAULT NULL,`path` char(128) DEFAULT NULL,`instance` char(255) DEFAULT NULL,`expires` datetime NOT NULL DEFAULT '2030-05-28 21:32:15',`q` float(10,2) NOT NULL DEFAULT '1.00',`callid` char(255) NOT NULL DEFAULT 'Default-Call-ID',`cseq` int(11) NOT NULL DEFAULT '13',`last_modified` datetime NOT NULL DEFAULT '1900-01-01 00:00:01',`flags` int(11) NOT NULL DEFAULT '0',`cflags` int(11) NOT NULL DEFAULT '0',`user_agent` char(255) NOT NULL DEFAULT '',`socket` char(64) DEFAULT NULL,`methods` int(11) DEFAULT NULL,`reg_id` int(11) DEFAULT 0,`server_id` int(11) DEFAULT 0,`connection_id` int(11) DEFAULT 0,`keepalive` int(11) DEFAULT 0,`partition` int(11) DEFAULT 0,`sip_instance` char(255) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `account_contact_idx` (`username`,`domain`,`contact`,`callid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN dynamic VARCHAR(50) DEFAULT NULL;
ALTER TABLE devices MODIFY COLUMN port INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_username VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN op_password VARCHAR(255) DEFAULT '';
CREATE TABLE IF NOT EXISTS `tariff_rate_import_rules` (`id` INT(11) NOT NULL AUTO_INCREMENT,`name` VARCHAR(100) NOT NULL DEFAULT '',`comment` VARCHAR(256) NOT NULL DEFAULT '',`updated_at` TIMESTAMP,`rate_increase_value` TINYINT DEFAULT NULL,`rate_increase_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`rate_decrease_value` TINYINT DEFAULT NULL,`rate_decrease_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`new_rate_value` TINYINT DEFAULT NULL,`new_rate_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`rate_deletion_value` TINYINT DEFAULT NULL,`rate_deletion_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`rate_blocked_value` TINYINT DEFAULT NULL,`rate_blocked_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`oldest_effective_date_value` SMALLINT DEFAULT NULL,`oldest_effective_date_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`maximum_effective_date_value` SMALLINT DEFAULT NULL,`maximum_effective_date_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`max_increase_value` DECIMAL(14,4) DEFAULT NULL,`max_increase_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`max_decrease_value` DECIMAL(14,4) DEFAULT NULL,`max_decrease_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`max_rate_value` DECIMAL(14,4) DEFAULT NULL,`max_rate_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`zero_rate_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`duplicate_rate_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`min_times_value` VARCHAR(100) DEFAULT NULL,`min_times_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`increments_value` VARCHAR(100) DEFAULT NULL,`increments_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',`code_moved_to_new_zone_action` ENUM('none', 'alert', 'reject rate') NOT NULL DEFAULT 'none',PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tariff_templates` (`id` INT(11) NOT NULL AUTO_INCREMENT,`name` VARCHAR(100) NOT NULL DEFAULT '',`rate_sheet` VARCHAR(2) DEFAULT '1',`header_lines` SMALLINT NOT NULL DEFAULT 0,`prefix_column` VARCHAR(2) DEFAULT NULL, `prefix_column2` VARCHAR(2) DEFAULT NULL, `destination_column` VARCHAR(2) DEFAULT NULL, `[REDACTED]` VARCHAR(2) DEFAULT NULL, `connection_fee_column` VARCHAR(2) DEFAULT NULL, `first_interval_rate_column` VARCHAR(2) DEFAULT NULL, `first_interval_mintime_column` VARCHAR(2) DEFAULT NULL, `first_interval_mintime_field` TINYINT DEFAULT NULL, `first_interval_increment_column` VARCHAR(2) DEFAULT NULL, `first_interval_increment_field` TINYINT DEFAULT NULL, `second_interval_rate_column` VARCHAR(2) DEFAULT NULL, `second_interval_mintime_column` VARCHAR(2) DEFAULT NULL, `second_interval_mintime_field` TINYINT DEFAULT NULL, `second_interval_increment_column` VARCHAR(2) DEFAULT NULL, `second_interval_increment_field` TINYINT DEFAULT NULL, `off_peak_first_interval_rate_column` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_mintime_column` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_mintime_field` TINYINT DEFAULT NULL, `off_peak_first_interval_increment_column` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_increment_field` TINYINT DEFAULT NULL, `off_peak_second_interval_rate_column` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_mintime_column` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_mintime_field` TINYINT DEFAULT NULL, `off_peak_second_interval_increment_column` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_increment_field` TINYINT DEFAULT NULL, `effective_date_option` TINYINT NOT NULL DEFAULT 0, `effective_date_column` VARCHAR(2) DEFAULT NULL, `effective_date_column2` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_sheet` TINYINT DEFAULT NULL, `effective_date_mapping_datetime` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_column_sheet` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_column_main` VARCHAR(2) DEFAULT NULL, `end_date_column` VARCHAR(2) DEFAULT NULL, `effective_date_format` VARCHAR(50) DEFAULT NULL, `prefix_column_secondary` VARCHAR(2) DEFAULT NULL, `prefix_column2_secondary` VARCHAR(2) DEFAULT NULL, `destination_column_secondary` VARCHAR(2) DEFAULT NULL, `[REDACTED]` VARCHAR(2) DEFAULT NULL, `connection_fee_column_secondary` VARCHAR(2) DEFAULT NULL, `first_interval_rate_column_secondary` VARCHAR(2) DEFAULT NULL, `first_interval_mintime_column_secondary` VARCHAR(2) DEFAULT NULL, `first_interval_mintime_field_secondary` TINYINT DEFAULT NULL, `first_interval_increment_column_secondary` VARCHAR(2) DEFAULT NULL, `first_interval_increment_field_secondary` TINYINT DEFAULT NULL, `second_interval_rate_column_secondary` VARCHAR(2) DEFAULT NULL, `second_interval_mintime_column_secondary` VARCHAR(2) DEFAULT NULL, `second_interval_mintime_field_secondary` TINYINT DEFAULT NULL, `second_interval_increment_column_secondary` VARCHAR(2) DEFAULT NULL, `second_interval_increment_field_secondary` TINYINT DEFAULT NULL, `off_peak_first_interval_rate_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_mintime_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_mintime_field_secondary` TINYINT DEFAULT NULL, `off_peak_first_interval_increment_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_first_interval_increment_field_secondary` TINYINT DEFAULT NULL, `off_peak_second_interval_rate_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_mintime_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_mintime_field_secondary` TINYINT DEFAULT NULL, `off_peak_second_interval_increment_column_secondary` VARCHAR(2) DEFAULT NULL, `off_peak_second_interval_increment_field_secondary` TINYINT DEFAULT NULL, `effective_date_option_secondary` TINYINT NOT NULL DEFAULT 0, `effective_date_column_secondary` VARCHAR(2) DEFAULT NULL, `effective_date_column2_secondary` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_sheet_secondary` TINYINT DEFAULT NULL, `effective_date_mapping_datetime_secondary` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_column_sheet_secondary` VARCHAR(2) DEFAULT NULL, `effective_date_mapping_column_main_secondary` VARCHAR(2) DEFAULT NULL, `end_date_column_secondary` VARCHAR(2) DEFAULT NULL, `currency_exchange_rate` DECIMAL(24,8) DEFAULT NULL, `deleted_rates_column` VARCHAR(2) DEFAULT NULL, `deleted_rates_text` VARCHAR(50) DEFAULT NULL, `blocked_rates_column` VARCHAR(2) DEFAULT NULL, `blocked_rates_text` VARCHAR(50) DEFAULT NULL, `generated_template` TEXT, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE m2_invoices ADD COLUMN grace_period TINYINT(4) DEFAULT 0;
ALTER TABLE emails ADD COLUMN email_type INT(11) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `tariff_email_details` (`id` INT(11) NOT NULL AUTO_INCREMENT,`email_id` INT(11),`attachment_type` ENUM('xlsx') DEFAULT 'xlsx',`date_format` VARCHAR(20),`filename` VARCHAR(256),`header` VARCHAR(10000) DEFAULT NULL,`footer` VARCHAR(10000) DEFAULT NULL,`level_of_detail` ENUM('basic', 'normal', 'full') DEFAULT 'normal',`import_details` TINYINT(1) DEFAULT 1,`change_summary` TINYINT(1) DEFAULT 1,`import_errors` TINYINT(1) DEFAULT 1,`rate_changes` TINYINT(1) DEFAULT 1,`notice_period_breaches` TINYINT(1) DEFAULT 1,`rejected_rates` TINYINT(1) DEFAULT 1,PRIMARY KEY (`id`),UNIQUE (`email_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tariff_template_exceptions` (`id` INT(11) NOT NULL AUTO_INCREMENT,`tariff_template_id` INT(11) NOT NULL, `exception_type` ENUM('connection_fee_change', 'first_interval_rate_change', 'first_interval_increment_change', 'first_interval_mintime_change', 'second_interval_rate_change', 'second_interval_increment_change', 'second_interval_mintime_change', 'off_peak_first_interval_rate_change', 'off_peak_first_interval_increment_change', 'off_peak_first_interval_mintime_change', 'off_peak_second_interval_rate_change', 'off_peak_second_interval_increment_change', 'off_peak_second_interval_mintime_change') NOT NULL DEFAULT 'connection_fee_change', `destination_mask` VARCHAR(150) NOT NULL DEFAULT '', `value` VARCHAR(50) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `tariff_template_id_index` (`tariff_template_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `tariff_import_rules` (`id` INT(11) NOT NULL AUTO_INCREMENT,	`name` VARCHAR(100) NOT NULL DEFAULT '',`priority` INT(11) NOT NULL,`active` TINYINT NOT NULL DEFAULT 1,`tariff_rate_import_rule_id` INT(11) DEFAULT NULL,`tariff_id` INT(11) DEFAULT NULL,`import_type` ENUM('add_update', 'replace') DEFAULT 'add_update',`tariff_template_id` INT(11) DEFAULT NULL,`effective_date_from` ENUM('template', 'subject', 'file_name') DEFAULT 'template',`effective_date_prefix` VARCHAR (256) DEFAULT NULL,`effective_date_format` VARCHAR (256) DEFAULT NULL,`manual_review` TINYINT NOT NULL DEFAULT 1,`stop_processing_more_rules` TINYINT NOT NULL DEFAULT 0,`mail_from` VARCHAR(1024) NOT NULL DEFAULT '%@%.%',`mail_sender` VARCHAR(256) DEFAULT NULL,`mail_subject` VARCHAR(256) DEFAULT NULL,`mail_text` VARCHAR(256) DEFAULT NULL,`file_name` VARCHAR(256) DEFAULT NULL,`trigger_received_email_notification_id` INT(11) DEFAULT NULL,`trigger_received_email_notification_recipients` VARCHAR(256) DEFAULT NULL,`trigger_review_email_notification_id` INT(11) DEFAULT NULL,`trigger_review_email_notification_recipients` VARCHAR(256) DEFAULT NULL,`trigger_imported_email_notification_id` INT(11) DEFAULT NULL,`trigger_imported_email_notification_recipients` VARCHAR(256) DEFAULT NULL,`trigger_errors_email_notification_id` INT(11) DEFAULT NULL,`trigger_errors_email_notification_recipients` VARCHAR(256) DEFAULT NULL,`trigger_rejected_email_notification_id` INT(11) DEFAULT NULL,`trigger_rejected_email_notification_recipients` VARCHAR(256) DEFAULT NULL,PRIMARY KEY (`id`),KEY `tariff_rate_import_rule_id_index` (`tariff_rate_import_rule_id`),KEY `tariff_id_index` (`tariff_id`),KEY `tariff_template_id_index` (`tariff_template_id`),KEY `trigger_received_email_notification_id_index` (`trigger_received_email_notification_id`),KEY `trigger_review_email_notification_id_index` (`trigger_review_email_notification_id`),KEY `trigger_imported_email_notification_id_index` (`trigger_imported_email_notification_id`),KEY `trigger_errors_email_notification_id_index` (`trigger_errors_email_notification_id`),KEY `trigger_rejected_email_notification_id_index` (`trigger_rejected_email_notification_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN cip VARCHAR(20) DEFAULT NULL;
ALTER TABLE numbers ADD COLUMN counter BIGINT(20) DEFAULT 0;
ALTER TABLE numbers ADD INDEX counter_index (counter);
ALTER TABLE devices ADD COLUMN callerid_number_pool_type VARCHAR(20) DEFAULT "random";
ALTER TABLE devices ADD COLUMN callerid_number_pool_deviation int(11) DEFAULT 5;
ALTER TABLE devices ALTER callerid_number_pool_deviation SET DEFAULT 5;
CREATE TABLE IF NOT EXISTS `tariff_emails` (`id` int(11) NOT NULL auto_increment,`from_email` varchar(100) NOT NULL,`from_name` varchar(100) NOT NULL,`reply_to` text NOT NULL,`delivered_to` text NOT NULL,`received` datetime NOT NULL,`subject` varchar(256) NOT NULL,`source` text NOT NULL,`cc` text NOT NULL,`message_plain` text NOT NULL,`message_plain_charset` varchar(50) NOT NULL,`message_html` text NOT NULL,`message_html_charset` varchar(50) NOT NULL,`folder` enum('inbox','complete','junk','') NOT NULL DEFAULT 'inbox',PRIMARY KEY  (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `tariff_attachments` (`id` int(11) NOT NULL auto_increment, `tariff_email_id` int(11) NOT NULL, `file_full_name` varchar(256) NOT NULL, `file_name` varchar(256) NOT NULL, `file_extension` varchar(20) NOT NULL, `file_type` varchar(50) NOT NULL, `size_bytes` bigint(20) NOT NULL, `data` mediumblob NOT NULL, PRIMARY KEY  (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
CREATE TABLE IF NOT EXISTS `tariff_jobs` (`id` INT(11) NOT NULL AUTO_INCREMENT, `created_at` DATETIME, `updated_at` TIMESTAMP, `status` VARCHAR(100) NOT NULL, `tariff_import_rule_id` INT(11) NOT NULL, `trigger_received_email_notification_sent` TINYINT NOT NULL DEFAULT 0, `file_received_at` DATETIME, `imported_at` DATETIME, `commited_at` DATETIME, `rate_changes` INT(11), `increases` INT(11), `descreases` INT(11), `new` INT(11), `deleted` INT(11), `breaches` INT(11), `blocked` INT(11), `other` INT(11), `rejected` INT(11), `rate_errors` INT(11), PRIMARY KEY (`id`), KEY `tariff_import_rule_id_index` (`tariff_import_rule_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE tariff_attachments ADD COLUMN status VARCHAR(100) DEFAULT NULL;
ALTER TABLE tariff_attachments ADD COLUMN tariff_import_rule_id INT(11) DEFAULT NULL;
ALTER TABLE tariff_jobs ADD COLUMN tariff_attachment_id INT(11) DEFAULT NULL;
ALTER TABLE tariff_jobs ADD COLUMN status_reason VARCHAR(255) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `user_balances` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `balance_delta` decimal(30,15) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
ALTER TABLE tariff_jobs ADD COLUMN effective_date DATETIME DEFAULT NULL;
ALTER TABLE users ADD COLUMN send_warning_balance_sms TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `tariffs` DROP `code_deck_id`;
ALTER TABLE dial_peers ADD COLUMN call_limit INT(11) DEFAULT 0;
ALTER TABLE `tariffs` ADD `changes_present` INT NOT NULL DEFAULT '1';
ALTER TABLE `tariffs` ADD INDEX `changes_index` ( `changes_present` );
ALTER TABLE `dial_peers` CHANGE `src_regexp` `src_regexp` VARCHAR( 1024 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '.*';
ALTER TABLE dpeer_tpoints ADD COLUMN tp_cps INT(11) DEFAULT 0;
ALTER TABLE dpeer_tpoints ADD COLUMN tp_call_limit INT(11) DEFAULT 0;
ALTER TABLE tariff_jobs ADD COLUMN reviewed TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE tariff_import_rules ADD COLUMN default_connection_fee DECIMAL(30,15) DEFAULT 0;
ALTER TABLE tariff_import_rules ADD COLUMN default_increment INT(11) DEFAULT 1;
ALTER TABLE tariff_import_rules ADD COLUMN default_min_time INT(11) DEFAULT 0;
ALTER TABLE tariff_import_rules ADD COLUMN reject_if_errors TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE tariff_import_rules ALTER reject_if_errors SET DEFAULT 1;
ALTER TABLE tariff_import_rules ADD COLUMN default_effective_from TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE devices ADD COLUMN tariff_intra INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tariff_inter INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tariff_indeter INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN us_jurisdictional_routing TINYINT(4) DEFAULT 0;
ALTER TABLE `devices` CHANGE `tariff_intra` `op_tariff_intra` INT( 11 ) NULL DEFAULT '0';
ALTER TABLE `devices` CHANGE `tariff_inter` `op_tariff_inter` INT( 11 ) NULL DEFAULT '0';
ALTER TABLE `devices` CHANGE `tariff_indeter` `op_tariff_indeter` INT( 11 ) NULL DEFAULT '0';
ALTER TABLE devices ADD COLUMN tp_tariff_intra INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_tariff_inter INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_tariff_indeter INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_us_jurisdictional_routing TINYINT(4) DEFAULT 0;
ALTER TABLE users ADD COLUMN billing_dynamic_generation_time INT(11) DEFAULT 24;
ALTER TABLE devices DROP COLUMN cip;
CREATE TABLE IF NOT EXISTS `rate_notification_jobs` (`id` INT(11) NOT NULL AUTO_INCREMENT, `created_at` DATETIME, `updated_at` TIMESTAMP, `status` VARCHAR(100) NOT NULL, `status_reason` VARCHAR(255), `tariff_id` BIGINT(20) NOT NULL, `user_id` BIGINT(20) NOT NULL, `email_id` INT(11) NOT NULL, `xlsx_template_id` INT(11), `rate_notification_type` TINYINT(4) NOT NULL DEFAULT 0, `agreement_timeout` INT(11) NOT NULL, `agreement_timeout_datetime` DATETIME NOT NULL, `client_agreement` TINYINT(4) NOT NULL DEFAULT 0, `client_agreement_datetime` DATETIME, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN op_use_pai_number_for_routing VARCHAR(50) NOT NULL DEFAULT 'never';
ALTER TABLE devices ADD COLUMN op_send_pai_number_as_caller_id_to_tp VARCHAR(50) NOT NULL DEFAULT 'never';
ALTER TABLE `tariffs` ADD `last_change_datetime` DATETIME DEFAULT NULL;
ALTER TABLE `rate_notification_jobs` ADD INDEX `tariff_id_index` ( `tariff_id` );
ALTER TABLE `rate_notification_jobs` ADD INDEX `user_id_index` ( `user_id` );
ALTER TABLE devices ADD COLUMN tp_from_domain VARCHAR(100) DEFAULT '';
CREATE TABLE IF NOT EXISTS `mnp_prefixes` (`id` INT(11) NOT NULL AUTO_INCREMENT, `prefix` VARCHAR(60) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE rate_notification_jobs ADD COLUMN unique_url_agree VARCHAR(255) DEFAULT NULL;
ALTER TABLE rate_notification_jobs ADD COLUMN unique_url_disagree VARCHAR(255) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `mnp_carrier_groups` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `mnp_carrier_codes` (`id` INT(11) NOT NULL AUTO_INCREMENT, `mnp_carrier_group_id` INT(11) NOT NULL, `code` VARCHAR(60) NOT NULL, PRIMARY KEY (`id`), KEY `mnp_carrier_group_id_index` (`mnp_carrier_group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN mnp_carrier_group_id INT(11) DEFAULT NULL, ADD INDEX `mnp_carrier_group_id_index` (`mnp_carrier_group_id`);
ALTER TABLE devices ADD COLUMN mnp_use TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN mnp_routing_group_id INT(11) DEFAULT NULL;
ALTER TABLE servers ADD COLUMN es TINYINT(4) DEFAULT 0;
ALTER TABLE servers ADD COLUMN fs TINYINT(4) DEFAULT 0;
ALTER TABLE servers ADD COLUMN proxy TINYINT(4) DEFAULT 0;
ALTER TABLE rate_notification_jobs ADD COLUMN last_email_sent_at DATETIME;
ALTER TABLE servers ADD COLUMN fs_status TINYINT(4) DEFAULT 0;
ALTER TABLE servers ADD COLUMN radius_status TINYINT(4) DEFAULT 0;
ALTER TABLE dial_peers MODIFY COLUMN dst_regexp VARCHAR(1024) NOT NULL;
ALTER TABLE dial_peers MODIFY COLUMN dst_deny_regexp VARCHAR(1024) NOT NULL;
ALTER TABLE dial_peers MODIFY COLUMN src_regexp VARCHAR(1024) NOT NULL DEFAULT '.*';
ALTER TABLE dial_peers MODIFY COLUMN src_deny_regexp VARCHAR(1024) NOT NULL;
ALTER TABLE devices MODIFY COLUMN op_src_regexp VARCHAR(1024) NOT NULL DEFAULT '.*';
ALTER TABLE devices MODIFY COLUMN op_src_deny_regexp VARCHAR(1024) NOT NULL DEFAULT '';
ALTER TABLE devices MODIFY COLUMN tp_src_regexp VARCHAR(1024) NOT NULL DEFAULT '.*';
ALTER TABLE devices MODIFY COLUMN tp_src_deny_regexp VARCHAR(1024) NOT NULL DEFAULT '';
ALTER TABLE alerts ADD COLUMN action_alert_sms_text varchar(160) NOT NULL DEFAULT '';
ALTER TABLE alerts ADD COLUMN action_clear_sms_text varchar(160) NOT NULL DEFAULT '';
ALTER TABLE m2_payments ADD COLUMN user_balance_before DECIMAL(30,15);
ALTER TABLE m2_payments ADD COLUMN user_balance_after DECIMAL(30,15);
ALTER TABLE alerts ADD COLUMN check_type_secondary VARCHAR(50);
ALTER TABLE alerts ADD COLUMN check_data_secondary VARCHAR(50);
ALTER TABLE alerts ADD COLUMN action_alert_disable_dp_in_rg TINYINT(4) DEFAULT 0;
ALTER TABLE alerts ADD COLUMN action_clear_enable_dp_in_rg TINYINT(4) DEFAULT 0;
ALTER TABLE alerts ADD COLUMN dial_peer_id INT(11);
ALTER TABLE aggregate_templates ADD COLUMN group_by_manager TINYINT(4);
ALTER TABLE aggregate_templates ADD COLUMN profit_percent_show TINYINT(4);
ALTER TABLE aggregate_templates ADD COLUMN s_manager INT(4);
CREATE TABLE IF NOT EXISTS `tariff_link_attachment_rules` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `string_start` VARCHAR(255), `string_end` VARCHAR(255), `priority` INT(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE tariff_link_attachment_rules ADD COLUMN link_pattern VARCHAR(255);
ALTER TABLE tariff_jobs ADD COLUMN schedule_import_at DATETIME DEFAULT NULL;
ALTER TABLE tariff_jobs ADD COLUMN temporary_tariff_id BIGINT(20) DEFAULT NULL;
ALTER TABLE servers ADD COLUMN b2bua TINYINT(4) DEFAULT 0;
ALTER TABLE servers ADD COLUMN media TINYINT(4) DEFAULT 0;
ALTER TABLE users ADD COLUMN generate_prepaid_invoice TINYINT(4) DEFAULT 0;
ALTER TABLE m2_invoices ADD COLUMN manual_payment_invoice TINYINT(4) DEFAULT 0;
ALTER TABLE tariff_import_rules ADD COLUMN delete_rates_which_are_not_present_in_file TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE emails ADD COLUMN from_email VARCHAR(255) NOT NULL DEFAULT '';
ALTER TABLE numbers ADD COLUMN pattern TINYINT(4) DEFAULT NULL;
ALTER TABLE numbers ADD INDEX pattern_index (pattern);
ALTER TABLE devices ADD bypass_media_tp TINYINT NOT NULL DEFAULT '1' AFTER bypass_media;
ALTER TABLE tariff_jobs ADD COLUMN alerted INT(11) DEFAULT NULL;
ALTER TABLE users ADD COLUMN web_address VARCHAR(255);
ALTER TABLE background_tasks ADD COLUMN `data8` TEXT;
ALTER TABLE background_tasks ADD COLUMN `data9` TEXT;
ALTER TABLE background_tasks ADD COLUMN `data10` TEXT;
ALTER TABLE tariff_import_rules MODIFY COLUMN effective_date_from  enum('template','subject','file_name', 'email_body') DEFAULT 'template';
ALTER TABLE iplocations ADD INDEX ip_index ( ip );
ALTER TABLE `servers` CHANGE `es` `es` TINYINT(4) NOT NULL DEFAULT '0';
ALTER TABLE `servers` CHANGE `fs` `fs` TINYINT(4) NOT NULL DEFAULT '0';
ALTER TABLE `servers` CHANGE `proxy` `proxy` TINYINT(4) NOT NULL DEFAULT '0';
ALTER TABLE server_loadstats ADD COLUMN cpu_radius_load decimal(8,4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN price_protection ENUM('off','min_rate_margin','min_rate_margin_percent') default 'off';
ALTER TABLE users ADD COLUMN min_rate_margin DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN min_rate_margin_percent DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN digits_used_for_price INT(11) DEFAULT 6;
ALTER TABLE users ADD COLUMN digits_rounding_method ENUM('up','down','mathematical') default 'up';
ALTER TABLE devices ADD COLUMN switch_model VARCHAR(255) DEFAULT "";
ALTER TABLE users CHANGE status user_status ENUM('testing','disabled','enabled', 'pending', 'suspended', 'daily_limit_exceeded') default 'testing';
ALTER TABLE users ADD COLUMN user_status ENUM('testing','disabled','enabled', 'pending', 'suspended', 'daily_limit_exceeded') default 'testing';
ALTER TABLE users CHANGE user_status user_status ENUM('testing','disabled','enabled', 'pending', 'suspended', 'daily_limit_exceeded', 'vendor') default 'testing';
ALTER TABLE users DROP COLUMN status;
ALTER TABLE `devices` ADD `changes_present` INT NOT NULL DEFAULT '1';
ALTER TABLE `devices` ADD INDEX `changes_index` ( `changes_present` );
ALTER TABLE `devices` ADD `op_routing_data_changed` INT NOT NULL DEFAULT '1';
ALTER TABLE `devices` ADD INDEX `op_routing_data_changed_index` ( `op_routing_data_changed` );
ALTER TABLE `dial_peers` ADD `changes_present` INT NOT NULL DEFAULT '1';
ALTER TABLE `dial_peers` ADD INDEX `changes_index` ( `changes_present` );
ALTER TABLE `routing_groups` ADD `changes_present` INT NOT NULL DEFAULT '1' AFTER `parent_routing_group_id`, ADD INDEX `changes_present_index` (`changes_present`);
ALTER TABLE `number_pools` ADD `changes_present` INT NOT NULL DEFAULT '1' AFTER `comment`, ADD INDEX `changes_present_index` (`changes_present`);
ALTER TABLE `users` ADD `changes_present` TINYINT NOT NULL DEFAULT '1' AFTER `user_status`, ADD INDEX `changes_present_index` (`changes_present`);
ALTER TABLE `mnp_carrier_groups` ADD `changes_present` TINYINT NOT NULL DEFAULT '1', ADD INDEX `changes_present_index` (`changes_present`);
ALTER TABLE users ADD COLUMN enforce_daily_limit TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_limit_reached TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_warning_reached TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_warning_email_sent TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_limit DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_warning DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN kill_calls_in_progress TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN show_daily_limit TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN allow_customer_to_edit TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE tariff_jobs ADD COLUMN restarts INT(11) DEFAULT 0;
ALTER TABLE users ADD COLUMN daily_spend_limit_last_reset_at DATETIME DEFAULT NULL;
ALTER TABLE users ADD COLUMN kill_calls_in_progress_flag TINYINT(4) NOT NULL DEFAULT 0;
CREATE TABLE IF NOT EXISTS `user_documents` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `description` VARCHAR(255), `upload_date` VARCHAR(255), `user_id` INT(11) NOT NULL, `full_file_name` VARCHAR(255), PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `daily_calls_count` (`id` INT(11) NOT NULL AUTO_INCREMENT, `date` VARCHAR(255) NULL, `calls` INT DEFAULT 0, PRIMARY KEY (`id`), KEY `date_index` (`date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS m2_zero_price_invoices LIKE m2_invoices;
ALTER TABLE `devices` ADD `changes_present_kam` TINYINT NOT NULL DEFAULT '1' AFTER `changes_present`, ADD INDEX `changes_present_kam_index` (`changes_present_kam`);
ALTER TABLE `devices` ADD `tp_forward_rpid` TINYINT NOT NULL DEFAULT '1' AFTER `forward_pai`, ADD `tp_forward_pai` TINYINT NOT NULL DEFAULT '1' AFTER `tp_forward_rpid`;
ALTER TABLE `devices` ADD `op_dc_group_id` INT NOT NULL DEFAULT '2' AFTER `op_routing_data_changed`, ADD `tp_dc_group_id` INT NOT NULL DEFAULT '2' AFTER `op_dc_group_id`;
CREATE TABLE IF NOT EXISTS `dc_groups` (`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(100), `changes_present` TINYINT(4) NOT NULL DEFAULT 1, INDEX(changes_present)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `disconnect_codes` (`id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `dc_group_id` INT(11), `namespace` ENUM('SIP', 'PROXY', 'CORE', 'Q.850') NOT NULL, `code` SMALLINT NOT NULL, `reason` VARCHAR(100) NOT NULL, `changed_code` SMALLINT NOT NULL DEFAULT 0, `changed_reason` VARCHAR(100) DEFAULT '', `success_when_non_zero_billsec` TINYINT(4) NOT NULL DEFAULT 0, `reroute` TINYINT(4) NOT NULL DEFAULT 1, `save_cdr` TINYINT(4) NOT NULL DEFAULT 1, `pass_reason_header` TINYINT(4) NOT NULL DEFAULT 1, INDEX(dc_group_id), INDEX(code)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `dc_groups` ADD `changes_present_kam` TINYINT NOT NULL DEFAULT '1' AFTER `changes_present`, ADD INDEX `changes_present_kam_index` (`changes_present_kam`);
ALTER TABLE rate_notification_jobs ADD COLUMN send_once TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `disconnect_codes` ADD `q850_code` INT NOT NULL DEFAULT '0' AFTER `changed_reason`;
ALTER TABLE `tariff_import_rules` DROP INDEX `trigger_errors_email_notification_id_index`;
ALTER TABLE `tariff_import_rules` CHANGE `trigger_errors_email_notification_id` `trigger_alerts_email_notification_id` INT(11) DEFAULT NULL, ADD INDEX `trigger_alerts_email_notification_id_index` (`trigger_alerts_email_notification_id`);
ALTER TABLE `tariff_import_rules` CHANGE `trigger_errors_email_notification_recipients` `trigger_alerts_email_notification_recipients` VARCHAR(256) DEFAULT NULL;
ALTER TABLE `tariff_import_rules` ADD COLUMN `trigger_rejects_email_notification_id` INT(11) DEFAULT NULL AFTER `trigger_alerts_email_notification_recipients`, ADD INDEX `trigger_rejects_email_notification_id_index` (`trigger_rejects_email_notification_id`);
ALTER TABLE `tariff_import_rules` ADD COLUMN `trigger_rejects_email_notification_recipients` VARCHAR(256) DEFAULT NULL AFTER `trigger_rejects_email_notification_id`;
ALTER TABLE `tariff_import_rules` ADD COLUMN `effective_date_timezone` VARCHAR(255) DEFAULT NULL AFTER `effective_date_from`;
ALTER TABLE rate_notification_jobs ADD COLUMN show_destination_group TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `tariff_templates` ADD COLUMN `deleted_rates_column_secondary` VARCHAR(2) DEFAULT NULL;
ALTER TABLE `tariff_templates` ADD COLUMN `deleted_rates_text_secondary` VARCHAR(50) DEFAULT NULL;
ALTER TABLE `tariff_templates` ADD COLUMN `blocked_rates_column_secondary` VARCHAR(2) DEFAULT NULL;
ALTER TABLE `tariff_templates` ADD COLUMN `blocked_rates_text_secondary` VARCHAR(50) DEFAULT NULL;
ALTER TABLE users ADD COLUMN allow_paypal TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_need_approval TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_credit_selection TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_fee_selection TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_charge_fee_on_entered_amount DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_charge_fee_on_net_amount DECIMAL(30,15) DEFAULT 0;
ALTER TABLE users ADD COLUMN paypal_do_not_send_confirmation_email TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE m2_payments ADD COLUMN entered_amount DECIMAL(30,15) DEFAULT 0;
ALTER TABLE m2_payments ADD COLUMN credited_amount DECIMAL(30,15) DEFAULT 0;
ALTER TABLE m2_payments ADD COLUMN approved TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `m2_payments` ADD INDEX `approved_index` ( `approved` );
CREATE TABLE IF NOT EXISTS `rate_notification_templates` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) NOT NULL DEFAULT '', `header_rows` INT(11) NOT NULL DEFAULT 1, `client_row` VARCHAR(10) NOT NULL DEFAULT '', `client_column` VARCHAR(10) NOT NULL DEFAULT '', `currency_row` VARCHAR(10) NOT NULL DEFAULT '', `currency_column` VARCHAR(10) NOT NULL DEFAULT '', `timezone_row` VARCHAR(10) NOT NULL DEFAULT '', `timezone_column` VARCHAR(10) NOT NULL DEFAULT '', `footer_text` TEXT, `footer_row` VARCHAR(10) NOT NULL DEFAULT '', `footer_column` VARCHAR(10) NOT NULL DEFAULT '', `destination_group_header_name` VARCHAR(100) NOT NULL DEFAULT 'Destination Group', `destination_group_column` VARCHAR(10) NOT NULL DEFAULT '', `destination_header_name` VARCHAR(100) NOT NULL DEFAULT 'Destination', `destination_column` VARCHAR(10) NOT NULL DEFAULT '', `prefix_header_name` VARCHAR(100) NOT NULL DEFAULT 'Dial Code/Prefix', `prefix_column` VARCHAR(10) NOT NULL DEFAULT '', `rate_header_name` VARCHAR(100) NOT NULL DEFAULT 'Rate', `rate_column` VARCHAR(10) NOT NULL DEFAULT '', `effective_from_header_name` VARCHAR(100) NOT NULL DEFAULT 'Effective From', `effective_from_column` VARCHAR(10) NOT NULL DEFAULT '', `rate_difference_raw_header_name` VARCHAR(100) NOT NULL DEFAULT 'Rate Difference', `rate_difference_raw_column` VARCHAR(10) NOT NULL DEFAULT '', `rate_difference_percentage_header_name` VARCHAR(100) NOT NULL DEFAULT 'Rate Difference %', `rate_difference_percentage_column` VARCHAR(10) NOT NULL DEFAULT '', `increment_header_name` VARCHAR(100) NOT NULL DEFAULT 'Increment', `increment_column` VARCHAR(10) NOT NULL DEFAULT '', `minimal_time_header_name` VARCHAR(100) NOT NULL DEFAULT 'Minimal Time', `minimal_time_column` VARCHAR(10) NOT NULL DEFAULT '', `billing_terms_header_name` VARCHAR(100) NOT NULL DEFAULT 'Billing Terms', `billing_terms_column` VARCHAR(10) NOT NULL DEFAULT '', `status_header_name` VARCHAR(100) NOT NULL DEFAULT 'Status', `status_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_1_header_name` VARCHAR(100) NOT NULL DEFAULT 'Custom Column 1', `custom_column_1_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_1_text` VARCHAR(255) NOT NULL DEFAULT '', `custom_column_2_header_name` VARCHAR(100) NOT NULL DEFAULT 'Custom Column 2', `custom_column_2_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_2_text` VARCHAR(255) NOT NULL DEFAULT '', `custom_column_3_header_name` VARCHAR(100) NOT NULL DEFAULT 'Custom Column 3', `custom_column_3_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_3_text` VARCHAR(255) NOT NULL DEFAULT '', `custom_column_4_header_name` VARCHAR(100) NOT NULL DEFAULT 'Custom Column 4', `custom_column_4_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_4_text` VARCHAR(255) NOT NULL DEFAULT '', `custom_column_5_header_name` VARCHAR(100) NOT NULL DEFAULT 'Custom Column 5', `custom_column_5_column` VARCHAR(10) NOT NULL DEFAULT '', `custom_column_5_text` VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE rate_notification_jobs ADD COLUMN rate_notification_template_id INT(11) DEFAULT NULL;
ALTER TABLE users ADD COLUMN rate_notification_template_id INT(11) NOT NULL DEFAULT -1;
ALTER TABLE `devices` ADD `tp_ignore_183nosdp` TINYINT NOT NULL DEFAULT '0' AFTER `ignore_183nosdp`;
ALTER TABLE `devices` ADD `op_ignore_180_after_183` TINYINT NOT NULL DEFAULT '0' AFTER `tp_ignore_183nosdp`, ADD `tp_ignore_180_after_183` TINYINT NOT NULL DEFAULT '0' AFTER `op_ignore_180_after_183`;
ALTER TABLE `tariff_templates` ADD COLUMN `import_column_separator` VARCHAR(2) DEFAULT ',';
ALTER TABLE `location` ADD INDEX `username_index` (`username`);
ALTER TABLE `rate_notification_templates` ADD COLUMN `connection_fee_header_name` VARCHAR(100) NOT NULL DEFAULT 'Connection Fee' AFTER `increment_header_name`;
ALTER TABLE `rate_notification_templates` ADD COLUMN `connection_fee_column` VARCHAR(10) NOT NULL DEFAULT '' AFTER `connection_fee_header_name`;
ALTER TABLE `devices` ADD `op_allow_own_tps` TINYINT NOT NULL DEFAULT '0' COMMENT 'is OP allowed to use own users TPs?';
ALTER TABLE `users` ADD `two_fa_enabled` TINYINT(4) NOT NULL DEFAULT '0';
CREATE TABLE IF NOT EXISTS `two_factor_auths` (`id` INT(11) NOT NULL AUTO_INCREMENT, `created_at` DATETIME NOT NULL, `user_id` INT(11) NOT NULL, generated_code VARCHAR(20) NOT NULL, `tried_attempts` TINYINT(4) NOT NULL DEFAULT 0, `max_attempts` TINYINT(4) NOT NULL, `valid_until` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN op_pai_regexp VARCHAR(1024);
ALTER TABLE devices ADD COLUMN op_rpid_regexp  VARCHAR(1024);
ALTER TABLE devices ADD COLUMN tp_pai_regexp VARCHAR(1024);
ALTER TABLE devices ADD COLUMN tp_rpid_regexp VARCHAR(1024);
ALTER TABLE call_details MODIFY pcap MEDIUMBLOB default NULL;
ALTER TABLE call_details MODIFY pcap_graph MEDIUMBLOB default NULL;
CREATE TABLE IF NOT EXISTS jqx_table_settings (`id` INT(11) NOT NULL AUTO_INCREMENT, `updated_at` TIMESTAMP, `user_id` INT(11) NOT NULL, `table_identifier` VARCHAR(255) NOT NULL, `newly_created` TINYINT(4) NOT NULL DEFAULT 1, `column_order` TEXT, `column_visibility` TEXT, PRIMARY KEY (`id`), KEY `user_id_index` (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN op_rg_intra INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_rg_inter INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN op_rg_indeter INT(11) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `lnp_prefixes` (`id` INT(11) NOT NULL AUTO_INCREMENT, `prefix` VARCHAR(60) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE background_tasks ADD INDEX task_id_index (task_id);
ALTER TABLE background_tasks ADD INDEX status_index (status);
ALTER TABLE background_tasks ADD INDEX created_at_index (created_at);
ALTER TABLE devices ADD COLUMN tp_username VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN tp_password VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN tp_expires INT(11) DEFAULT 3600;
ALTER TABLE devices ADD COLUMN tp_register TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_auth TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `version` (`id` int(11) NOT NULL AUTO_INCREMENT, `table_version` int(11) DEFAULT 0, `table_name` varchar(32) DEFAULT '', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8; /* table used for Kamailio modules */
DROP VIEW IF EXISTS uacreg;
CREATE VIEW uacreg AS SELECT id, MD5(id) AS l_uuid, tp_username as l_username, ipaddr AS l_domain, tp_username AS r_username, ipaddr AS r_domain, '' AS realm, tp_username AS auth_username, tp_password AS auth_password, '' AS auth_ha1, CONCAT('sip:', ipaddr, ':' , port) AS auth_proxy, tp_expires AS expires, 0 AS flags, 0 AS reg_delay, '' AS socket FROM devices WHERE tp = 1 AND tp_active = 1 AND tp_register = 1 AND tp_auth = 1 AND LENGTH(tp_username) > 0 AND LENGTH(tp_password) > 0;
ALTER TABLE m2_invoices ADD COLUMN manual_payment_id int(11) DEFAULT NULL;
ALTER TABLE devices ADD COLUMN op_match_rg_id INT(11) DEFAULT 0;
ALTER TABLE users ADD COLUMN hide_financial_data_in_quick_stats TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN auth_check_cli TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN auth_check_cld TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN auth_check_from_domain TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN auth_check_to_domain TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_from_diversion TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_from_rpid TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_from_pai TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_from_ppi TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_from_from TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_tr_rule_type TINYINT(4) DEFAULT 2;
ALTER TABLE devices ADD COLUMN cli_regexp TEXT;
ALTER TABLE devices ADD COLUMN cli_allow_type TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN cli_number_pool_allow_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cli_deny_type TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN cli_number_pool_deny_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cld_from_type TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN cld_tr_rule_type TINYINT(4) DEFAULT 2;
ALTER TABLE devices ADD COLUMN cld_regexp TEXT;
ALTER TABLE devices ADD COLUMN cld_allow_type TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN cld_allow_regexp TEXT;
ALTER TABLE devices ADD COLUMN cld_number_pool_allow_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN cld_deny_type TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN cld_deny_regexp TEXT;
ALTER TABLE devices ADD COLUMN cld_number_pool_deny_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN domain_from_auth VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN domain_to_auth VARCHAR(255) DEFAULT '';
ALTER TABLE devices ADD COLUMN use_pai_if_cli_anonymous TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `did_tags`( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `comment` VARCHAR(255) NULL, `color_text` VARCHAR(10) DEFAULT '#FFFFFF' NOT NULL, `color_bg` VARCHAR(10) DEFAULT '#6AA84F' NOT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `did_tag_links` ( `id` INT NOT NULL AUTO_INCREMENT , `did_id` INT NOT NULL , `tag_id` INT NOT NULL , PRIMARY KEY (`id`), INDEX `did_index` (`did_id`), INDEX `tag_index` (`tag_id`)) ENGINE = InnoDB;
ALTER TABLE users ADD COLUMN round_call_price_in_cdr TINYINT(4) DEFAULT 0;
ALTER TABLE users MODIFY COLUMN round_call_price_in_cdr TINYINT(4) DEFAULT 0;
CREATE TABLE `did_buying_pricing_groups` ( `id` INT NOT NULL AUTO_INCREMENT ,`custom` TINYINT NOT NULL DEFAULT '0',`name` VARCHAR(255) NOT NULL , `currency` VARCHAR(10) NULL DEFAULT NULL , `activation_fee` DECIMAL(18,9) NOT NULL DEFAULT '0' , `recurring_fee` DECIMAL(18,9) NOT NULL DEFAULT '0', `tariff_id` INT NOT NULL , `changes_present` TINYINT NOT NULL DEFAULT '1' , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `charge_plans`( `id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `name_for_user` VARCHAR(255) NOT NULL, `description` VARCHAR(255) NULL, `status` TINYINT(4) DEFAULT 1, `multiple_apply` TINYINT(4) DEFAULT 0, `period_number` INT(11) DEFAULT 1, `period_units` TINYINT(4) DEFAULT 2, `try_to_renew_for_number` INT(11) DEFAULT 1, `try_to_renew_for_units` TINYINT(4) DEFAULT 0,`try_to_renew_in_advance_number` INT(11) DEFAULT 1, `try_to_renew_in_advance_units` TINYINT(4) DEFAULT 0,`apply_subscription_charges` TINYINT(4) DEFAULT 0, `periods_in_advance` INT(11) DEFAULT 1, `charge_suspended_customers` TINYINT(4) DEFAULT 0, `subscription_is_activated` TINYINT(4) DEFAULT 0, `if_balance_insufficient` TINYINT(4) DEFAULT 0, `early_cancelation_penalty` TINYINT(4) DEFAULT 0, `minimum_subscription_period` INT(11) DEFAULT NULL, `early_cancelation_penalty_price` DECIMAL(30,15) DEFAULT 0, `issue_credit_customer_was_blocked` TINYINT(4) DEFAULT 0, `issue_credit_service_was_suspended` TINYINT(4) DEFAULT 0, `issue_credit_no_funds` TINYINT(4) DEFAULT 0, `currency_id` INT(11) DEFAULT 1, `activation_fee` DECIMAL(30,15) NOT NULL DEFAULT 0, `periodic_fee` DECIMAL(30,15) NOT NULL DEFAULT 0, `activation_fee_inv_line` VARCHAR(255) NULL, `periodic_fee_inv_line` VARCHAR(255) NULL, `rounding_precision` INT(11) DEFAULT 2, `rounding_method` TINYINT(4) DEFAULT 2, `plan_type` TINYINT(4) DEFAULT 0, `selfcost` DECIMAL(30,15) NOT NULL DEFAULT 0, `period_allign_to_customer` TINYINT(4) DEFAULT 0, `period_full_charge_firt_period` TINYINT(4) DEFAULT 0, `period_full_charge_last_period` TINYINT(4) DEFAULT 0,  PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE `did_selling_pricing_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `custom` tinyint(4) NOT NULL DEFAULT '0', `name` varchar(255) NOT NULL, `currency` varchar(10) DEFAULT NULL, `activation_fee_overwrite` tinyint(4) NOT NULL DEFAULT '0', `activation_fee` decimal(18,9) NOT NULL DEFAULT '0.000000000', `activation_fee_additional` decimal(18,9) NOT NULL DEFAULT '0.000000000', `activation_fee_markup` decimal(18,9) NOT NULL DEFAULT '0.000000000', `recurring_fee_overwrite` tinyint(4) NOT NULL DEFAULT '0', `recurring_fee` decimal(18,9) NOT NULL DEFAULT '0.000000000', `recurring_fee_additional` decimal(18,9) NOT NULL DEFAULT '0.000000000', `recurring_fee_markup` decimal(18,9) NOT NULL DEFAULT '0.000000000', `round_digits` tinyint(4) NOT NULL DEFAULT '2' COMMENT 'decimals, range 0..8', `rounding` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0-up, 1-down, 2-round', `tariff_id` int(11) NOT NULL, `changes_present` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN tp_pai_generate TEXT;
ALTER TABLE devices ADD COLUMN tp_rpid_generate TEXT;
ALTER TABLE devices ADD COLUMN use_tariffs_by_clis TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN use_default_tariff_if_by_cli_not_found TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `tariffs_by_clis` (`id` INT(11) NOT NULL AUTO_INCREMENT, `tp_id` BIGINT(20) NOT NULL, `tariff_id` BIGINT(20) NOT NULL, `number_pool_id` INT(11) NOT NULL, PRIMARY KEY (`id`), INDEX `tp_id_index` (`tp_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `custom_services` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `description` VARCHAR(255) NOT NULL, `recommended_charge_plan_id` INT(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE m2_payments ADD COLUMN payment_type TINYINT(4) DEFAULT 0;
ALTER TABLE automatic_cdr_exports ADD COLUMN send_to_ftp VARCHAR(255) DEFAULT '' AFTER `send_to_email`;
ALTER TABLE charge_plans MODIFY COLUMN try_to_renew_for_number INT(11) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `dids` ( `id` INT NOT NULL AUTO_INCREMENT , `did` VARCHAR(50) NOT NULL , `country_code` VARCHAR(5) NOT NULL ,`destination_id` INT NOT NULL, `comment` VARCHAR(255) NULL DEFAULT NULL , `status` TINYINT NOT NULL DEFAULT '0' , `on_hold_till` DATETIME NULL DEFAULT NULL , `vendor_id` INT NOT NULL COMMENT 'DID Vendor ->users.id' , `customer_id` INT NULL COMMENT 'DID Customer ->users.id' , `account_id` INT NOT NULL DEFAULT 0, `subscription_id` INT NOT NULL , `custom_buying_pricing` TINYINT NOT NULL DEFAULT '0' , `custom_selling_pricing` TINYINT NOT NULL DEFAULT '0' , `buying_pricing_group_id` INT NOT NULL COMMENT '->did_pricing_groups.id' , `selling_pricing_group_id` INT NOT NULL COMMENT '->did_pricing_groups.id' , `forward_to` TINYINT NOT NULL DEFAULT '0' , `forward_cp_id` INT NOT NULL COMMENT '->devices.id' , `forward_custom_dst` VARCHAR(50) NULL DEFAULT NULL , `forward_did_id` INT NOT NULL , `failover1` TINYINT NOT NULL DEFAULT '0' , `failover1_cp_id` INT NOT NULL COMMENT '->devices.id' , `failover1_custom_dst` VARCHAR(50) NOT NULL , `failover1_did_id` INT NOT NULL , `failover2` TINYINT NOT NULL DEFAULT '0' , `failover2_cp_id` INT NOT NULL COMMENT '->devices.id' , `failover2_custom_dst` VARCHAR(50) NOT NULL , `failover2_did_id` INT NOT NULL, `dc_on_non_active` INT NOT NULL, `cc_limit` INT NOT NULL, `dc_on_cc_limit` INT NOT NULL, `recommended_charge_plan_id` INT(11) NOT NULL, `changes_present` TINYINT NOT NULL DEFAULT '1', PRIMARY KEY (`id`), INDEX `status_index` (`status`), INDEX `vendor_index` (`vendor_id`), INDEX `customer_index` (`customer_id`), INDEX `changes_present_index` (`changes_present`), INDEX `buying_pricing_group_index` (`buying_pricing_group_id`), INDEX `selling_pricing_group_index` (`selling_pricing_group_id`), INDEX `country_code_index` (`country_code`), INDEX `destination_index` (`destination_id`)) ENGINE = InnoDB;
ALTER TABLE `servers` ADD `local_ip` VARCHAR(255) NULL DEFAULT NULL AFTER `server_ip`;
CREATE TABLE IF NOT EXISTS `flat_rates`(`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `description` VARCHAR(255) NOT NULL DEFAULT '', `recommended_charge_plan_id` INT(11) NOT NULL, `minutes_per_period` INT(11) NOT NULL DEFAULT 100, `round_by` TINYINT(4) NOT NULL DEFAULT 1, `discount_on_call_rates` TINYINT(4) NOT NULL DEFAULT 100, `base_tariff` TINYINT(4) NOT NULL DEFAULT 1, `base_tariff_tariff_id` INT(11), `limit_max_rate_for_providers` TINYINT(4) NOT NULL DEFAULT 1, `limit_max_rate_for_providers_rate` DECIMAL(18,9) DEFAULT 0.1, `limit_max_rate_for_providers_currency_id` INT(11) DEFAULT 1, `notify_customer` TINYINT(4) NOT NULL DEFAULT 1, `notify_customer_minutes_used` INT(11) DEFAULT 0, `notify_customer_email_id` INT(11), `action_on_expiry` TINYINT(4) NOT NULL DEFAULT 1, `action_on_expiry_split_cdr` TINYINT(4) NOT NULL DEFAULT 1, `transfer_to_next_period_max_unused_minutes` INT(11) DEFAULT 0, `destination_type` TINYINT(4) NOT NULL DEFAULT 0, `destination_regexp` VARCHAR(255), `destination_number_pool_id` INT(11), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `flat_rate_destinations`(`id` INT(11) NOT NULL AUTO_INCREMENT, `flat_rate_id` INT(11) NOT NULL, `destination_id` BIGINT(20) NOT NULL, `active` TINYINT(4) NOT NULL DEFAULT 1, PRIMARY KEY (`id`), INDEX `flat_rate_id_index` (`flat_rate_id`), INDEX `destination_id_index` (`destination_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN show_calls_statistics_for_last_days INT(11) DEFAULT -1;
CREATE TABLE IF NOT EXISTS `subscriptions`(`id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `name_for_user` VARCHAR(255) NOT NULL, `description` VARCHAR(255) NULL, `charge_plan_status` TINYINT(4) DEFAULT 1, `multiple_apply` TINYINT(4) DEFAULT 0, `period_number` INT(11) DEFAULT 1, `period_units` TINYINT(4) DEFAULT 2, `try_to_renew_for_number` INT(11) DEFAULT NULL, `try_to_renew_for_units` TINYINT(4) DEFAULT 0, `try_to_renew_in_advance_number` INT(11) DEFAULT 1, `try_to_renew_in_advance_units` TINYINT(4) DEFAULT 0, `apply_subscription_charges` TINYINT(4) DEFAULT 0, `periods_in_advance` INT(11) DEFAULT 1, `charge_suspended_customers` TINYINT(4) DEFAULT 0, `subscription_is_activated` TINYINT(4) DEFAULT 0, `if_balance_insufficient` TINYINT(4) DEFAULT 0, `early_cancelation_penalty` TINYINT(4) DEFAULT 0, `minimum_subscription_period` INT(11) DEFAULT NULL, `early_cancelation_penalty_price` DECIMAL(30,15) DEFAULT 0, `issue_credit_customer_was_blocked` TINYINT(4) DEFAULT 0, `issue_credit_service_was_suspended` TINYINT(4) DEFAULT 0, `issue_credit_no_funds` TINYINT(4) DEFAULT 0, `currency_id` INT(11) DEFAULT 1, `activation_fee` DECIMAL(30,15) NOT NULL DEFAULT 0, `periodic_fee` DECIMAL(30,15) NOT NULL DEFAULT 0, `activation_fee_inv_line` VARCHAR(255) NULL, `periodic_fee_inv_line` VARCHAR(255) NULL, `rounding_precision` INT(11) DEFAULT 2, `rounding_method` TINYINT(4) DEFAULT 2, `plan_type` TINYINT(4) DEFAULT 0, `selfcost` DECIMAL(30,15) NOT NULL DEFAULT 0, `period_allign_to_customer` TINYINT(4) DEFAULT 0,`period_full_charge_firt_period` TINYINT(4) DEFAULT 0, `period_full_charge_last_period` TINYINT(4) DEFAULT 0, `charge_plan_id` INT(11) NOT NULL, `status` TINYINT(4) DEFAULT 0, `user_id` INT(11) NOT NULL, `account_id` INT(11) NOT NULL, `did_id` INT(11) NOT NULL, `discount` TINYINT(4) NOT NULL DEFAULT 0, `no_expire` TINYINT(4) NOT NULL DEFAULT 0, `activation_start` DATETIME NULL, `start_date` DATETIME NULL, `end_date` DATETIME NULL, `billed_to` DATETIME NULL, `last_charge_date` DATETIME NULL, `last_charge_amount` DECIMAL(30,15) DEFAULT 0, `action_type` TINYINT(4) DEFAULT 0, `refund_type` TINYINT(4) DEFAULT 0, `did_status_change` TINYINT(4) DEFAULT 0, PRIMARY KEY (`id`)) ENGINE = InnoDB;
ALTER TABLE rate_notification_jobs ADD COLUMN filename VARCHAR(255) DEFAULT 'rate_notification_data';
ALTER TABLE charge_plans ALTER apply_subscription_charges SET DEFAULT 1;
ALTER TABLE activecalls ADD COLUMN did_id INT(11) DEFAULT 0;
ALTER TABLE dids MODIFY COLUMN recommended_charge_plan_id INT(11) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `core_tasks` (`id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT, `entity` TINYINT(4) DEFAULT 0, `entity_id` INT(11) DEFAULT 0, `action` TINYINT(4) DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN `time_format` ENUM('Default', '%H:%M:%S', '%M:%S') NOT NULL DEFAULT 'Default';
ALTER TABLE tariff_import_rules ADD COLUMN trigger_import_failed_email_notification_id INT(11) AFTER `trigger_rejected_email_notification_recipients`;
ALTER TABLE tariff_import_rules ADD INDEX trigger_import_failed_email_notification_id_index ( trigger_import_failed_email_notification_id );
ALTER TABLE tariff_import_rules ADD COLUMN trigger_import_failed_email_notification_recipients VARCHAR(256) AFTER `trigger_import_failed_email_notification_id`;
CREATE TABLE IF NOT EXISTS `email_jobs` (`id` INT(11) NOT NULL AUTO_INCREMENT, `uniqueid` VARCHAR(255), `created_at` DATETIME, `updated_at` TIMESTAMP, `user_id` INT(11), `email_id` INT(11), `email_name` VARCHAR(255), `send_from` VARCHAR(255), `send_to` VARCHAR(255), `sendemail_text` TEXT, `sent_at` DATETIME, `status` VARCHAR(100) NOT NULL, `status_reason` TEXT, PRIMARY KEY (`id`), INDEX `user_id_index` (`user_id`), INDEX `email_id_index` (`email_id`), INDEX `email_name_index` (`email_name`), INDEX `uniqueid_index` (`uniqueid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE subscriptions ADD COLUMN flat_rate_id INT(11) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `flat_rate_data` (`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `period_start` DATETIME DEFAULT NULL, `period_end` DATETIME DEFAULT NULL, `subscription_id` MEDIUMINT(8) UNSIGNED DEFAULT '0', `total_seconds` MEDIUMINT(8) UNSIGNED DEFAULT '0', `seconds_used` MEDIUMINT(8) UNSIGNED DEFAULT '0', `transferred_seconds` MEDIUMINT(8) UNSIGNED DEFAULT '0', `period_seconds` MEDIUMINT(8) UNSIGNED DEFAULT '0', `calls` INT(11) UNSIGNED DEFAULT '0', `email_sent` TINYINT(4) DEFAULT '0', PRIMARY KEY (`id`), INDEX `period_start_index` (`period_start`), INDEX `period_end_index` (`period_end`), INDEX `subscription_id_index` (`subscription_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `did_buying_pricing_groups` CHANGE `recurring_fee` `periodic_fee` DECIMAL(18,9) NOT NULL DEFAULT '0';
ALTER TABLE `did_selling_pricing_groups` CHANGE `recurring_fee_overwrite` `periodic_fee_overwrite` tinyint(4) NOT NULL DEFAULT '0';
ALTER TABLE `did_selling_pricing_groups` CHANGE `recurring_fee` `periodic_fee` decimal(18,9) NOT NULL DEFAULT '0.000000000';
ALTER TABLE `did_selling_pricing_groups` CHANGE `recurring_fee_additional` `periodic_fee_additional` decimal(18,9) NOT NULL DEFAULT '0.000000000';
ALTER TABLE `did_selling_pricing_groups` CHANGE `recurring_fee_markup` `periodic_fee_markup` decimal(18,9) NOT NULL DEFAULT '0.000000000';
CREATE TABLE `op_mnp_tariffs` (`id` INT(11) NOT NULL AUTO_INCREMENT, `op_id` INT(11) NOT NULL, `mnp_carrier_group_id` INT(11)  NOT NULL, `tariff_id` INT(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `charge_plans` CHANGE `issue_credit_customer_was_blocked` `issue_credit_customer_was_blocked` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `charge_plans` CHANGE `issue_credit_service_was_suspended` `issue_credit_service_was_suspended` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `charge_plans` CHANGE `issue_credit_no_funds` `issue_credit_no_funds` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `charge_plans` ADD COLUMN `skip_credits_for_the_first_billing_period` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `charge_plans` ADD COLUMN `skip_credits_for_the_regular_billing_periods` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `charge_plans` ADD COLUMN `skip_credits_for_the_last_billing_period` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `subscriptions` ADD COLUMN `skip_credits_for_the_first_billing_period` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `subscriptions` ADD COLUMN `skip_credits_for_the_regular_billing_periods` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE `subscriptions` ADD COLUMN `skip_credits_for_the_last_billing_period` TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE subscriptions ADD COLUMN custom_service_id INT(11) DEFAULT NULL;
ALTER TABLE `charge_plans` ADD COLUMN `charge_past` TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `charge_past` TINYINT(4) NOT NULL DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_block_user` TINYINT(4) DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_suspend_service` TINYINT(4) DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_charge_subscription` TINYINT(4) DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_send_email_to_admin` TINYINT(4) DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_admin_email_template_id` INT(11) DEFAULT NULL;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_send_email_to_user` TINYINT(4) DEFAULT 0;
ALTER TABLE `charge_plans` ADD COLUMN `insufficient_funds_user_email_template_id` INT(11) DEFAULT NULL;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_block_user` TINYINT(4) DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_suspend_service` TINYINT(4) DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_charge_subscription` TINYINT(4) DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_send_email_to_admin` TINYINT(4) DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_admin_email_template_id` INT(11) DEFAULT NULL;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_send_email_to_user` TINYINT(4) DEFAULT 0;
ALTER TABLE `subscriptions` ADD COLUMN `insufficient_funds_user_email_template_id` INT(11) DEFAULT NULL;
ALTER TABLE subscriptions ADD COLUMN changes_present TINYINT(4) DEFAULT 0;
ALTER TABLE subscriptions ADD INDEX changes_present_index (changes_present);
ALTER TABLE flat_rates ADD COLUMN changes_present TINYINT(4) DEFAULT 0;
ALTER TABLE flat_rates ADD INDEX changes_present_index (changes_present);
ALTER TABLE number_pools ADD COLUMN owner_id INT(11) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `subscription_actions` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`created_at` datetime DEFAULT NULL,`completed_at` datetime DEFAULT NULL,`subscription_id` mediumint(8) unsigned DEFAULT '0',`action` varchar(50) DEFAULT '',`data1` varchar(100) DEFAULT '',`data2` varchar(100) DEFAULT '',`data3` varchar(100) DEFAULT '',PRIMARY KEY (`id`),KEY `created_at_index` (`created_at`),KEY `completed_at_index` (`completed_at`),KEY `subscription_id_index` (`subscription_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE subscription_actions ADD COLUMN data4 VARCHAR(100) DEFAULT '';
ALTER TABLE `charge_plans` CHANGE `insufficient_funds_block_user` `insufficient_funds_block_user` TINYINT(4) DEFAULT 1;
ALTER TABLE `charge_plans` CHANGE `insufficient_funds_suspend_service` `insufficient_funds_suspend_service` TINYINT(4) DEFAULT 1;
ALTER TABLE `charge_plans` CHANGE `insufficient_funds_charge_subscription` `insufficient_funds_charge_subscription` TINYINT(4) DEFAULT 1;
ALTER TABLE `charge_plans` ADD COLUMN `issue_credits_user_blocked_inv_line` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `charge_plans` ADD COLUMN `issue_credits_subscription_suspended_inv_line` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `charge_plans` ADD COLUMN `cancellation_fee_inv_line` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `subscriptions` ADD COLUMN `issue_credits_user_blocked_inv_line` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `subscriptions` ADD COLUMN `issue_credits_subscription_suspended_inv_line` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `subscriptions` ADD COLUMN `cancellation_fee_inv_line` VARCHAR(255) DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `financial_data_records` (`id` int(11) NOT NULL AUTO_INCREMENT,`created_at` datetime DEFAULT NULL,`user_id` int(11) DEFAULT '0',`subscription_id` int(11) DEFAULT '0',`time_zone` varchar(50) DEFAULT '',`period_start` datetime DEFAULT NULL,`period_end` datetime DEFAULT NULL,`discount_percent` decimal(30,15) DEFAULT '0.000000000000000',`amount` decimal(30,15) DEFAULT '0.000000000000000',`currency` varchar(10) DEFAULT '',`exchange_rate` decimal(30,15) DEFAULT '1.000000000000000',`amount_in_default_currency` decimal(30,15) DEFAULT '0.000000000000000',`user_balance_before` decimal(30,15) DEFAULT '0.000000000000000',`user_balance_after` decimal(30,15) DEFAULT '0.000000000000000',`entity` enum('unknown','subscription') DEFAULT NULL,`action` enum('unknown','create','update','close','suspend','unsuspend','disable','undisable','charge_activation','charge_periodic','charge_cancellation','activate','refund') DEFAULT NULL,`data1` varchar(100) DEFAULT '',`data2` varchar(100) DEFAULT '',`data3` varchar(100) DEFAULT '',PRIMARY KEY (`id`),KEY `user_id_index` (`user_id`),KEY `subscription_id_index` (`subscription_id`),KEY `period_start_index` (`period_start`),KEY `period_end_index` (`period_end`),KEY `created_at_index` (`created_at`),KEY `entity_index` (`entity`),KEY `action_index` (`action`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE financial_data_records MODIFY COLUMN data1 VARCHAR(255) DEFAULT '';
ALTER TABLE financial_data_records MODIFY COLUMN data2 VARCHAR(255) DEFAULT '';
ALTER TABLE financial_data_records MODIFY COLUMN data3 VARCHAR(255) DEFAULT '';
ALTER TABLE subscription_actions MODIFY COLUMN data1 VARCHAR(255) DEFAULT '';
ALTER TABLE subscription_actions MODIFY COLUMN data2 VARCHAR(255) DEFAULT '';
ALTER TABLE subscription_actions MODIFY COLUMN data3 VARCHAR(255) DEFAULT '';
ALTER TABLE subscription_actions MODIFY COLUMN data4 VARCHAR(255) DEFAULT '';
ALTER TABLE m2_invoice_lines ADD COLUMN subscription_id INT(11) DEFAULT 0;
ALTER TABLE subscriptions DROP COLUMN action_type;
ALTER TABLE subscriptions DROP COLUMN refund_type;
ALTER TABLE subscriptions DROP COLUMN did_status_change;
ALTER TABLE subscription_actions ADD COLUMN execute_at DATETIME DEFAULT NULL AFTER `created_at`;
ALTER TABLE financial_data_records ADD COLUMN inv_line VARCHAR(255) DEFAULT '';
ALTER TABLE users ADD COLUMN show_quick_stats TINYINT DEFAULT 1;
ALTER TABLE blocked_ips ADD INDEX sync_index (server_id, blocked_ip, unblock);
ALTER TABLE blocked_ips ADD INDEX get_index (server_id, unblock);
ALTER TABLE blocked_ips ADD INDEX get_index2 (server_id, blocked_ip, chain, unblock);
ALTER TABLE aggregate_templates ADD COLUMN group_by_user_rate TINYINT(4) DEFAULT 0;
ALTER TABLE aggregate_templates ADD COLUMN group_by_provider_rate TINYINT(4) DEFAULT 0;
ALTER TABLE m2_invoice_lines ADD COLUMN did_id INT(11) DEFAULT 0;
ALTER TABLE rate_notification_jobs ADD COLUMN decreases_effective_from DATETIME DEFAULT NULL;
ALTER TABLE rate_notification_jobs ADD COLUMN increases_effective_from DATETIME DEFAULT NULL;
CREATE TABLE IF NOT EXISTS `supplier_invoices` (`id` INT(11) NOT NULL AUTO_INCREMENT, `created_at` DATETIME DEFAULT NULL, `supplier_user_id` INT(11) NOT NULL, `time_period_from` DATETIME DEFAULT NULL, `time_period_till` DATETIME DEFAULT NULL, `invoice_generation_date` DATETIME DEFAULT NULL, `supplier_invoice_amount` DECIMAL(30,15) NOT NULL DEFAULT '0.000000000000000', `supplier_invoice_amount_currency_id` INT(11) NOT NULL DEFAULT 1, `supplier_invoice_amount_exchange_rate` DECIMAL(30,15) NOT NULL DEFAULT '0.000000000000000', `our_amount` DECIMAL(30,15) NOT NULL DEFAULT '0.000000000000000', `status` VARCHAR(50) NOT NULL DEFAULT '', `supplier_invoice_number` VARCHAR(255) NOT NULL DEFAULT '', `note` VARCHAR(255) NOT NULL DEFAULT '', `attachment_filename` VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE subscriptions ADD COLUMN insufficient_funds_admin_email_sent TINYINT(4) DEFAULT 0;
ALTER TABLE subscriptions ADD COLUMN insufficient_funds_user_email_sent TINYINT(4) DEFAULT 0;
CREATE TABLE IF NOT EXISTS `number_pool_numbers_usage_reports` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `created_at` DATETIME DEFAULT NULL, `updated_at` DATETIME DEFAULT NULL, `last_time_viewed_at` DATETIME DEFAULT NULL, `number_pool_id` INT(11) NOT NULL, `status` VARCHAR(50) NOT NULL, `for_date` VARCHAR(50) NOT NULL, `utc_offset` INT(11) NOT NULL DEFAULT 0, `numbers_in_np_total_count` BIGINT(20) NOT NULL, `total_h0` BIGINT(20) NOT NULL DEFAULT 0, `total_h1` BIGINT(20) NOT NULL DEFAULT 0, `total_h2` BIGINT(20) NOT NULL DEFAULT 0, `total_h3` BIGINT(20) NOT NULL DEFAULT 0, `total_h4` BIGINT(20) NOT NULL DEFAULT 0, `total_h5` BIGINT(20) NOT NULL DEFAULT 0, `total_h6` BIGINT(20) NOT NULL DEFAULT 0, `total_h7` BIGINT(20) NOT NULL DEFAULT 0, `total_h8` BIGINT(20) NOT NULL DEFAULT 0, `total_h9` BIGINT(20) NOT NULL DEFAULT 0, `total_h10` BIGINT(20) NOT NULL DEFAULT 0, `total_h11` BIGINT(20) NOT NULL DEFAULT 0, `total_h12` BIGINT(20) NOT NULL DEFAULT 0, `total_h13` BIGINT(20) NOT NULL DEFAULT 0, `total_h14` BIGINT(20) NOT NULL DEFAULT 0, `total_h15` BIGINT(20) NOT NULL DEFAULT 0, `total_h16` BIGINT(20) NOT NULL DEFAULT 0, `total_h17` BIGINT(20) NOT NULL DEFAULT 0, `total_h18` BIGINT(20) NOT NULL DEFAULT 0, `total_h19` BIGINT(20) NOT NULL DEFAULT 0, `total_h20` BIGINT(20) NOT NULL DEFAULT 0, `total_h21` BIGINT(20) NOT NULL DEFAULT 0, `total_h22` BIGINT(20) NOT NULL DEFAULT 0, `total_h23` BIGINT(20) NOT NULL DEFAULT 0, `total_total` BIGINT(20) NOT NULL DEFAULT 0, `total_h0_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h1_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h2_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h3_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h4_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h5_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h6_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h7_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h8_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h9_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h10_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h11_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h12_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h13_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h14_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h15_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h16_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h17_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h18_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h19_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h20_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h21_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h22_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_h23_answered` BIGINT(20) NOT NULL DEFAULT 0, `total_total_answered` BIGINT(20) NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY `last_time_viewed_at_index` (`last_time_viewed_at`), KEY `number_pool_id_index` (`number_pool_id`), KEY `for_date_index` (`for_date`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
ALTER TABLE users ADD COLUMN two_fa_authentication_method TINYINT(4) DEFAULT 0;
ALTER TABLE users ADD COLUMN two_fa_authenticator_secret VARCHAR(255) DEFAULT NULL;
ALTER TABLE users ADD COLUMN two_fa_authenticator_verified TINYINT(4) DEFAULT 0;
ALTER TABLE users ADD COLUMN two_fa_authenticator_last_otp_at INT(11) DEFAULT NULL;
ALTER TABLE aggregate_templates ADD COLUMN group_by_hangupcause TINYINT(4) DEFAULT 0;
ALTER TABLE aggregate_templates ADD COLUMN group_by_src_prefix TINYINT(4) DEFAULT 0;
ALTER TABLE aggregate_templates ADD COLUMN group_by_date TINYINT(4) DEFAULT 0;
ALTER TABLE aggregate_templates ADD COLUMN group_by_date_hour TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN rinstance VARCHAR(100) DEFAULT NULL;
ALTER TABLE subscriptions ADD INDEX did_id_index (did_id);
ALTER TABLE subscriptions ADD INDEX flat_rate_id_index (flat_rate_id);
ALTER TABLE subscriptions ADD INDEX activation_start_index (activation_start);
ALTER TABLE subscriptions ADD INDEX start_date_index (start_date);
ALTER TABLE subscriptions ADD INDEX end_date_index (end_date);
ALTER TABLE subscriptions ADD INDEX no_expire_index (no_expire);
ALTER TABLE subscriptions ADD INDEX user_id_index (user_id);
ALTER TABLE subscriptions ADD INDEX status_index (status);
ALTER TABLE subscriptions ADD COLUMN did_status_on_finish TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_dst_transformation_type TINYINT(4) DEFAULT 0
ALTER TABLE devices ADD COLUMN tp_ruri_transformation_regexp VARCHAR(255) DEFAULT NULL;
ALTER TABLE devices ADD COLUMN tp_to_transformation_regexp VARCHAR(255) DEFAULT NULL;
ALTER TABLE devices ADD COLUMN tp_stirshaken_add_identity TINYINT(4) DEFAULT 0;
ALTER TABLE subscription_actions ADD COLUMN data5 VARCHAR(255) DEFAULT '';
CREATE TABLE IF NOT EXISTS `header_transformation_rules_groups` (`id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255), `description` VARCHAR(255), PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `header_transformation_rules` (`id` INT(11) NOT NULL AUTO_INCREMENT, `header_transformation_rules_group_id` INT(11) NOT NULL, `header_name` VARCHAR(255), `action` VARCHAR(255),`regex_transformation` VARCHAR(1024),`construction` VARCHAR(1024), PRIMARY KEY (`id`), INDEX `header_transformation_rules_group_id_index` (`header_transformation_rules_group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE devices ADD COLUMN tp_header_transformation_rules_group_id INT(11) DEFAULT 0;
ALTER TABLE header_transformation_rules_groups ADD COLUMN changes_present TINYINT(4) DEFAULT 0;
ALTER TABLE rate_notification_jobs ADD COLUMN ignore_action TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_stirshaken_attest_level TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cld_check TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN tp_cli_check TINYINT(4) DEFAULT 1;
ALTER TABLE devices ADD COLUMN tp_cld_whitelist_type TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cld_blacklist_type TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cld_whitelist_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cld_blacklist_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cld_whitelist_regexp VARCHAR(1024);
ALTER TABLE devices ADD COLUMN tp_cld_blacklist_regexp VARCHAR(1024);
ALTER TABLE devices ADD COLUMN tp_cli_whitelist_type tinyint DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cli_blacklist_type tinyint DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cli_whitelist_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cli_blacklist_number_pool_id INT(11) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cli_transformation_type TINYINT(4) DEFAULT 0;
ALTER TABLE devices ADD COLUMN tp_cli_transformation_regexp VARCHAR(255) DEFAULT NULL;
ALTER TABLE dids ADD COLUMN header_transformation_rules_group_id INT(11) DEFAULT 0;
ALTER TABLE dids ADD COLUMN changes_present_kam TINYINT(4) NOT NULL DEFAULT 1;
ALTER TABLE automatic_cdr_exports ADD COLUMN send_to_sftp VARCHAR(255) DEFAULT '' AFTER `send_to_ftp`;
### SQL sentences goes to the top ^^^^^ from this line
# make sure you press ENTER (to end line) after last SQL sentence!
# also whole SQL sentence should go into one line
