Hi,
Below is a quick stab at something that could do the upgrade procedure
for us.
Namely, every time in the future there is an update to do to the db, it
goes as a new function in upgrade.php
So... if in 'version' 56 I decide to remove a column, I would do
something like :
function upgrade_56() {
// probably need to switch between database types.
// see below.
db_query('alter table add column bar woof foo');
}
I've missed out the logic to update the config table after an upgrade,
but have included the logic not to include the same update twice.
Any comments/observations?
The only problems with the below is that it can't run on it's own
without the table already existing - I can't seem to use db_query($sql)
if the table doesn't exist and catch the error. Does this imply
db_query($sql) needs updating to return some sort of error code or call
trigger_error() instead?
(I've forwarded the svn ci message, so you can see the code as
necessary)
thanks
David
----- Forwarded message from Gin...@us... -----
Added: trunk/upgrade.php
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/upgrade.php (rev 0)
+++ trunk/upgrade.php 2007-10-31 20:18:53 UTC (rev 170)
@@ -0,0 +1,68 @@
+<?php
+require_once('common.php');
+$sql =3D "SELECT * FROM config WHERE name =3D 'version'";
+
+// create table config (name varchar(20), value varchar(20));
+// insert into config('version', '01');
+// Should really query the db to see if the 'config' table exists first!
+
+$r =3D db_query($sql);
+
+if($r['rows'] =3D=3D 1) {
+ $rs =3D $r['result'];
+ $row =3D db_array($rs);
+ $version =3D $row['value'];
+ _do_upgrade($version);
+}
+
+
+function _do_upgrade($current_version) {
+ $all_functions =3D get_defined_functions();
+ $upgrade_functions =3D array();
+ foreach($all_functions['user'] as $function_name) {
+ if(preg_match('!upgrade_(\d+)!', $function_name, $matches)) {
+ $version =3D $matches[1];
+ if($version <=3D $current_version) {
+ continue;
+ }
+ $upgrade_functions[$matches[1]] =3D $function_name;
+ }
+ }
+
+ ksort($upgrade_functions);
+ foreach($upgrade_functions as $version =3D> $function) {
+ $function();
+ }
+}
+
+function upgrade_00() {
+ global $CONF;
+ if($CONF['database_type'] =3D=3D 'mysql') {
+ echo 'mysql 00';
+ }
+ if($CONF['database_type'] =3D=3D 'pgsql') {
+ echo 'pgsql 00';
+ }
+}
+
+function upgrade_01() {
+ global $CONF;
+ if($CONF['database_type'] =3D=3D 'mysql') {
+ echo 'mysql 01';
+ }
+ if($CONF['database_type'] =3D=3D 'pgsql') {
+ echo 'pgsql 01';
+ }
+}
+function upgrade_02() {
+ global $CONF;
+ if($CONF['database_type'] =3D=3D 'mysql') {
+ echo 'mysql 02';
+ }
+ if($CONF['database_type'] =3D=3D 'pgsql') {
+ echo 'pgsql 02';
+ }
+}
+function upgrade_03() {
+ echo 'woof 03';
+}
This was sent by the SourceForge.net collaborative development platform, th=
e world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Postfixadmin-svn mailing list
Pos...@li...
https://lists.sourceforge.net/lists/listinfo/postfixadmin-svn
----- End forwarded message -----
--=20
David Goodwin=20
[ david at codepoets dot co dot uk ]
[ http://www.codepoets.co.uk ]
|