Browse Source

Add support for FK constraints management for fixtures to the Postgres server

Yves P 10 years ago
parent
commit
c5e1ba77ac
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/Database/Schema/PostgresSchema.php

+ 31 - 0
src/Database/Schema/PostgresSchema.php

@@ -417,6 +417,37 @@ class PostgresSchema extends BaseSchema
         return $out;
     }
 
+
+    public function addConstraintSql(Table $table)
+    {
+        $sqlPattern = 'ALTER TABLE %s ADD %s';
+        $sql = [];
+
+        foreach ($table->constraints() as $name) {
+            $constraint = $table->constraint($name);
+            if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
+                $sql[] = sprintf($sqlPattern, $table->name(), $this->constraintSql($table, $name));
+            }
+        }
+
+        return $sql;
+    }
+
+    public function dropConstraintSql(Table $table)
+    {
+        $sqlPattern = 'ALTER TABLE %s DROP CONSTRAINT %s';
+        $sql = [];
+
+        foreach ($table->constraints() as $name) {
+            $constraint = $table->constraint($name);
+            if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
+                $sql[] = sprintf($sqlPattern, $table->name(), $name);
+            }
+        }
+
+        return $sql;
+    }
+
     /**
      * {@inheritDoc}
      */