Improved the upgrade/toolkit: make sure that NULL is allowed for SQL columns found in the DB but not defined in the data model (attribute removed or renamed)

SVN:trunk[1637]
This commit is contained in:
Romain Quetiez
2011-10-20 11:45:52 +00:00
parent f979dd40e0
commit ff201e8b8a

View File

@@ -3522,11 +3522,20 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
}
}
// Find out unused columns
//
foreach($aTableInfo['Fields'] as $sField => $aFieldData)
{
if (!isset($aFieldData['used']) || !$aFieldData['used'])
{
$aErrors[$sClass]['*'][] = "Column '$sField' in table '$sTable' is not used";
if (!CMDBSource::IsNullAllowed($sTable, $sField))
{
// Allow null values so that new record can be inserted
// without specifying the value of this unknown column
$sFieldDefinition = "`$sField` ".CMDBSource::GetFieldType($sTable, $sField).' NULL';
$aSugFix[$sClass][$sAttCode][] = "ALTER TABLE `$sTable` CHANGE `$sField` $sFieldDefinition";
$aAlterTableItems[$sTable][$sField] = "CHANGE `$sField` $sFieldDefinition";
}
}
}
}