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
7 changes: 5 additions & 2 deletions docs/en/writing-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@ however with the MySQL adapter + MariaDB, the `nativeuuid` type maps to
a native uuid column instead of `CHAR(36)` like `uuid` does.

In addition, the Postgres adapter supports `interval`, `json`, `jsonb`,
`uuid`, `cidr`, `inet` and `macaddr` column types (PostgreSQL 9.3 and
above).
`uuid`, `cidr`, `inet`, `macaddr` and `citext` column types (PostgreSQL 9.3
and above). The `citext` type requires the `citext` extension to be enabled
on the database; the migration does not create the extension automatically,
run `CREATE EXTENSION IF NOT EXISTS citext` first (for example from an
earlier migration via `$this->execute(...)`).

### Valid Column Options

Expand Down
2 changes: 2 additions & 0 deletions src/Db/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ interface AdapterInterface

public const TYPE_MACADDR = TableSchemaInterface::TYPE_MACADDR;

public const TYPE_CITEXT = TableSchemaInterface::TYPE_CITEXT;

public const TYPE_INTERVAL = TableSchemaInterface::TYPE_INTERVAL;

/**
Expand Down
1 change: 1 addition & 0 deletions src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PostgresAdapter extends AbstractAdapter
self::TYPE_CIDR,
self::TYPE_INET,
self::TYPE_MACADDR,
self::TYPE_CITEXT,
self::TYPE_INTERVAL,
self::TYPE_BINARY_UUID,
self::TYPE_NATIVE_UUID,
Expand Down
3 changes: 3 additions & 0 deletions src/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Column extends DatabaseColumn
/** Postgres-only column type */
public const MACADDR = TableSchemaInterface::TYPE_MACADDR;

/** Postgres-only column type, requires the `citext` extension */
public const CITEXT = TableSchemaInterface::TYPE_CITEXT;

/** Postgres-only column type */
public const INTERVAL = TableSchemaInterface::TYPE_INTERVAL;

Expand Down
28 changes: 28 additions & 0 deletions tests/TestCase/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,34 @@ public function testAddColumnJsonbCompat(): void
$this->assertTrue($table->hasColumn('config'));
}

/**
* Test that adding a column with the citext type works.
*
* Requires the `citext` extension to be enabled on the database; the setUp
* above creates the extension when missing.
*/
public function testAddColumnCitext(): void
{
$table = new Table('table1', [], $this->adapter);
$table->save();
$this->assertFalse($table->hasColumn('nickname'));
$table->addColumn('nickname', 'citext', ['null' => true])
->save();
$this->assertTrue($table->hasColumn('nickname'));

$columns = $this->adapter->getColumns('table1');
$nickname = null;
foreach ($columns as $column) {
if ($column->getName() === 'nickname') {
$nickname = $column;
break;
}
}
$this->assertNotNull($nickname);
$this->assertSame('citext', $nickname->getType());
$this->assertTrue($nickname->isNull());
}

public static function providerAddColumnIdentity(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Db/Adapter/SqliteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,7 @@ public static function provideColumnTypesForValidation(): array
[SqliteAdapter::TYPE_UUID, true],
[SqliteAdapter::TYPE_TIMESTAMP, true],
[SqliteAdapter::TYPE_CIDR, false],
[SqliteAdapter::TYPE_CITEXT, false],
[SqliteAdapter::TYPE_DECIMAL, true],
[SqliteAdapter::TYPE_GEOMETRY, false],
[SqliteAdapter::TYPE_INET, false],
Expand Down
Loading