2
0
forked from Wavyzz/dolibarr

New: Can define different requests according to database type into

migration files.
This commit is contained in:
Laurent Destailleur
2011-12-10 11:26:04 +01:00
parent b467529ca9
commit a723bbeb19
6 changed files with 38 additions and 14 deletions

View File

@@ -39,6 +39,7 @@ For developers:
- New: Log module outputs can be setup with "or" rule (not only "xor"). - New: Log module outputs can be setup with "or" rule (not only "xor").
- New: Add FirePHP output for logging module. - New: Add FirePHP output for logging module.
- New: Add trigger ACTION_DELETE and ACTION_MODIFY - 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: Data structure for supplier prices is simpler.
- Qual: Removed no more used external libraries. - Qual: Removed no more used external libraries.
- Qual: Cleaned a lot of dead code. - Qual: Cleaned a lot of dead code.

View File

@@ -132,17 +132,33 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='')
{ {
$buf = fgets($fp, 4096); $buf = fgets($fp, 4096);
// Cas special de lignes autorisees pour certaines versions uniquement // Test if request must be ran only for particular database or version (if yes, we must remove the -- comment)
if (preg_match('/^--\sV([0-9\.]+)/i',$buf,$reg)) if (preg_match('/^--\sV(MYSQL|PGSQL|)([0-9\.]+)/i',$buf,$reg))
{ {
$versioncommande=explode('.',$reg[1]); $qualified=1;
//print var_dump($versioncommande);
//print var_dump($versionarray); // restrict on database type
if (count($versioncommande) && count($versionarray) if (! empty($reg[1]))
&& versioncompare($versioncommande,$versionarray) <= 0) {
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 // 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.'<br>'; //print "Ligne $i qualifi?e par version: ".$buf.'<br>';
} }
} }

View File

@@ -1,7 +1,7 @@
-- --
-- Be carefull to requests order. -- Be carefull to requests order.
-- This file must be loaded by calling /install/index.php page -- 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 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 rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);

View File

@@ -1,7 +1,7 @@
-- --
-- Be carefull to requests order. -- Be carefull to requests order.
-- This file must be loaded by calling /install/index.php page -- 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 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 add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;

View File

@@ -1,13 +1,19 @@
-- --
-- Be carefull to requests order. -- Be carefull to requests order.
-- This file must be loaded by calling /install/index.php page -- 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 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 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 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 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; 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 ref_fourn varchar(30) after fk_soc;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN entity integer DEFAULT 1 NOT NULL; 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 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); ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_fournisseur_price_ref (ref_fourn, fk_soc, quantity, entity);

View File

@@ -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) foreach($filelist as $file)
{ {
print '<tr><td nowrap>'; print '<tr><td nowrap>';