Skip to content

Commit 2105ce3

Browse files
authored
Add IndexMethod class (#384)
1 parent 45a4b12 commit 2105ce3

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Enh #380: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
2929
- Enh #381, #383: Add `ColumnDefinitionParser` class (@Tigrov)
3030
- Enh #382: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov)
31+
- New #384: Add `IndexMethod` class (@Tigrov)
3132

3233
## 1.3.0 March 21, 2024
3334

src/IndexMethod.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Db\Pgsql;
6+
7+
/**
8+
* Defines the available index methods for {@see DDLQueryBuilder::createIndex()} method.
9+
*/
10+
final class IndexMethod
11+
{
12+
/**
13+
* Define the type of the index as `BRIN`.
14+
*/
15+
public const BRIN = 'BRIN';
16+
/**
17+
* Define the type of the index as `BTREE`.
18+
*/
19+
public const BTREE = 'BTREE';
20+
/**
21+
* Define the type of the index as `GIN`.
22+
*/
23+
public const GIN = 'GIN';
24+
/**
25+
* Define the type of the index as `GIST`.
26+
*/
27+
public const GIST = 'GIST';
28+
/**
29+
* Define the type of the index as `HASH`.
30+
*/
31+
public const HASH = 'HASH';
32+
/**
33+
* Define the type of the index as `SPGIST`.
34+
*/
35+
public const SPGIST = 'SPGIST';
36+
}

tests/CommandTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use PHPUnit\Framework\Attributes\DataProviderExternal;
78
use Throwable;
89
use Yiisoft\Db\Exception\Exception;
910
use Yiisoft\Db\Exception\InvalidConfigException;
1011
use Yiisoft\Db\Exception\NotSupportedException;
1112
use Yiisoft\Db\Pgsql\Connection;
1213
use Yiisoft\Db\Pgsql\Dsn;
1314
use Yiisoft\Db\Pgsql\Driver;
15+
use Yiisoft\Db\Pgsql\Tests\Provider\CommandProvider;
1416
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
1517
use Yiisoft\Db\Tests\Common\CommonCommandTest;
1618
use Yiisoft\Db\Tests\Support\DbHelper;
@@ -285,4 +287,10 @@ public function testShowDatabases(): void
285287
$this->assertSame('pgsql:host=127.0.0.1;dbname=postgres;port=5432', $db->getDriver()->getDsn());
286288
$this->assertSame(['yiitest'], $command->showDatabases());
287289
}
290+
291+
#[DataProviderExternal(CommandProvider::class, 'createIndex')]
292+
public function testCreateIndex(array $columns, array $indexColumns, string|null $indexType, string|null $indexMethod): void
293+
{
294+
parent::testCreateIndex($columns, $indexColumns, $indexType, $indexMethod);
295+
}
288296
}

tests/Provider/CommandProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Yiisoft\Db\Expression\ArrayExpression;
88
use Yiisoft\Db\Expression\JsonExpression;
9+
use Yiisoft\Db\Pgsql\Column\ColumnBuilder;
10+
use Yiisoft\Db\Pgsql\IndexMethod;
911
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
1012

1113
final class CommandProvider extends \Yiisoft\Db\Tests\Provider\CommandProvider
@@ -90,4 +92,17 @@ public static function rawSql(): array
9092
],
9193
]);
9294
}
95+
96+
public static function createIndex(): array
97+
{
98+
return [
99+
...parent::createIndex(),
100+
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::BTREE],
101+
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::HASH],
102+
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::BRIN],
103+
[['col1' => ColumnBuilder::array()], ['col1'], null, IndexMethod::GIN],
104+
[['col1' => 'point'], ['col1'], null, IndexMethod::GIST],
105+
[['col1' => 'point'], ['col1'], null, IndexMethod::SPGIST],
106+
];
107+
}
93108
}

0 commit comments

Comments
 (0)