Skip to content

Commit 9a3a14f

Browse files
authored
Drop unique index (#10)
* fix: drop unique using drop index cascade * Fix PHP styling Co-authored-by: tryvin <[email protected]>
1 parent ba05b63 commit 9a3a14f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Schema/CockroachGrammar.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,21 @@ public function compileDropFullText(Blueprint $blueprint, Fluent $command)
3434
{
3535
return $this->compileDropIndex($blueprint, $command);
3636
}
37+
38+
/**
39+
* Compile a drop unique key command.
40+
*
41+
* CockroachDB doesn't support alter table for dropping unique indexes.
42+
* https://github.com/cockroachdb/cockroach/issues/42840?version=v22.1
43+
*
44+
* @param \Illuminate\Database\Schema\Blueprint $blueprint
45+
* @param \Illuminate\Support\Fluent $command
46+
* @return string
47+
*/
48+
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
49+
{
50+
$index = $this->wrap($command->index);
51+
52+
return "drop index {$this->wrapTable($blueprint)}@{$index} cascade";
53+
}
3754
}

tests/Database/DatabaseCockroachDbSchemaGrammarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function test_drop_unique()
140140
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
141141

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

146146
public function test_drop_index()

0 commit comments

Comments
 (0)