phpgroupware-docteam
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-docteam] Re: [Phpgroupware-developers] About renaming colu


From: Dave Hall
Subject: [Phpgroupware-docteam] Re: [Phpgroupware-developers] About renaming columns in update functions
Date: Fri, 10 Feb 2006 20:52:13 +1100

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'];
> }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]