1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

A few fixes to Migrations and formatting/code fixes.

This commit is contained in:
Jonathan.Wage 2007-11-25 20:30:51 +00:00
parent 3829b0f2d4
commit 2bd3667750
4 changed files with 15 additions and 33 deletions

View file

@ -1114,7 +1114,7 @@ final class Doctrine
*/ */
public static function makeDirectories($path, $mode = 0777) public static function makeDirectories($path, $mode = 0777)
{ {
if (!$path) { if ( ! $path) {
return false; return false;
} }

View file

@ -584,4 +584,4 @@ class Doctrine_Migration
$this->addChange('removed_indexes', $options); $this->addChange('removed_indexes', $options);
} }
} }

View file

@ -82,9 +82,7 @@ class Doctrine_Migration_Builder
*/ */
public function setMigrationsPath($path) public function setMigrationsPath($path)
{ {
if ( ! file_exists($path)) { Doctrine::makeDirectories($path);
mkdir($path, 0777);
}
$this->migrationsPath = $path; $this->migrationsPath = $path;
} }
@ -138,7 +136,7 @@ END;
*/ */
public function generateMigrationsFromDb() public function generateMigrationsFromDb()
{ {
$directory = '/tmp/tmp_doctrine_models'; $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
Doctrine::generateModelsFromDb($directory); Doctrine::generateModelsFromDb($directory);
@ -173,7 +171,7 @@ END;
$up = $this->buildCreateTable($export); $up = $this->buildCreateTable($export);
$down = $this->buildDropTable($export); $down = $this->buildDropTable($export);
$className = 'Add'.Doctrine::classify($export['tableName']); $className = 'Add' . Doctrine::classify($export['tableName']);
$this->generateMigrationClass($className, array(), $up, $down); $this->generateMigrationClass($className, array(), $up, $down);
} }
@ -207,7 +205,7 @@ END;
*/ */
public function buildCreateForeignKey($tableName, $definition) public function buildCreateForeignKey($tableName, $definition)
{ {
return "\t\t\$this->createForeignKey('" . $tableName . "', " . $this->dataToPhpCode($definition) . ");"; return "\t\t\$this->createForeignKey('" . $tableName . "', " . var_export($definition, true) . ");";
} }
/** /**
@ -232,9 +230,9 @@ END;
{ {
$code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', "; $code = "\t\t\$this->createTable('" . $tableData['tableName'] . "', ";
$code .= $this->dataToPhpCode($tableData['columns']) . ", "; $code .= var_export($tableData['columns'], true) . ", ";
$code .= $this->dataToPhpCode(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary'])); $code .= var_export(array('indexes' => $tableData['options']['indexes'], 'primary' => $tableData['options']['primary']), true);
$code .= ");"; $code .= ");";
@ -252,22 +250,6 @@ END;
return "\t\t\$this->dropTable('" . $tableData['tableName'] . "');"; return "\t\t\$this->dropTable('" . $tableData['tableName'] . "');";
} }
/**
* dataToPhpCode
*
* @param string $data
* @return string
*/
public function dataToPhpCode($data)
{
ob_start();
var_export($data);
$results = ob_get_contents();
ob_end_clean();
return $results;
}
/** /**
* generateMigrationClass * generateMigrationClass
* *

View file

@ -116,13 +116,13 @@ class Doctrine_Migration_Process
public function processRenamedColumns($columns) public function processRenamedColumns($columns)
{ {
foreach ($columns as $column) { foreach ($columns as $column) {
$conn = $this->getConnection($column['tableName']); $conn = $this->getConnection($column['tableName']);
$columnList = $conn->import->listTableColumns($column['tableName']); $columnList = $conn->import->listTableColumns($column['tableName']);
if (isset($columnList[$column['oldColumnName']])) { if (isset($columnList[$column['oldColumnName']])) {
$conn->export->alterTable($column['tableName'], $conn->export->alterTable($column['tableName'],
array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'], array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'],
'definition'=>$columnList[$column['oldColumnName']])))); 'definition'=>$columnList[$column['oldColumnName']]))));
} }
} }
} }