[Cs-webdbupgrade-commits] SF.net SVN: cs-webdbupgrade:[31] trunk/0.1
Status: Inactive
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-08-06 20:45:47
|
Revision: 31
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=31&view=rev
Author: crazedsanity
Date: 2009-08-06 20:45:38 +0000 (Thu, 06 Aug 2009)
Log Message:
-----------
Upgrade scripts & schema.
Modified Paths:
--------------
trunk/0.1/schema/schema.sql
Added Paths:
-----------
trunk/0.1/upgrades/
trunk/0.1/upgrades/upgrade.xml
trunk/0.1/upgrades/upgradeTo0.2.0.php
Modified: trunk/0.1/schema/schema.sql
===================================================================
--- trunk/0.1/schema/schema.sql 2009-08-06 20:44:19 UTC (rev 30)
+++ trunk/0.1/schema/schema.sql 2009-08-06 20:45:38 UTC (rev 31)
@@ -15,7 +15,7 @@
-- "DB_TABLE" setting.
CREATE TABLE {tableName} (
{primaryKey} serial NOT NULL PRIMARY KEY,
- project_name varchar(30) NOT NULL,
+ project_name varchar(30) NOT NULL UNIQUE,
version_string varchar(50) NOT NULL,
version_major integer NOT NULL,
version_minor integer NOT NULL,
Copied: trunk/0.1/upgrades/upgrade.xml (from rev 23, trunk/0.1/exampleUpgrades/upgrade.xml)
===================================================================
--- trunk/0.1/upgrades/upgrade.xml (rev 0)
+++ trunk/0.1/upgrades/upgrade.xml 2009-08-06 20:45:38 UTC (rev 31)
@@ -0,0 +1,30 @@
+<upgrade>
+ <system_note>To determine which section in matching to use, heed only the information
+ beneath the tag that indicates the current database version (for 5.2.4,
+ you would find information under matching for "v5.2.4"). This section
+ indicates the version that it should upgrade the database to
+ ("target_version"), the name of the script ("script_name"), the class name
+ ("class_name"), and the name of the method within that class ("call_method")
+ to call in order to perform the upgrade. The method should return TRUE on
+ success: anything else would indicate failure. Upgrade failure may leave
+ the system in an inconsistent state.
+
+ IMPORTANT: in order to facilitate doing multiple version upgrades, the name
+ of the class must be UNIQUE to all the other classes. For this reason, the
+ class name should be something like "v1_0_0_ALPHA1__to__v1_0_0_ALPHA2".
+
+ REMEMBER: the "target_version" should NEVER be higher than the next item
+ beneath matching; this will cause horrible logic errors, causing an upgsrade
+ to get skipped, or an exception to be thrown, potentially leaving the system
+ in an unstable state. Unstable is bad, m'kay?</system_note>
+
+ <initialversion>0.1.0</initialversion>
+ <matching>
+ <v0.1.0>
+ <target_version>0.2.0</target_version>
+ <script_name>upgradeTo0.2.0.php</script_name>
+ <class_name>upgrade_to_0_2_0</class_name>
+ <call_method>run_upgrade</call_method>
+ </v0.1.0>
+ </matching>
+</upgrade>
Copied: trunk/0.1/upgrades/upgradeTo0.2.0.php (from rev 23, trunk/0.1/exampleUpgrades/upgradeTo1.2.0-ALPHA4.php)
===================================================================
--- trunk/0.1/upgrades/upgradeTo0.2.0.php (rev 0)
+++ trunk/0.1/upgrades/upgradeTo0.2.0.php 2009-08-06 20:45:38 UTC (rev 31)
@@ -0,0 +1,52 @@
+<?php
+
+class upgrade_to_0_2_0 extends cs_webdbupgrade {
+
+ //=========================================================================
+ public function __construct(cs_phpDB &$db) {
+ if(!$db->is_connected()) {
+ throw new exception(__METHOD__ .": database is not connected");
+ }
+ $this->db = $db;
+
+ $this->gfObj = new cs_globalFunctions;
+ $this->gfObj->debugPrintOpt = 1;
+
+ //make sure there's enough info to use.
+ $requiredConstants = array(
+ 'table' => 'cs_webdbupgrade-DB_TABLE',
+ 'pkey' => 'cs_webdbupgrade-DB_PRIMARYKEY',
+ 'seq' => 'cs_webdbupgrade-DB_SEQUENCE'
+ );
+
+ $this->dbStuff = array();
+ foreach($requiredConstants as $k=>$v) {
+ if(defined($v)) {
+ $this->dbStuff[$k] = constant($v);
+ }
+ else {
+ throw new exception(__METHOD__ .": missing required constant (". $v .")");
+ }
+ }
+
+
+ }//end __construct()
+ //=========================================================================
+
+
+
+ //=========================================================================
+ public function run_upgrade() {
+
+ $dropColumns = array('version_major', 'version_minor', 'version_maintenance', 'version_suffix');
+ foreach($dropColumns as $col) {
+ $sql = "ALTER TABLE ". $this->dbStuff['table'] ." DROP COLUMN ". $col;
+ $this->db->run_update($sql, true);
+ }
+
+ return(true);
+ }//end run_upgrade()
+ //=========================================================================
+}
+
+?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|