Skip to content

Commit 591fc0c

Browse files
committed
added suport for gin index
1 parent abb1aa8 commit 591fc0c

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/Bosnadev/Database/Schema/Blueprint.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,52 @@
77
class Blueprint extends \Illuminate\Database\Schema\Blueprint
88
{
99

10+
/**
11+
* Add the index commands fluently specified on columns.
12+
*
13+
* @return void
14+
*/
15+
protected function addFluentIndexes()
16+
{
17+
foreach ($this->columns as $column)
18+
{
19+
foreach (array('primary', 'unique', 'index', 'gin') as $index)
20+
{
21+
// If the index has been specified on the given column, but is simply
22+
// equal to "true" (boolean), no name has been specified for this
23+
// index, so we will simply call the index methods without one.
24+
if ($column->$index === true)
25+
{
26+
$this->$index($column->name);
27+
28+
continue 2;
29+
}
30+
31+
// If the index has been specified on the column and it is something
32+
// other than boolean true, we will assume a name was provided on
33+
// the index specification, and pass in the name to the method.
34+
elseif (isset($column->$index))
35+
{
36+
$this->$index($column->name, $column->$index);
37+
38+
continue 2;
39+
}
40+
}
41+
}
42+
}
43+
44+
/**
45+
* Specify an index for the table.
46+
*
47+
* @param string|array $columns
48+
* @param string $name
49+
* @return \Illuminate\Support\Fluent
50+
*/
51+
public function gin($columns, $name = null)
52+
{
53+
return $this->indexCommand('gin', $columns, $name);
54+
}
55+
1056
/**
1157
* Create a new character column on the table.
1258
*
@@ -37,7 +83,7 @@ public function uuid($column) {
3783

3884
/**
3985
* Create a new jsonb column on the table
40-
*
86+
*
4187
* @param $column
4288
* @return \Illuminate\Support\Fluent
4389
*/

src/Bosnadev/Database/Schema/Grammars/PostgresGrammar.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace Bosnadev\Database\Schema\Grammars;
22

33
use Illuminate\Support\Fluent;
4+
use Bosnadev\Database\Schema\Blueprint;
45

56
/**
67
* Class PostgresGrammar
@@ -75,4 +76,18 @@ protected function isUuid($value) {
7576
return preg_match( '/^uuid_generate_v/', $value );
7677
}
7778

79+
/**
80+
* Compile a gin index key command.
81+
*
82+
* @param \Bosnadev\Database\Schema\Blueprint $blueprint
83+
* @param \Illuminate\Support\Fluent $command
84+
* @return string
85+
*/
86+
public function compileGin(Blueprint $blueprint, Fluent $command)
87+
{
88+
$columns = $this->columnize($command->columns);
89+
90+
return "create index {$command->index} on ".$this->wrapTable($blueprint)." using gin ({$columns})";
91+
}
92+
7893
}

0 commit comments

Comments
 (0)