Skip to content

Commit

Permalink
Add support for SET type #81
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Apr 19, 2020
1 parent f19622f commit e29da7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Migration/Adapter/Generator/PhinxMySqlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ private function getPhinxColumnOptions(string $phinxType, array $columnData, arr
// Numeric attributes
$attributes = $this->getPhinxColumnOptionsNumeric($attributes, $columnData);

// Enum values
if ($phinxType === 'enum') {
$attributes = $this->getOptionEnumValue($attributes, $columnData);
// Enum and set values
if ($phinxType === 'enum' || $phinxType === 'set') {
$attributes = $this->getOptionEnumAndSetValues($attributes, $columnData);
}

// Collation
Expand Down Expand Up @@ -841,12 +841,12 @@ private function getPhinxColumnOptionsNumeric(array $attributes, array $columnDa
*
* @return array Attributes
*/
private function getOptionEnumValue(array $attributes, array $columnData): array
private function getOptionEnumAndSetValues(array $attributes, array $columnData): array
{
$match = null;
$pattern = '/enum\((.*)\)/';
$pattern = '/(enum|set)\((.*)\)/';
if (preg_match($pattern, $columnData['COLUMN_TYPE'], $match) === 1) {
$values = str_getcsv($match[1], ',', "'", '\\');
$values = str_getcsv($match[2], ',', "'", '\\');
$attributes['values'] = $values;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/PhinxGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,38 @@ public function testEnum(): void
$this->assertSame($oldSchema, $newSchema);
}

/**
* Test #81.
*
* @return void
*/
public function testSetValues(): void
{
$this->execSql("CREATE TABLE `test`(
`id` INT NOT NULL AUTO_INCREMENT,
`myset` SET('1','abc'),
PRIMARY KEY (`id`))
ENGINE=INNODB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;");

$this->generate();

$this->execSql("ALTER TABLE `test` CHANGE `myset` `myset` SET('1','abc','new')");
$oldSchema = $this->getTableSchema('test');
$this->generateAgain();

// Reset
$this->dropTables();

// Run all generated migrations
$this->migrate();

$newSchema = $this->getTableSchema('test');
$this->assertSame($oldSchema, $newSchema);
}


//

/**
* Test. #46.
*
Expand Down

0 comments on commit e29da7b

Please sign in to comment.