Skip to content

Commit a9bdef3

Browse files
committed
Added drop operation for enum
1 parent 1e4ebe5 commit a9bdef3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/V2/Migration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ protected function foreignKey(array $fields, string $table, array $outerKeys): F
7474
return new ForeignKey($fields, $table, $outerKeys);
7575
}
7676

77-
protected function enum(string $name, array $values): TypeBuilder
77+
protected function enum(string $name): TypeBuilder
7878
{
7979
return new TypeBuilder(
8080
$name,
81-
$values,
8281
TypeBuilder::ENUM,
8382
$this->database()
8483
);

src/V2/TypeBuilder.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cycle\Migrations\V2;
66

77
use Cycle\Database\DatabaseInterface;
8+
use Cycle\Migrations\Exception\OperationException;
89

910
class TypeBuilder
1011
{
@@ -18,18 +19,20 @@ class TypeBuilder
1819

1920
public function __construct(
2021
string $name,
21-
array $values,
2222
string $type,
2323
DatabaseInterface $db
2424
) {
2525
$this->db = $db;
2626
$this->name = $name;
27-
$this->values = $values;
2827
$this->type = $type;
2928
}
3029

3130
public function create(): void
3231
{
32+
if (empty($this->values)) {
33+
throw new OperationException('Values can\'t be empty');
34+
}
35+
3336
$values = implode(',', array_map(static fn($v) => "'{$v}'", $this->values));
3437

3538
$query = sprintf(
@@ -50,4 +53,11 @@ public function drop(): void
5053
$this->db->commit();
5154

5255
}
56+
57+
public function addValues(array $values): self
58+
{
59+
$this->values = $values;
60+
61+
return $this;
62+
}
5363
}

0 commit comments

Comments
 (0)