Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Enh #380: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
- Enh #381, #383: Add `ColumnDefinitionParser` class (@Tigrov)
- Enh #382: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov)
- New #384: Add `IndexMethod` class (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
36 changes: 36 additions & 0 deletions src/IndexMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Pgsql;

/**
* Defines the available index methods for {@see DDLQueryBuilder::createIndex()} method.
*/
final class IndexMethod
{
/**
* Define the type of the index as `BRIN`.
*/
public const BRIN = 'BRIN';
/**
* Define the type of the index as `BTREE`.
*/
public const BTREE = 'BTREE';
/**
* Define the type of the index as `GIN`.
*/
public const GIN = 'GIN';
/**
* Define the type of the index as `GIST`.
*/
public const GIST = 'GIST';
/**
* Define the type of the index as `HASH`.
*/
public const HASH = 'HASH';
/**
* Define the type of the index as `SPGIST`.
*/
public const SPGIST = 'SPGIST';
}
8 changes: 8 additions & 0 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Yiisoft\Db\Pgsql\Tests;

use PHPUnit\Framework\Attributes\DataProviderExternal;
use Throwable;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Dsn;
use Yiisoft\Db\Pgsql\Driver;
use Yiisoft\Db\Pgsql\Tests\Provider\CommandProvider;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonCommandTest;
use Yiisoft\Db\Tests\Support\DbHelper;
Expand Down Expand Up @@ -285,4 +287,10 @@ public function testShowDatabases(): void
$this->assertSame('pgsql:host=127.0.0.1;dbname=postgres;port=5432', $db->getDriver()->getDsn());
$this->assertSame(['yiitest'], $command->showDatabases());
}

#[DataProviderExternal(CommandProvider::class, 'createIndex')]
public function testCreateIndex(array $columns, array $indexColumns, string|null $indexType, string|null $indexMethod): void
{
parent::testCreateIndex($columns, $indexColumns, $indexType, $indexMethod);
}
}
15 changes: 15 additions & 0 deletions tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Yiisoft\Db\Expression\ArrayExpression;
use Yiisoft\Db\Expression\JsonExpression;
use Yiisoft\Db\Pgsql\Column\ColumnBuilder;
use Yiisoft\Db\Pgsql\IndexMethod;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;

final class CommandProvider extends \Yiisoft\Db\Tests\Provider\CommandProvider
Expand Down Expand Up @@ -90,4 +92,17 @@ public static function rawSql(): array
],
]);
}

public static function createIndex(): array
{
return [
...parent::createIndex(),
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::BTREE],
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::HASH],
[['col1' => ColumnBuilder::integer()], ['col1'], null, IndexMethod::BRIN],
[['col1' => ColumnBuilder::array()], ['col1'], null, IndexMethod::GIN],
[['col1' => 'point'], ['col1'], null, IndexMethod::GIST],
[['col1' => 'point'], ['col1'], null, IndexMethod::SPGIST],
];
}
}