From c002ae63371094b2cf9c731f779128e7a68e9970 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 2 Mar 2012 09:54:43 -0600 Subject: [PATCH] Use constraints for "unique" on Postgres schemas. Previous was using CREATE INDEX, should be using ADD CONSTRAINT as this will create the index automatically per Postgres documentation. Signed-off-by: Taylor Otwell --- laravel/database/schema/grammars/postgres.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/laravel/database/schema/grammars/postgres.php b/laravel/database/schema/grammars/postgres.php index 30bfa2f6..8eb6b4dd 100644 --- a/laravel/database/schema/grammars/postgres.php +++ b/laravel/database/schema/grammars/postgres.php @@ -146,7 +146,11 @@ public function primary(Table $table, Fluent $command) */ public function unique(Table $table, Fluent $command) { - return $this->key($table, $command, true); + $table = $this->wrap($table); + + $columns = $this->columnize($command->columns); + + return "ALTER TABLE $table ADD CONSTRAINT ".$command->name." UNIQUE ($columns)"; } /** @@ -283,7 +287,7 @@ public function drop_primary(Table $table, Fluent $command) */ public function drop_unique(Table $table, Fluent $command) { - return $this->drop_key($table, $command); + return "ALTER TABLE ".$this->wrap($table)." DROP CONSTRAINT ".$command->name; } /**