From a723bbeb19abf400119cb5594249a3cac7f369cc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 10 Dec 2011 11:26:04 +0100 Subject: [PATCH] New: Can define different requests according to database type into migration files. --- ChangeLog | 1 + htdocs/core/lib/admin.lib.php | 32 ++++++++++++++----- .../install/mysql/migration/2.9.0-3.0.0.sql | 2 +- .../install/mysql/migration/3.0.0-3.1.0.sql | 2 +- .../install/mysql/migration/3.1.0-3.2.0.sql | 13 ++++++-- htdocs/install/upgrade.php | 2 +- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index fc8b21bc25a..50e67e76b6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ For developers: - New: Log module outputs can be setup with "or" rule (not only "xor"). - New: Add FirePHP output for logging module. - New: Add trigger ACTION_DELETE and ACTION_MODIFY +- New: Can define different requests according to database type into migration files. - Qual: Data structure for supplier prices is simpler. - Qual: Removed no more used external libraries. - Qual: Cleaned a lot of dead code. diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index cb92f02603e..9a92e63ea9c 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -132,17 +132,33 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='') { $buf = fgets($fp, 4096); - // Cas special de lignes autorisees pour certaines versions uniquement - if (preg_match('/^--\sV([0-9\.]+)/i',$buf,$reg)) + // Test if request must be ran only for particular database or version (if yes, we must remove the -- comment) + if (preg_match('/^--\sV(MYSQL|PGSQL|)([0-9\.]+)/i',$buf,$reg)) { - $versioncommande=explode('.',$reg[1]); - //print var_dump($versioncommande); - //print var_dump($versionarray); - if (count($versioncommande) && count($versionarray) - && versioncompare($versioncommande,$versionarray) <= 0) + $qualified=1; + + // restrict on database type + if (! empty($reg[1])) + { + if (strtolower($reg[1]) != $db->type) $qualified=0; + } + + // restrict on version + if ($qualified) + { + $versionrequest=explode('.',$reg[2]); + //print var_dump($versionrequest); + //print var_dump($versionarray); + if (! count($versionrequest) || ! count($versionarray) || versioncompare($versionrequest,$versionarray) > 0) + { + $qualified=0; + } + } + + if ($qualified) { // Version qualified, delete SQL comments - $buf=preg_replace('/^--\sV([0-9\.]+)/i','',$buf); + $buf=preg_replace('/^--\sV(MYSQL|PGSQL|)([0-9\.]+)/i','',$buf); //print "Ligne $i qualifi?e par version: ".$buf.'
'; } } diff --git a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql index 41a13c8e91e..de37c4971ab 100644 --- a/htdocs/install/mysql/migration/2.9.0-3.0.0.sql +++ b/htdocs/install/mysql/migration/2.9.0-3.0.0.sql @@ -1,7 +1,7 @@ -- -- Be carefull to requests order. -- This file must be loaded by calling /install/index.php page --- when current version is 2.8.0 or higher. +-- when current version is 2.9.0 or higher. -- -- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; -- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 74de025b9fd..a9b60c1b88d 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -1,7 +1,7 @@ -- -- Be carefull to requests order. -- This file must be loaded by calling /install/index.php page --- when current version is 2.8.0 or higher. +-- when current version is 3.0.0 or higher. -- -- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; -- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; diff --git a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql index 69e71660538..8bbd990bbac 100755 --- a/htdocs/install/mysql/migration/3.1.0-3.2.0.sql +++ b/htdocs/install/mysql/migration/3.1.0-3.2.0.sql @@ -1,13 +1,19 @@ -- -- Be carefull to requests order. -- This file must be loaded by calling /install/index.php page --- when current version is 2.8.0 or higher. +-- when current version is 3.1.0 or higher. -- -- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; -- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; -- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); -- To change type of field: ALTER TABLE llx_table MODIFY name varchar(60); --- +-- To restrict request to Mysql version x.y use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y use -- VPGSQLx.y + + +-- V4.1 DELETE FROM llx_product_fournisseur WHERE fk_product NOT IN (SELECT rowid from llx_product); +-- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); UPDATE llx_c_paper_format SET active=1 WHERE active=0; @@ -57,7 +63,8 @@ ALTER TABLE llx_product_fournisseur_price ADD COLUMN fk_soc integer after fk_pro ALTER TABLE llx_product_fournisseur_price ADD COLUMN ref_fourn varchar(30) after fk_soc; ALTER TABLE llx_product_fournisseur_price ADD COLUMN entity integer DEFAULT 1 NOT NULL; -UPDATE llx_product_fournisseur_price as a, llx_product_fournisseur as b SET a.fk_product = b.fk_product, a.fk_soc = b.fk_soc, a.ref_fourn = b.ref_fourn, a.entity = b.entity WHERE a.fk_product_fournisseur = b.rowid AND (a.fk_product IS NULL OR a.fk_soc IS NULL OR a.fk_product = 0 OR a.fk_soc = 0); +-- VMYSQL4.1 UPDATE llx_product_fournisseur_price as a, llx_product_fournisseur as b SET a.fk_product = b.fk_product, a.fk_soc = b.fk_soc, a.ref_fourn = b.ref_fourn, a.entity = b.entity WHERE a.fk_product_fournisseur = b.rowid AND (a.fk_product IS NULL OR a.fk_soc IS NULL OR a.fk_product = 0 OR a.fk_soc = 0); +-- VPGSQL8.1 UPDATE llx_product_fournisseur_price as a SET fk_product = b.fk_product, fk_soc = b.fk_soc, ref_fourn = b.ref_fourn, entity = b.entity FROM llx_product_fournisseur as b WHERE a.fk_product_fournisseur = b.rowid AND (a.fk_product IS NULL OR a.fk_soc IS NULL OR a.fk_product = 0 OR a.fk_soc = 0); ALTER TABLE llx_product_fournisseur_price DROP INDEX uk_product_fournisseur_price_ref; ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_fournisseur_price_ref (ref_fourn, fk_soc, quantity, entity); diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 08d00535bdf..d48c91c6c88 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -321,7 +321,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) } } - // Boucle sur chaque fichier + // Loop on each migrate files foreach($filelist as $file) { print '';