mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-24 23:09:13 +01:00
Mergeing in the most recently schema files
This commit is contained in:
parent
c5055a9d04
commit
28f53016d6
@ -17,17 +17,17 @@ class phpgw_schema_proc
|
|||||||
var $m_oDeltaProc;
|
var $m_oDeltaProc;
|
||||||
var $m_odb;
|
var $m_odb;
|
||||||
var $m_aTables;
|
var $m_aTables;
|
||||||
var $m_oDeltaOnly;
|
var $m_bDeltaOnly;
|
||||||
|
|
||||||
function phpgw_schema_proc($dbms)
|
function phpgw_schema_proc($dbms)
|
||||||
{
|
{
|
||||||
include(PHPGW_SERVER_ROOT . "/setup/inc/phpgw_schema_proc_" . $dbms . ".inc.php");
|
include("phpgw_schema_proc_" . $dbms . ".inc.php");
|
||||||
eval("\$this->m_oTranslator = new phpgw_schema_proc_$dbms;");
|
eval("\$this->m_oTranslator = new phpgw_schema_proc_$dbms;");
|
||||||
|
|
||||||
include(PHPGW_SERVER_ROOT . "/setup/inc/phpgw_schema_proc_array.inc.php");
|
include("phpgw_schema_proc_array.inc.php");
|
||||||
$this->m_oDeltaProc = new phpgw_schema_proc_array;
|
$this->m_oDeltaProc = new phpgw_schema_proc_array;
|
||||||
$this->m_aTables = array();
|
$this->m_aTables = array();
|
||||||
$this->m_oDeltaOnly = True; // Either is an insane default!
|
$this->m_bDeltaOnly = false; // Default to false here in case it's just a CreateTable script
|
||||||
}
|
}
|
||||||
|
|
||||||
function GenerateScripts($aTables, $bOutputHTML = false)
|
function GenerateScripts($aTables, $bOutputHTML = false)
|
||||||
@ -54,6 +54,7 @@ class phpgw_schema_proc
|
|||||||
{
|
{
|
||||||
if ($bOutputHTML)
|
if ($bOutputHTML)
|
||||||
print("<br>Failed generating script for <b>$sTableName</b><br>");
|
print("<br>Failed generating script for <b>$sTableName</b><br>");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,56 +117,63 @@ class phpgw_schema_proc
|
|||||||
function DropTable($sTableName)
|
function DropTable($sTableName)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->DropTable($this, $this->m_aTables, $sTableName);
|
$retVal = $this->m_oDeltaProc->DropTable($this, $this->m_aTables, $sTableName);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->DropTable($this, $this->m_aTables, $sTableName);
|
return $retVal && $this->m_oTranslator->DropTable($this, $this->m_aTables, $sTableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropColumn($sTableName, $aTableDef, $sColumnName, $bCopyData = true)
|
function DropColumn($sTableName, $aTableDef, $sColumnName, $bCopyData = true)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->DropColumn($this, $this->m_aTables, $sTableName, $aTableDef, $sColumnName, $bCopyData);
|
$retVal = $this->m_oDeltaProc->DropColumn($this, $this->m_aTables, $sTableName, $aTableDef, $sColumnName, $bCopyData);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->DropColumn($this, $this->m_aTables, $sTableName, $aTableDef, $sColumnName, $bCopyData);
|
return $retVal && $this->m_oTranslator->DropColumn($this, $this->m_aTables, $sTableName, $aTableDef, $sColumnName, $bCopyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RenameTable($sOldTableName, $sNewTableName)
|
function RenameTable($sOldTableName, $sNewTableName)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->RenameTable($this, $this->m_aTables, $sOldTableName, $sNewTableName);
|
$retVal = $this->m_oDeltaProc->RenameTable($this, $this->m_aTables, $sOldTableName, $sNewTableName);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->RenameTable($this, $this->m_aTables, $sOldTableName, $sNewTableName);
|
return $retVal && $this->m_oTranslator->RenameTable($this, $this->m_aTables, $sOldTableName, $sNewTableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = true)
|
function RenameColumn($sTableName, $sOldColumnName, $sNewColumnName, $bCopyData = true)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->RenameColumn($this, $this->m_aTables, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData);
|
$retVal = $this->m_oDeltaProc->RenameColumn($this, $this->m_aTables, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->RenameColumn($this, $this->m_aTables, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData);
|
return $retVal && $this->m_oTranslator->RenameColumn($this, $this->m_aTables, $sTableName, $sOldColumnName, $sNewColumnName, $bCopyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData = true)
|
function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData = true)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->AlterColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef, $bCopyData);
|
$retVal = $this->m_oDeltaProc->AlterColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef, $bCopyData);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->AlterColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef, $bCopyData);
|
return $retVal && $this->m_oTranslator->AlterColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef, $bCopyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddColumn($sTableName, $sColumnName, $aColumnDef)
|
function AddColumn($sTableName, $sColumnName, $aColumnDef)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->AddColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef);
|
$retVal = $this->m_oDeltaProc->AddColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->AddColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef);
|
return $retVal && $this->m_oTranslator->AddColumn($this, $this->m_aTables, $sTableName, $sColumnName, $aColumnDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CreateTable($sTableName, $aTableDef)
|
function CreateTable($sTableName, $aTableDef)
|
||||||
{
|
{
|
||||||
$retVal = $this->m_oDeltaProc->CreateTable($this, $this->m_aTables, $sTableName, $aTableDef);
|
$retVal = $this->m_oDeltaProc->CreateTable($this, $this->m_aTables, $sTableName, $aTableDef);
|
||||||
if ($this->m_oDeltaOnly)
|
if ($this->m_bDeltaOnly)
|
||||||
return $retVal;
|
return $retVal;
|
||||||
|
|
||||||
return $retVal && $this->m_oTranslator->CreateTable($this, $this->m_aTables, $sTableName, $aTableDef);
|
return $retVal && $this->m_oTranslator->CreateTable($this, $this->m_aTables, $sTableName, $aTableDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,10 +184,9 @@ class phpgw_schema_proc
|
|||||||
|
|
||||||
function _GetTableSQL($sTableName, $aTableDef, &$sTableSQL, &$sSequenceSQL)
|
function _GetTableSQL($sTableName, $aTableDef, &$sTableSQL, &$sSequenceSQL)
|
||||||
{
|
{
|
||||||
echo "is_array";
|
|
||||||
if (!is_array($aTableDef))
|
if (!is_array($aTableDef))
|
||||||
return false;
|
return false;
|
||||||
echo "it is";
|
|
||||||
$sTableSQL = "";
|
$sTableSQL = "";
|
||||||
reset($aTableDef["fd"]);
|
reset($aTableDef["fd"]);
|
||||||
while (list($sFieldName, $aFieldAttr) = each($aTableDef["fd"]))
|
while (list($sFieldName, $aFieldAttr) = each($aTableDef["fd"]))
|
||||||
@ -217,6 +224,7 @@ class phpgw_schema_proc
|
|||||||
{
|
{
|
||||||
if ($bOutputHTML)
|
if ($bOutputHTML)
|
||||||
print("<br>Failed getting primary key<br>");
|
print("<br>Failed getting primary key<br>");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,6 +235,7 @@ class phpgw_schema_proc
|
|||||||
{
|
{
|
||||||
if ($bOutputHTML)
|
if ($bOutputHTML)
|
||||||
print("<br>Failed getting unique constraint<br>");
|
print("<br>Failed getting unique constraint<br>");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ class phpgw_schema_proc_array
|
|||||||
{
|
{
|
||||||
if (IsSet($aTables[$sTableName]["fd"][$sColumnName]))
|
if (IsSet($aTables[$sTableName]["fd"][$sColumnName]))
|
||||||
$aTables[$sTableName]["fd"][$sColumnName] = $aColumnDef;
|
$aTables[$sTableName]["fd"][$sColumnName] = $aColumnDef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -59,7 +59,7 @@ class phpgw_schema_proc_pgsql
|
|||||||
$sTranslated = "text";
|
$sTranslated = "text";
|
||||||
break;
|
break;
|
||||||
case "timestamp":
|
case "timestamp":
|
||||||
$sTranslated = "timestamp";
|
$sTranslated = "timestamp";
|
||||||
break;
|
break;
|
||||||
case "varchar":
|
case "varchar":
|
||||||
if ($iPrecision > 0 && $iPrecision < 256)
|
if ($iPrecision > 0 && $iPrecision < 256)
|
||||||
@ -96,9 +96,9 @@ class phpgw_schema_proc_pgsql
|
|||||||
return "UNIQUE($sFields)";
|
return "UNIQUE($sFields)";
|
||||||
}
|
}
|
||||||
|
|
||||||
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = "")
|
function _GetColumns($oProc, $sTableName, &$sColumns, $sDropColumn = '', $sAlteredColumn = '', $sAlteredColumnType = '')
|
||||||
{
|
{
|
||||||
$sColumns = "";
|
$sColumns = '';
|
||||||
$query = "SELECT a.attname FROM pg_attribute a,pg_class b WHERE ";
|
$query = "SELECT a.attname FROM pg_attribute a,pg_class b WHERE ";
|
||||||
$query .= "b.oid=a.attrelid AND a.attnum>0 and b.relname='$sTableName'";
|
$query .= "b.oid=a.attrelid AND a.attnum>0 and b.relname='$sTableName'";
|
||||||
if ($sDropColumn != "")
|
if ($sDropColumn != "")
|
||||||
@ -110,12 +110,64 @@ class phpgw_schema_proc_pgsql
|
|||||||
{
|
{
|
||||||
if ($sColumns != "")
|
if ($sColumns != "")
|
||||||
$sColumns .= ",";
|
$sColumns .= ",";
|
||||||
$sColumns .= $oProc->m_odb->f(0);
|
|
||||||
|
$sFieldName = $oProc->m_odb->f(0);
|
||||||
|
$sColumns .= $sFieldName;
|
||||||
|
if ($sAlteredColumn == $sFieldName && $sAlteredColumnType != '')
|
||||||
|
$sColumns .= '::' . $sAlteredColumnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _CopyAlteredTable($oProc, &$aTables, $sSource, $sDest)
|
||||||
|
{
|
||||||
|
$oDB = $oProc->m_odb;
|
||||||
|
$oProc->m_odb->query("select * from $sSource");
|
||||||
|
while ($oProc->m_odb->next_record())
|
||||||
|
{
|
||||||
|
$sSQL = "insert into $sDest (";
|
||||||
|
for ($i = 0; $i < count($aTables[$sDest]); $i++)
|
||||||
|
{
|
||||||
|
if ($i > 0)
|
||||||
|
$sSQL .= ',';
|
||||||
|
|
||||||
|
$sSQL .= $aTables[$sDest]['fd'][$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
$sSQL .= ') values (';
|
||||||
|
for ($i = 0; $i < $oProc->m_odb->num_fields(); $i++)
|
||||||
|
{
|
||||||
|
if ($i > 0)
|
||||||
|
$sSQL .= ',';
|
||||||
|
|
||||||
|
if ($oProc->m_odb->f($i) != null)
|
||||||
|
{
|
||||||
|
switch ($aTables[$sDest]['fd'][$i])
|
||||||
|
{
|
||||||
|
case "blob":
|
||||||
|
case "char":
|
||||||
|
case "date":
|
||||||
|
case "text":
|
||||||
|
case "timestamp":
|
||||||
|
case "varchar":
|
||||||
|
$sSQL .= "'" . $oProc->m_odb->f($i) . "'";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$sSQL .= $oProc->m_odb->f($i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$sSQL .= 'null';
|
||||||
|
}
|
||||||
|
$sSQL .= ')';
|
||||||
|
|
||||||
|
$oDB->query($sSQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function DropTable($oProc, &$aTables, $sTableName)
|
function DropTable($oProc, &$aTables, $sTableName)
|
||||||
{
|
{
|
||||||
return !!($oProc->m_odb->query("DROP TABLE " . $sTableName));
|
return !!($oProc->m_odb->query("DROP TABLE " . $sTableName));
|
||||||
@ -124,9 +176,9 @@ class phpgw_schema_proc_pgsql
|
|||||||
function DropColumn($oProc, &$aTables, $sTableName, $aNewTableDef, $sColumnName, $bCopyData = true)
|
function DropColumn($oProc, &$aTables, $sTableName, $aNewTableDef, $sColumnName, $bCopyData = true)
|
||||||
{
|
{
|
||||||
if ($bCopyData)
|
if ($bCopyData)
|
||||||
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
|
$oProc->m_odb->query("SELECT * INTO $sTableName" . "_tmp FROM $sTableName");
|
||||||
else
|
|
||||||
$this->DropTable($oProc, $sTableName);
|
$this->DropTable($oProc, $aTables, $sTableName);
|
||||||
|
|
||||||
$oProc->_GetTableSQL($sTableName, $aNewTableDef, $sTableSQL);
|
$oProc->_GetTableSQL($sTableName, $aNewTableDef, $sTableSQL);
|
||||||
$query = "CREATE TABLE $sTableName ($sTableSQL)";
|
$query = "CREATE TABLE $sTableName ($sTableSQL)";
|
||||||
@ -137,7 +189,7 @@ class phpgw_schema_proc_pgsql
|
|||||||
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns, $sColumnName);
|
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns, $sColumnName);
|
||||||
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
||||||
$bRet = !!($oProc->m_odb->query($query));
|
$bRet = !!($oProc->m_odb->query($query));
|
||||||
return ($bRet && $this->DropTable($oProc, $sTableName . "_tmp"));
|
return ($bRet && $this->DropTable($oProc, $aTables, $sTableName . "_tmp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function RenameTable($oProc, &$aTables, $sOldTableName, $sNewTableName)
|
function RenameTable($oProc, &$aTables, $sOldTableName, $sNewTableName)
|
||||||
@ -150,9 +202,9 @@ class phpgw_schema_proc_pgsql
|
|||||||
// This really needs testing - it can affect primary keys, and other table-related objects
|
// This really needs testing - it can affect primary keys, and other table-related objects
|
||||||
// like sequences and such
|
// like sequences and such
|
||||||
if ($bCopyData)
|
if ($bCopyData)
|
||||||
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
|
$oProc->m_odb->query("SELECT * INTO $sTableName" . "_tmp FROM $sTableName");
|
||||||
else
|
|
||||||
$this->DropTable($oProc, $sTableName);
|
$this->DropTable($oProc, $aTables, $sTableName);
|
||||||
|
|
||||||
if (!$bCopyData)
|
if (!$bCopyData)
|
||||||
return $this->CreateTable($oProc, $aTables, $sTableName, $oProc->m_aTables[$sTableName], false);
|
return $this->CreateTable($oProc, $aTables, $sTableName, $oProc->m_aTables[$sTableName], false);
|
||||||
@ -162,26 +214,29 @@ class phpgw_schema_proc_pgsql
|
|||||||
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
||||||
|
|
||||||
$bRet = !!($oProc->m_odb->query($query));
|
$bRet = !!($oProc->m_odb->query($query));
|
||||||
return ($bRet && $this->DropTable($oProc, $sTableName . "_tmp"));
|
return ($bRet && $this->DropTable($oProc, $aTables, $sTableName . "_tmp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlterColumn($oProc, &$aTables, $sTableName, $sColumnName, &$aColumnDef, $bCopyData = true)
|
function AlterColumn($oProc, &$aTables, $sTableName, $sColumnName, &$aColumnDef, $bCopyData = true)
|
||||||
{
|
{
|
||||||
if ($bCopyData)
|
if ($bCopyData)
|
||||||
$oProc->m_odb->query("ALTER TABLE $sTableName RENAME TO $sTableName" . "_tmp");
|
$oProc->m_odb->query("SELECT * INTO $sTableName" . "_tmp FROM $sTableName");
|
||||||
else
|
|
||||||
$this->DropTable($oProc, $sTableName);
|
$this->DropTable($oProc, $aTables, $sTableName);
|
||||||
|
|
||||||
if (!$bCopyData)
|
if (!$bCopyData)
|
||||||
return $this->CreateTable($oProc, $aTables, $sTableName, $aTables[$sTableName], false);
|
return $this->CreateTable($oProc, $aTables, $sTableName, $aTables[$sTableName], false);
|
||||||
|
|
||||||
echo $aTables[$sTableName];
|
|
||||||
$this->CreateTable($oProc, $aTables, $sTableName, $aTables[$sTableName], false);
|
$this->CreateTable($oProc, $aTables, $sTableName, $aTables[$sTableName], false);
|
||||||
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns);
|
$this->_GetColumns($oProc, $sTableName . "_tmp", $sColumns, '', $sColumnName, $aColumnDef['type'] == 'auto' ? 'int4' : $aColumnDef['type']);
|
||||||
$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
|
||||||
|
|
||||||
$bRet = !!($oProc->m_odb->query($query));
|
// TODO: analyze the type of change and determine if this is used or _CopyAlteredTable
|
||||||
return ($bRet && $this->DropTable($oProc, $sTableName . "_tmp"));
|
//$query = "INSERT INTO $sTableName SELECT $sColumns FROM $sTableName" . "_tmp";
|
||||||
|
//$bRet = !!($oProc->m_odb->query($query));
|
||||||
|
|
||||||
|
$bRet = $this->_CopyAlteredTable($oProc, $aTables, $sTableName . '_tmp', $sTableName);
|
||||||
|
|
||||||
|
return ($bRet && $this->DropTable($oProc, $aTables, $sTableName . "_tmp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddColumn($oProc, &$aTables, $sTableName, $sColumnName, &$aColumnDef)
|
function AddColumn($oProc, &$aTables, $sTableName, $sColumnName, &$aColumnDef)
|
||||||
@ -207,7 +262,7 @@ class phpgw_schema_proc_pgsql
|
|||||||
$oProc->m_odb->query($sSequenceSQL);
|
$oProc->m_odb->query($sSequenceSQL);
|
||||||
|
|
||||||
$query = "CREATE TABLE $sTableName ($sTableSQL)";
|
$query = "CREATE TABLE $sTableName ($sTableSQL)";
|
||||||
echo $query;
|
|
||||||
return !!($oProc->m_odb->query($query));
|
return !!($oProc->m_odb->query($query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user