[Cs-webdbupgrade-commits] SF.net SVN: cs-webdbupgrade:[23] trunk/0.1
Status: Inactive
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-08-04 15:40:50
|
Revision: 23
http://cs-webdbupgrade.svn.sourceforge.net/cs-webdbupgrade/?rev=23&view=rev
Author: crazedsanity
Date: 2009-08-04 15:40:42 +0000 (Tue, 04 Aug 2009)
Log Message:
-----------
Properly loads schema on first use.
/cs_webdbupgrade.class.php:
* MAIN:::
-- new private var, $sequenceName
* __construct():
-- make sure DB_TABLE and DB_PRIMARYKEY are defined configuration
parameters.
* get_database_version():
-- updated regex for if the table doesn't exist (this regex should be
consolidated).
* load_table():
-- replace the "primaryKey" var in the schema with the value from the
configuration.
-- pass the internal "sequenceName" to the call to run_insert().
/schema/schema.sql:
* added a (configured) primary key so the id of inserts can be returned.
* the "project_name" is no longer the primary key.
Modified Paths:
--------------
trunk/0.1/cs_webdbupgrade.class.php
trunk/0.1/schema/schema.sql
Modified: trunk/0.1/cs_webdbupgrade.class.php
===================================================================
--- trunk/0.1/cs_webdbupgrade.class.php 2009-07-30 16:19:26 UTC (rev 22)
+++ trunk/0.1/cs_webdbupgrade.class.php 2009-08-04 15:40:42 UTC (rev 23)
@@ -23,6 +23,9 @@
/** Array of configuration parameters. */
private $config = NULL;
+ /** Name of primary key sequence of main table (for handling inserts with PostgreSQL) */
+ private $sequenceName;
+
/** Database object. */
protected $db;
@@ -103,6 +106,11 @@
$this->gfObj->debugPrintOpt = constant('DEBUGPRINTOPT');
}
+ if(!isset($this->config['DB_PRIMARYKEY']) || !isset($this->config['DB_TABLE'])) {
+ throw new exception(__METHOD__ .": no setting for DB_TABLE or DB_PRIMARYKEY, cannot continue");
+ }
+ $this->sequenceName = $this->config['DB_TABLE'] .'_'. $this->config['DB_PRIMARYKEY'] .'_seq';
+
if(!defined('DBTYPE')) {
throw new exception(__METHOD__ .": required constant 'DBTYPE' not set");
}
@@ -123,6 +131,7 @@
$this->logsObj = new cs_webdblogger($this->db, "Upgrade");
}
catch(exception $e) {
+ $this->gfObj->debug_print($this->config,1);
throw new exception(__METHOD__ .": failed to connect to database or logger error: ". $e->getMessage());
}
@@ -458,7 +467,7 @@
if(strlen($dberror) || $numrows != 1) {
//
- if(preg_match('/doesn\'t exist/', $dberror)) {
+ if(preg_match('/doesn\'t exist/', $dberror) || preg_match('/does not exist/', $dberror)) {
//add the table...
$loadTableResult = $this->load_table();
if($loadTableResult === TRUE) {
@@ -914,6 +923,7 @@
$schemaFileLocation = dirname(__FILE__) .'/schema/schema.sql';
$schema = file_get_contents($schemaFileLocation);
$schema = str_replace('{tableName}', $this->config['DB_TABLE'], $schema);
+ $schema = str_replace('{primaryKey}', $this->config['DB_PRIMARYKEY'], $schema);
$this->db->exec($schema);
$loadTableResult = $this->db->errorMsg();
@@ -928,7 +938,7 @@
$insertData['project_name'] = $this->projectName;
$sql = 'INSERT INTO '. $this->config['DB_TABLE'] . $this->gfObj->string_from_array($insertData, 'insert');
- if($this->db->run_insert($sql)) {
+ if($this->db->run_insert($sql, $this->sequenceName)) {
$this->logsObj->log_by_class('Created initial version info ('. $insertData['version_string'] .')', $logType);
}
else {
Modified: trunk/0.1/schema/schema.sql
===================================================================
--- trunk/0.1/schema/schema.sql 2009-07-30 16:19:26 UTC (rev 22)
+++ trunk/0.1/schema/schema.sql 2009-08-04 15:40:42 UTC (rev 23)
@@ -14,7 +14,8 @@
-- The "{tableName}" portion will be replaced with the value of the configured
-- "DB_TABLE" setting.
CREATE TABLE {tableName} (
- project_name varchar(30) NOT NULL PRIMARY KEY,
+ {primaryKey} serial NOT NULL PRIMARY KEY,
+ project_name varchar(30) NOT NULL,
version_string varchar(50) NOT NULL,
version_major integer NOT NULL,
version_minor integer NOT NULL,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|