summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorPiotr Mrowczynski <mrow4a@yahoo.com>2017-10-02 12:32:21 +0200
committerJoas Schilling <coding@schilljs.com>2017-10-30 18:57:19 +0100
commit6a51c1bc4fd0f2496103f901fef3b550688c2364 (patch)
treea8f0e105711148d4f76953ee383c9af870849e47 /lib/private
parentd081a1a5adf007b383b0140c3ac469249d79878a (diff)
downloadnextcloud-server-6a51c1bc4fd0f2496103f901fef3b550688c2364.tar.gz
nextcloud-server-6a51c1bc4fd0f2496103f901fef3b550688c2364.zip
Add foreign key support to OC
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/OracleMigrator.php40
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/private/DB/OracleMigrator.php b/lib/private/DB/OracleMigrator.php
index b01ec78684b..4541f9cb72f 100644
--- a/lib/private/DB/OracleMigrator.php
+++ b/lib/private/DB/OracleMigrator.php
@@ -30,6 +30,7 @@ use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
+use Doctrine\DBAL\Schema\ForeignKeyConstraint;
class OracleMigrator extends NoCheckMigrator {
@@ -82,6 +83,27 @@ class OracleMigrator extends NoCheckMigrator {
}
/**
+ * Quote an ForeignKeyConstraint's name but changing the name requires recreating
+ * the ForeignKeyConstraint instance and copying over all properties.
+ *
+ * @param ForeignKeyConstraint $fkc old fkc
+ * @return ForeignKeyConstraint new fkc instance with new name
+ */
+ protected function quoteForeignKeyConstraint($fkc) {
+ return new ForeignKeyConstraint(
+ array_map(function($columnName) {
+ return $this->connection->quoteIdentifier($columnName);
+ }, $fkc->getLocalColumns()),
+ $this->connection->quoteIdentifier($fkc->getForeignTableName()),
+ array_map(function($columnName) {
+ return $this->connection->quoteIdentifier($columnName);
+ }, $fkc->getForeignColumns()),
+ $fkc->getName(),
+ $fkc->getOptions()
+ );
+ }
+
+ /**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
* @return \Doctrine\DBAL\Schema\SchemaDiff
@@ -100,7 +122,9 @@ class OracleMigrator extends NoCheckMigrator {
array_map(function(Index $index) {
return $this->quoteIndex($index);
}, $table->getIndexes()),
- $table->getForeignKeys(),
+ array_map(function(ForeignKeyConstraint $fck) {
+ return $this->quoteForeignKeyConstraint($fck);
+ }, $table->getForeignKeys()),
0,
$table->getOptions()
);
@@ -158,9 +182,17 @@ class OracleMigrator extends NoCheckMigrator {
return $this->quoteIndex($index);
}, $tableDiff->renamedIndexes);
- // TODO handle $tableDiff->addedForeignKeys
- // TODO handle $tableDiff->changedForeignKeys
- // TODO handle $tableDiff->removedForeignKeys
+ $tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
+ return $this->quoteForeignKeyConstraint($fkc);
+ }, $tableDiff->addedForeignKeys);
+
+ $tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
+ return $this->quoteForeignKeyConstraint($fkc);
+ }, $tableDiff->changedForeignKeys);
+
+ $tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) {
+ return $this->quoteForeignKeyConstraint($fkc);
+ }, $tableDiff->removedForeignKeys);
}
return $schemaDiff;