Skip to content

Commit

Permalink
fix(database): only create indexes if they do not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Nov 7, 2023
1 parent ea19255 commit 33b89fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Database/Sql/CreateIndexSqlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class CreateIndexSqlBuilder extends SqlBuilder
public function build(): string
{
return sprintf(
'CREATE INDEX `%s` ON `%s` (%s);',
'CREATE INDEX IF NOT EXISTS `%s` ON `%s` (%s);',
$this->index,
$this->getTable(),
implode(', ', $this->columns)
Expand All @@ -28,7 +28,7 @@ public function build(): string

public function index(string $name, array $columns): self
{
$this->index = $name;
$this->index = $name;
$this->columns = $columns;

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Database/Sql/CreateIndexSqlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$builder->index('index_123', ['column1', 'column2']);

$result = <<<SQL
CREATE INDEX `index_123` ON `ps_table` (column1, column2);
CREATE INDEX IF NOT EXISTS `index_123` ON `ps_table` (column1, column2);
SQL;

expect($builder->build())->toEqual($result);
Expand Down

0 comments on commit 33b89fd

Please sign in to comment.