-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(database): fix database indexes and keys
- Loading branch information
1 parent
5e92f23
commit 5ddb09d
Showing
6 changed files
with
133 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Database\Sql; | ||
|
||
final class CreateIndexSqlBuilder extends SqlBuilder | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $columns = []; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $index; | ||
|
||
public function build(): string | ||
{ | ||
return sprintf( | ||
'CREATE INDEX `%s` ON `%s` (%s);', | ||
$this->index, | ||
$this->getTable(), | ||
implode(', ', $this->columns) | ||
); | ||
} | ||
|
||
public function index(string $name, array $columns): self | ||
{ | ||
$this->index = $name; | ||
$this->columns = $columns; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** @noinspection StaticClosureCanBeUsedInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\PrestaShop\Database\Sql; | ||
|
||
it('creates sql', function () { | ||
$builder = new CreateIndexSqlBuilder('table'); | ||
|
||
$builder->index('index_123', ['column1', 'column2']); | ||
|
||
$result = <<<SQL | ||
CREATE INDEX `index_123` ON `table` (column1, column2); | ||
SQL; | ||
|
||
expect($builder->build())->toEqual($result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters