Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Added SET datatype on MySQL Grammar #28171

Merged
merged 2 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,18 @@ public function enum($column, array $allowed)
return $this->addColumn('enum', $column, compact('allowed'));
}

/**
* Create a new set column on the table.
*
* @param string $column
* @param array $allowed
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function set($column, array $allowed)
{
return $this->addColumn('set', $column, compact('allowed'));
}

/**
* Create a new json column on the table.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,17 @@ protected function typeEnum(Fluent $column)
return sprintf('enum(%s)', $this->quoteString($column->allowed));
}

/**
* Create the column definition for a set enumeration type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeSet(Fluent $column)
{
return sprintf('set(%s)', $this->quoteString($column->allowed));
}

/**
* Create the column definition for a json type.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,16 @@ public function testAddingEnum()
$this->assertEquals('alter table `users` add `role` enum(\'member\', \'admin\') not null', $statements[0]);
}

public function testAddingSet()
{
$blueprint = new Blueprint('users');
$blueprint->set('role', ['member', 'admin']);
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table `users` add `role` set(\'member\', \'admin\') not null', $statements[0]);
}

public function testAddingJson()
{
$blueprint = new Blueprint('users');
Expand Down