Skip to content

Commit

Permalink
Mapping the json type to JSONB in postgres
Browse files Browse the repository at this point in the history
I made a mistake in my previous pull request by mapping the json
type to plain JSON in postgres, when it should have been JSONB.

JSONB has the advantage that values inside can be indexed and searched
very efficiently.
  • Loading branch information
lorenzo committed Mar 26, 2016
1 parent 7c650f0 commit d67ba3f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Database/Schema/PostgresSchema.php
Expand Up @@ -345,7 +345,7 @@ public function columnSql(Table $table, $name)
'datetime' => ' TIMESTAMP',
'timestamp' => ' TIMESTAMP',
'uuid' => ' UUID',
'json' => ' JSON'
'json' => ' JSONB'
];

if (isset($typeMap[$data['type']])) {
Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Database/Schema/PostgresSchemaTest.php
Expand Up @@ -73,7 +73,7 @@ protected function _createTables($connection)
published BOOLEAN DEFAULT false,
views SMALLINT DEFAULT 0,
readingtime TIME,
data JSON,
data JSONB,
created TIMESTAMP,
CONSTRAINT "content_idx" UNIQUE ("title", "body"),
CONSTRAINT "author_idx" FOREIGN KEY ("author_id") REFERENCES "schema_authors" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
Expand Down Expand Up @@ -205,6 +205,10 @@ public static function convertColumnProvider()
'JSON',
['type' => 'json', 'length' => null]
],
[
'JSONB',
['type' => 'json', 'length' => null]
],
];
}

Expand Down Expand Up @@ -988,7 +992,7 @@ public function testCreateSql()
"id" SERIAL,
"title" VARCHAR NOT NULL,
"body" TEXT,
"data" JSON,
"data" JSONB,
"created" TIMESTAMP,
PRIMARY KEY ("id")
)
Expand Down

0 comments on commit d67ba3f

Please sign in to comment.