Skip to content

Commit 0b4f9c3

Browse files
authored
Merge pull request #898 from cakephp/jsonb-shim
Add jsonb type shim for postgres adapter
2 parents 69732d9 + c24da7e commit 0b4f9c3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/Db/Adapter/PostgresAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ protected function mapColumnData(array $data): array
220220
) {
221221
$data['type'] = 'timestamptimezone';
222222
}
223+
// CakePHP only has a json type (which uses the JSONB storage type)
224+
if ($data['type'] === self::PHINX_TYPE_JSONB) {
225+
$data['type'] = 'json';
226+
}
223227

224228
return $data;
225229
}

tests/TestCase/Db/Adapter/PostgresAdapterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,19 @@ public function testAddColumnWithAutoIdentity()
653653
}
654654
}
655655

656+
/**
657+
* Test that shims from PHINX_TYPE_JSONB to 'json' type work.
658+
*/
659+
public function testAddColumnJsonbCompat()
660+
{
661+
$table = new Table('table1', [], $this->adapter);
662+
$table->save();
663+
$this->assertFalse($table->hasColumn('config'));
664+
$table->addColumn('config', 'jsonb')
665+
->save();
666+
$this->assertTrue($table->hasColumn('config'));
667+
}
668+
656669
public static function providerAddColumnIdentity(): array
657670
{
658671
return [

0 commit comments

Comments
 (0)