Also make the schema_info table name configurable.
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
*/
protected $_targetVersion = null;
+ /**
+ * @var string
+ */
+ protected $_schemaTableName = 'schema_info';
+
/*##########################################################################
# Constructor
$this->_logger = new Horde_Support_Stub();
$this->_inflector = new Horde_Support_Inflector();
- $this->_connection->initializeSchemaInformation();
+ $this->_initializeSchemaInformation();
}
$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
}
/**
+ * @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);
}
$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');
$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');
$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');
$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');
*/
}
+ 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');