From 4fb5f7c20175e7b7a5e4d359acde6165f8b650ed Mon Sep 17 00:00:00 2001 From: romanb Date: Tue, 16 Oct 2007 17:05:52 +0000 Subject: [PATCH] added createForeignKey() support to export module and migrations --- lib/Doctrine/Export.php | 13 ++++++++++++- lib/Doctrine/Migration.php | 19 +++++++++++++++++-- lib/Doctrine/Migration/Process.php | 8 ++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index b6b060175..4e7e6094d 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -442,7 +442,7 @@ class Doctrine_Export extends Doctrine_Connection_Module $query .= ' (' . implode(', ', $fields) . ')'; return $query; - } + } /** * createForeignKeySql * @@ -458,6 +458,17 @@ class Doctrine_Export extends Doctrine_Connection_Module return $query; } + /** + * createForeignKey + * + * @param string $table name of the table on which the foreign key is to be created + * @param array $definition associative array that defines properties of the foreign key to be created. + * @return string + */ + public function createForeignKey($table, array $definition) + { + return $this->conn->execute($this->createForeignKeySql($table, $definition)); + } /** * alter an existing table * (this method is implemented by the drivers) diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index f60a579ef..932092c69 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -43,7 +43,8 @@ class Doctrine_Migration 'added_indexes' => array(), 'removed_indexes' => array(), 'created_constraints' => array(), - 'dropped_constraints' => array()), + 'dropped_constraints' => array(), + 'created_fks' => array()), $migrationTableName = 'migration_version', $migrationClassesDirectory = array(), $migrationClasses = array(); @@ -411,7 +412,7 @@ class Doctrine_Migration } /** - * createConstraint + * dropConstraint * * @param string $tableName * @param string $constraintName @@ -424,6 +425,20 @@ class Doctrine_Migration $this->addChange('dropped_constraints', $options); } + /** + * createForeignKey + * + * @param string $tableName + * @param string $constraintName + * @return void + */ + public function createForeignKey($tableName, array $definition) + { + $options = get_defined_vars(); + + $this->addChange('created_fks', $options); + } + /** * addColumn * diff --git a/lib/Doctrine/Migration/Process.php b/lib/Doctrine/Migration/Process.php index fc8081ec1..c0351f268 100644 --- a/lib/Doctrine/Migration/Process.php +++ b/lib/Doctrine/Migration/Process.php @@ -142,4 +142,12 @@ class Doctrine_Migration_Process $constraint['primary']); } } + + public function processCreatedFks($foreignKeys) + { + foreach ($foreignKeys as $fk) { + $conn = $this->getConnection($fk['tableName']); + $conn->export->createForeignKey($fk['tableName'], $fk['definition']); + } + } } \ No newline at end of file