Skip to content

Commit

Permalink
Drop unique index (#10)
Browse files Browse the repository at this point in the history
* fix: drop unique using drop index cascade

* Fix PHP styling

Co-authored-by: tryvin <[email protected]>
  • Loading branch information
tryvin and tryvin authored Sep 26, 2022
1 parent ba05b63 commit 9a3a14f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Schema/CockroachGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ public function compileDropFullText(Blueprint $blueprint, Fluent $command)
{
return $this->compileDropIndex($blueprint, $command);
}

/**
* Compile a drop unique key command.
*
* CockroachDB doesn't support alter table for dropping unique indexes.
* https://github.com/cockroachdb/cockroach/issues/42840?version=v22.1
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
{
$index = $this->wrap($command->index);

return "drop index {$this->wrapTable($blueprint)}@{$index} cascade";
}
}
2 changes: 1 addition & 1 deletion tests/Database/DatabaseCockroachDbSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function test_drop_unique()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table "users" drop constraint "foo"', $statements[0]);
$this->assertSame('drop index "users"@"foo" cascade', $statements[0]);
}

public function test_drop_index()
Expand Down

0 comments on commit 9a3a14f

Please sign in to comment.