Skip to content
Permalink
Browse files

Merge pull request #29213 from danmichaelo/add-postgres-collation

Add Postgres support for collation() on columns
  • Loading branch information...
taylorotwell committed Jul 18, 2019
2 parents 1f74cc1 + 9775c60 commit 99522fc8186fe249526a56b82ad8e14c7ce4f831
@@ -11,7 +11,7 @@
* @method ColumnDefinition autoIncrement() Set INTEGER columns as auto-increment (primary key)
* @method ColumnDefinition change() Change the column
* @method ColumnDefinition charset(string $charset) Specify a character set for the column (MySQL)
* @method ColumnDefinition collation(string $collation) Specify a collation for the column (MySQL/SQL Server)
* @method ColumnDefinition collation(string $collation) Specify a collation for the column (MySQL/PostgreSQL/SQL Server)
* @method ColumnDefinition comment(string $comment) Add a comment to the column (MySQL)
* @method ColumnDefinition default(mixed $value) Specify a "default" value for the column
* @method ColumnDefinition first() Place the column "first" in the table (MySQL)
@@ -19,7 +19,7 @@ class PostgresGrammar extends Grammar
*
* @var array
*/
protected $modifiers = ['Increment', 'Nullable', 'Default'];
protected $modifiers = ['Collate', 'Increment', 'Nullable', 'Default'];
/**
* The columns available as serials.
@@ -879,6 +879,20 @@ private function formatPostGisType(string $type)
return "geography($type, 4326)";
}
/**
* Get the SQL for a collation column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->collation)) {
return ' collate '.$this->wrapValue($column->collation);
}
}
/**
* Get the SQL for a nullable column modifier.
*
@@ -21,10 +21,11 @@ public function testBasicCreateTable()
$blueprint->create();
$blueprint->increments('id');
$blueprint->string('email');
$blueprint->string('name')->collation('nb_NO.utf8');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertEquals('create table "users" ("id" serial primary key not null, "email" varchar(255) not null)', $statements[0]);
$this->assertEquals('create table "users" ("id" serial primary key not null, "email" varchar(255) not null, "name" varchar(255) collate "nb_NO.utf8" not null)', $statements[0]);
$blueprint = new Blueprint('users');
$blueprint->increments('id');

0 comments on commit 99522fc

Please sign in to comment.
You can’t perform that action at this time.