* PostgreSQL: automatic shorten all content requiring it, before schema update, to not stall 14.3 update

This commit is contained in:
Ralf Becker 2015-08-05 08:37:33 +00:00
parent 3714b053c8
commit cedc038f0c
2 changed files with 22 additions and 12 deletions

View File

@ -441,6 +441,21 @@ class schema_proc
function AlterColumn($sTableName, $sColumnName, $aColumnDef, $bCopyData=True)
{
$table_def = $this->GetTableDefinition($sTableName);
// PostgreSQL: varchar or ascii column shortened, use substring to avoid error if current content is to long
if($this->sType == 'pgsql' && in_array($table_def['fd'][$sColumnName]['type'], array('varchar', 'ascii')) &&
in_array($aColumnDef['type'], array('varchar', 'ascii')) &&
$table_def['fd'][$sColumnName]['precision'] > $aColumnDef['precision'])
{
$this->m_odb->update($sTableName, array(
"$sColumnName=SUBSTRING($sColumnName FROM 1 FOR ".(int)$aColumnDef['precision'].')',
), "LENGTH($sColumnName) > ".(int)$aColumnDef['precision'], __LINE__, __FILE__);
if (($shortend = $this->m_odb->affected_rows()))
{
error_log(__METHOD__."('$sTableName', '$sColumnName', ".array2string($aColumnDef).") $shortend values shortened");
}
}
$table_def['fd'][$sColumnName] = $aColumnDef;
$aSql = $this->dict->AlterColumnSQL($sTableName,$ado_col = $this->_egw2adodb_columndef(array(
@ -667,6 +682,13 @@ class schema_proc
{
$value = "ENCODE($value,'escape')";
}
// varchar or ascii column shortened, use substring to avoid error if current content is to long
elseif(in_array($old_table_def['fd'][$name]['type'], array('varchar', 'ascii')) &&
in_array($data['type'], array('varchar', 'ascii')) &&
$old_table_def['fd'][$name]['precision'] > $data['precision'])
{
$value = "SUBSTRING($value FROM 1 FOR ".(int)$data['precision'].')';
}
// cast everything which is a different type
elseif($old_table_def['fd'][$name]['type'] != $data['type'] && ($type_translated = $this->TranslateType($data['type'])))
{

View File

@ -159,12 +159,6 @@ function phpgwapi_upgrade14_2_004()
'nullable' => False
));*/
// shorten all acl_location entries to 16 chars, to not stall update for PostgreSQL
$GLOBALS['egw_setup']->db->update('egw_acl', array(
'acl_location=SUBSTRING(acl_location FROM 1 FOR 16)',
'acl_appname=SUBSTRING(acl_appname FROM 1 FOR 16)',
), 'LENGTH(acl_location) > 16 OR LENGTH(acl_appname) > 16', __LINE__, __FILE__);
$GLOBALS['egw_setup']->oProc->RefreshTable('egw_acl',array(
'fd' => array(
'acl_appname' => array('type' => 'ascii','precision' => '16','nullable' => False),
@ -372,12 +366,6 @@ function phpgwapi_upgrade14_2_012()
function phpgwapi_upgrade14_2_013()
{
// shorten all history_appname/history_status entries to 16/32 chars, to not stall update for PostgreSQL
$GLOBALS['egw_setup']->db->update('egw_history_log', array(
'history_appname=SUBSTRING(history_appname FROM 1 FOR 16)',
'history_status=SUBSTRING(history_status FROM 1 FOR 32)',
), 'LENGTH(history_appname) > 16 OR LENGTH(history_status) > 32', __LINE__, __FILE__);
$GLOBALS['egw_setup']->oProc->AlterColumn('egw_history_log','history_appname',array(
'type' => 'ascii',
'precision' => '16',