Re: [Phpgroupware-developers] About renaming columns in update functions

Dave Hall <[email protected]> Fri, 10 Feb 2006 20:52:13 +1100
Newsgroups gmane.comp.web.phpgroupware.documentation,gmane.comp.web.phpgroupware.devel
Organization phpGroupWare
Message-ID <[email protected]>
On Fri, 2006-02-10 at 10:25 +0100, Sigurd Nes wrote: 
> This should something for the doc-team.
> 

CCed this my response :)

This is a really good idea, not only for pgsql, but for all upgrade
scripts in general.  If it dies, we shouldn't leave a mess for the user
to try and clean up.  Very simple and elegant, but not obvious until
someone else mentions it :)

Cheers


Dave

> tables_update.inc.php
> 
> In order to do a successful renaming for a column in pgsql - one has to throw in the table definition.
> It is also wise to insulate the potentially damaging altering of the db in a transaction.
> 
> example:
> 
> /**
> * Update property version from 0.9.17.510 to 0.9.17.511
> */
> 
> $test[] = '0.9.17.510';
> function property_upgrade0_9_17_510()
> {
> 	$table_def = array(
> 		'fm_custom' => array(
> 			'fd' => array(
> 				'id' => array('type' => 'int','precision' => '4','nullable' => False),
> 				'name' => array('type' => 'varchar','precision' => '100','nullable' => False),
> 				'sql_text' => array('type' => 'text','nullable' => False),
> 				'entry_date' => array('type' => 'int','precision' => '4','nullable' => True),
> 				'user_id' => array('type' => 'int','precision' => '4','nullable' => True)
> 			),
> 			'pk' => array('id'),
> 			'fk' => array(),
> 			'ix' => array(),
> 			'uc' => array()
> 		)
> 	);
> 
> 	$GLOBALS['phpgw_setup']->oProc->m_aTables = $table_def;
> 	$GLOBALS['phpgw_setup']->oProc->m_odb->transaction_begin();
> 	$GLOBALS['phpgw_setup']->oProc->RenameColumn('fm_custom','sql','sql_text');
> 	$GLOBALS['setup_info']['property']['currentver'] = '0.9.17.511';
> 	$GLOBALS['phpgw_setup']->oProc->m_odb->transaction_commit();		
> 	return $GLOBALS['setup_info']['property']['currentver'];
> }