From: Chuck Hagenbuch Date: Wed, 13 Jan 2010 21:51:17 +0000 (-0500) Subject: Move management of the schema_info table entirely into the Migrator class. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=573f45513fe3c68cec203afaf40dab5c247ba904;p=horde.git Move management of the schema_info table entirely into the Migrator class. Also make the schema_info table name configurable. --- diff --git a/framework/Db/lib/Horde/Db/Adapter/Base/Schema.php b/framework/Db/lib/Horde/Db/Adapter/Base/Schema.php index aa5d9e90b..690cc736c 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base/Schema.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base/Schema.php @@ -669,20 +669,6 @@ abstract class Horde_Db_Adapter_Base_Schema abstract public function currentDatabase(); /** - * Should not be called normally, but this operation is non-destructive. - * The migrations module handles this automatically. - */ - public function initializeSchemaInformation() - { - try { - $this->execute("CREATE TABLE schema_info (". - " version ".$this->typeToSql('integer'). - ")"); - return $this->execute("INSERT INTO schema_info (version) VALUES (0)"); - } catch (Exception $e) {} - } - - /** * The sql for this column type * * @param string $type diff --git a/framework/Db/lib/Horde/Db/Migration/Migrator.php b/framework/Db/lib/Horde/Db/Migration/Migrator.php index 7bf75f0e6..08958677b 100644 --- a/framework/Db/lib/Horde/Db/Migration/Migrator.php +++ b/framework/Db/lib/Horde/Db/Migration/Migrator.php @@ -38,6 +38,11 @@ class Horde_Db_Migration_Migrator */ protected $_targetVersion = null; + /** + * @var string + */ + protected $_schemaTableName = 'schema_info'; + /*########################################################################## # Constructor @@ -63,7 +68,7 @@ class Horde_Db_Migration_Migrator $this->_logger = new Horde_Support_Stub(); $this->_inflector = new Horde_Support_Inflector(); - $this->_connection->initializeSchemaInformation(); + $this->_initializeSchemaInformation(); } @@ -111,15 +116,28 @@ class Horde_Db_Migration_Migrator $this->_doMigrate(); } + + /*########################################################################## + # Accessor + ##########################################################################*/ + /** - * @return int + * @return integer */ public function getCurrentVersion() { - $sql = 'SELECT version FROM schema_info'; + $sql = 'SELECT version FROM ' . $this->_schemaTableName; return $this->_connection->selectValue($sql); } + /** + * @param string $schemaTableName + */ + public function setSchemaTableName($schemaTableName) + { + $this->_schemaTableName = $schemaTableName; + } + /*########################################################################## # Protected @@ -216,12 +234,25 @@ class Horde_Db_Migration_Migrator } /** + * @TODO + */ + protected function _initializeSchemaInformation() + { + try { + $schemaTable = $this->_connection->createTable($this->_schemaTableName, array('primaryKey' => false)); + $schemaTable->column('version', 'integer'); + $schemaTable->end(); + return $this->_connection->insert('INSERT INTO ' . $this->_schemaTableName . ' (version) VALUES (0)'); + } catch (Exception $e) {} + } + + /** * @param integer $version */ protected function _setSchemaVersion($version) { $version = $this->_isDown() ? $version - 1 : $version; - $sql = "UPDATE schema_info SET version = " . (int)$version; + $sql = 'UPDATE ' . $this->_schemaTableName . ' SET version = ' . (int)$version; $this->_connection->update($sql); } diff --git a/framework/Db/test/Horde/Db/Adapter/MysqliTest.php b/framework/Db/test/Horde/Db/Adapter/MysqliTest.php index 3ace11bae..0b6e17a6d 100644 --- a/framework/Db/test/Horde/Db/Adapter/MysqliTest.php +++ b/framework/Db/test/Horde/Db/Adapter/MysqliTest.php @@ -1059,14 +1059,6 @@ class Horde_Db_Adapter_MysqliTest extends PHPUnit_Framework_TestCase $this->assertNotEquals($expected, $structure); } - public function testInitializeSchemaInformation() - { - $this->_conn->initializeSchemaInformation(); - - $sql = "SELECT version FROM schema_info"; - $this->assertEquals(0, $this->_conn->selectValue($sql)); - } - public function testTypeToSqlTypePrimaryKey() { $result = $this->_conn->typeToSql('primaryKey'); diff --git a/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php b/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php index c0fe67b45..cb787cd0e 100644 --- a/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php +++ b/framework/Db/test/Horde/Db/Adapter/Pdo/MysqlTest.php @@ -1079,14 +1079,6 @@ class Horde_Db_Adapter_Pdo_MysqlTest extends PHPUnit_Framework_TestCase $this->assertNotEquals($expected, $structure); } - public function testInitializeSchemaInformation() - { - $this->_conn->initializeSchemaInformation(); - - $sql = "SELECT version FROM schema_info"; - $this->assertEquals(0, $this->_conn->selectValue($sql)); - } - public function testTypeToSqlTypePrimaryKey() { $result = $this->_conn->typeToSql('primaryKey'); diff --git a/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php b/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php index 79322c931..cab6db38e 100644 --- a/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php +++ b/framework/Db/test/Horde/Db/Adapter/Pdo/PgsqlTest.php @@ -927,14 +927,6 @@ class Horde_Db_Adapter_Pdo_PgsqlTest extends PHPUnit_Framework_TestCase $this->assertEquals('test', $name); } - public function testInitializeSchemaInformation() - { - $this->_conn->initializeSchemaInformation(); - - $sql = "SELECT version FROM schema_info"; - $this->assertEquals(0, $this->_conn->selectValue($sql)); - } - public function testTypeToSqlTypePrimaryKey() { $result = $this->_conn->typeToSql('primaryKey'); diff --git a/framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php b/framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php index 065fc5539..d597bad06 100644 --- a/framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php +++ b/framework/Db/test/Horde/Db/Adapter/Pdo/SqliteTest.php @@ -946,14 +946,6 @@ class Horde_Db_Adapter_Pdo_SqliteTest extends PHPUnit_Framework_TestCase $this->assertNotEquals($expected, $structure); } - public function testInitializeSchemaInformation() - { - $this->_conn->initializeSchemaInformation(); - - $sql = "SELECT version FROM schema_info"; - $this->assertEquals(0, $this->_conn->selectValue($sql)); - } - public function testTypeToSqlTypePrimaryKey() { $result = $this->_conn->typeToSql('primaryKey'); diff --git a/framework/Db/test/Horde/Db/Migration/MigratorTest.php b/framework/Db/test/Horde/Db/Migration/MigratorTest.php index 7d8850687..a486d6cb8 100644 --- a/framework/Db/test/Horde/Db/Migration/MigratorTest.php +++ b/framework/Db/test/Horde/Db/Migration/MigratorTest.php @@ -96,6 +96,15 @@ client: */ } + public function testInitializeSchemaInformation() + { + $dir = dirname(dirname(__FILE__)).'/fixtures/migrations/'; + $migrator = new Horde_Db_Migration_Migrator($this->_conn, $dir); + + $sql = "SELECT version FROM schema_info"; + $this->assertEquals(0, $this->_conn->selectValue($sql)); + } + public function testMigrator() { $columns = $this->_columnNames('users');