From 8e03d7b4758c69901dbdd3468da7dab55430df03 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Wed, 7 Sep 2016 13:59:43 +0200 Subject: [PATCH] MT#22031 cosmetic up script changes for MariaDB compatibility * "partition" is a reserved word in MariaDB and as such the existing column with name partition is escaped as `partition` * MariaDB is more restrictive to column alterations that have foreign keys in another tables and as such added constract drop/add wrapped into LOCK TABLES. LOCK TABLES is essential there as after DROP FOREIGN KEY up until the CONSTRANT is recreated again there is a chance to break the consistency with a wrong sql statement executed when the up script is being applied. Change-Id: I4b08a1c5b2c5e1632e2683f62251fe3873ebc58e --- db_scripts/diff/15172_not_replicated.up | 2 +- db_scripts/diff/15211.up | 10 ++++++++++ db_scripts/diff/15251_not_replicated.up | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/db_scripts/diff/15172_not_replicated.up b/db_scripts/diff/15172_not_replicated.up index e4496e59..2c762802 100644 --- a/db_scripts/diff/15172_not_replicated.up +++ b/db_scripts/diff/15172_not_replicated.up @@ -20,7 +20,7 @@ REPLACE INTO version (`table_name`, `table_version`) VALUES ('dialplan','2'); ALTER TABLE location ADD COLUMN server_id INT(11) DEFAULT 0 NOT NULL; ALTER TABLE location ADD COLUMN connection_id INT(11) DEFAULT 0 NOT NULL; ALTER TABLE location ADD COLUMN keepalive INT(11) DEFAULT 0 NOT NULL; -ALTER TABLE location ADD COLUMN partition INT(11) DEFAULT 0 NOT NULL; +ALTER TABLE location ADD COLUMN `partition` INT(11) DEFAULT 0 NOT NULL; REPLACE INTO version (`table_name`, `table_version`) VALUES ('location','8'); -- table: presentity diff --git a/db_scripts/diff/15211.up b/db_scripts/diff/15211.up index dc946a5f..4c529b84 100644 --- a/db_scripts/diff/15211.up +++ b/db_scripts/diff/15211.up @@ -1,3 +1,13 @@ USE billing; +LOCK TABLES ncos_lnp_list WRITE, lnp_numbers WRITE, lnp_providers WRITE; + +ALTER TABLE ncos_lnp_list DROP FOREIGN KEY `c_l_l_lnpproid_ref`; +ALTER TABLE lnp_numbers DROP FOREIGN KEY `l_n_lnpproid_ref`; + ALTER TABLE lnp_providers MODIFY id int(11) unsigned not null auto_increment; + +ALTER TABLE ncos_lnp_list ADD CONSTRAINT `c_l_l_lnpproid_ref` FOREIGN KEY (`lnp_provider_id`) REFERENCES `lnp_providers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE lnp_numbers ADD CONSTRAINT `l_n_lnpproid_ref` FOREIGN KEY (`lnp_provider_id`) REFERENCES `lnp_providers` (`id`) ON UPDATE CASCADE; + +UNLOCK TABLES; diff --git a/db_scripts/diff/15251_not_replicated.up b/db_scripts/diff/15251_not_replicated.up index 24fb80f1..7d0373f7 100644 --- a/db_scripts/diff/15251_not_replicated.up +++ b/db_scripts/diff/15251_not_replicated.up @@ -9,7 +9,10 @@ WHERE a.id < b.id and (a.number = b.number and a.lnp_provider_id = b.lnp_provider_id); -ALTER TABLE lnp_numbers DROP FOREIGN KEY l_n_lnpproid_ref; -DROP INDEX l_n_lnpproid_ref ON lnp_numbers; +LOCK TABLES lnp_numbers WRITE; + +ALTER TABLE lnp_numbers DROP FOREIGN KEY `l_n_lnpproid_ref`; CREATE UNIQUE INDEX l_n_lnpproidnumber_idx ON lnp_numbers (lnp_provider_id,number); ALTER TABLE lnp_numbers ADD CONSTRAINT l_n_lnpproid_ref FOREIGN KEY (lnp_provider_id) REFERENCES lnp_providers (id) ON DELETE RESTRICT ON UPDATE CASCADE; + +UNLOCK TABLES;