|
@@ -198,39 +198,6 @@ class Postgres extends Grammar {
|
|
return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})";
|
|
return $create." INDEX {$command->name} ON ".$this->wrap($table)." ({$columns})";
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Generate the SQL statement for creating a foreign key.
|
|
|
|
- *
|
|
|
|
- * @param Table $table
|
|
|
|
- * @param Command $command
|
|
|
|
- * @return string
|
|
|
|
- */
|
|
|
|
- public function foreign(Table $table, Fluent $command)
|
|
|
|
- {
|
|
|
|
- $name = $command->name;
|
|
|
|
-
|
|
|
|
- // We need to wrap both of the table names in quoted identifiers to protect
|
|
|
|
- // against any possible keyword collisions, both the table on which the
|
|
|
|
- // command is being executed and the referenced table are wrapped.
|
|
|
|
- $table = $this->wrap($table);
|
|
|
|
-
|
|
|
|
- $on = $this->wrap($command->on);
|
|
|
|
-
|
|
|
|
- // Next we need to columnize both the command table's columns as well as
|
|
|
|
- // the columns referenced by the foreign key. We'll cast the referenced
|
|
|
|
- // columns to an array since they aren't by the fluent command.
|
|
|
|
- $foreign = $this->columnize($command->columns);
|
|
|
|
-
|
|
|
|
- $referenced = $this->columnize((array) $command->references);
|
|
|
|
-
|
|
|
|
- // Finally we can built the SQL. This should be the same for all database
|
|
|
|
- // platforms we support, but we'll just keep it in the grammars since
|
|
|
|
- // adding foreign keys using ALTER isn't supported by SQLite.
|
|
|
|
- $sql = "ALTER TABLE $table ADD CONSTRAINT $name ";
|
|
|
|
-
|
|
|
|
- die($sql .= "FOREIGN KEY ($foreign) REFERENCES $on ($referenced)");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Generate the SQL statement for a drop table command.
|
|
* Generate the SQL statement for a drop table command.
|
|
*
|
|
*
|
|
@@ -287,7 +254,7 @@ class Postgres extends Grammar {
|
|
*/
|
|
*/
|
|
public function drop_unique(Table $table, Fluent $command)
|
|
public function drop_unique(Table $table, Fluent $command)
|
|
{
|
|
{
|
|
- return "ALTER TABLE ".$this->wrap($table)." DROP CONSTRAINT ".$command->name;
|
|
|
|
|
|
+ return $this->drop_constraint($table, $command);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -326,6 +293,18 @@ class Postgres extends Grammar {
|
|
return 'DROP INDEX '.$command->name;
|
|
return 'DROP INDEX '.$command->name;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Drop a foreign key constraint from the table.
|
|
|
|
+ *
|
|
|
|
+ * @param Table $table
|
|
|
|
+ * @param Fluent $fluent
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public function drop_foreign(Table $table, Fluent $command)
|
|
|
|
+ {
|
|
|
|
+ return $this->drop_constraint($table, $command);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Generate the data-type definition for a string.
|
|
* Generate the data-type definition for a string.
|
|
*
|
|
*
|