Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL - possibility to create "character varying" column without limit #2233

Open
wants to merge 3 commits into
base: 0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@
case static::PHINX_TYPE_DOUBLE:
return ['name' => 'double precision'];
case static::PHINX_TYPE_STRING:
return ['name' => 'character varying', 'limit' => 255];
return ['name' => 'character varying'];

Check warning on line 1070 in src/Phinx/Db/Adapter/PostgresAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Phinx/Db/Adapter/PostgresAdapter.php#L1070

Added line #L1070 was not covered by tests
Mapiiik marked this conversation as resolved.
Show resolved Hide resolved
case static::PHINX_TYPE_CHAR:
return ['name' => 'character', 'limit' => 255];
case static::PHINX_TYPE_BIG_INTEGER:
Expand Down
20 changes: 10 additions & 10 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2462,12 +2462,12 @@ public function testDumpCreateTable()
->save();

if ($this->usingPostgres10()) {
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, "column1" CHARACTER VARYING (255) ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING (255) NOT NULL DEFAULT \'test\', CONSTRAINT ' .
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, "column1" CHARACTER VARYING ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING NOT NULL DEFAULT \'test\', CONSTRAINT ' .
'"table1_pkey" PRIMARY KEY ("id"));';
} else {
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" SERIAL NOT NULL, "column1" CHARACTER VARYING (255) ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING (255) NOT NULL DEFAULT \'test\', CONSTRAINT ' .
$expectedOutput = 'CREATE TABLE "public"."table1" ("id" SERIAL NOT NULL, "column1" CHARACTER VARYING ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING NOT NULL DEFAULT \'test\', CONSTRAINT ' .
'"table1_pkey" PRIMARY KEY ("id"));';
}
$actualOutput = $consoleOutput->fetch();
Expand All @@ -2494,12 +2494,12 @@ public function testDumpCreateTableWithSchema()
->save();

if ($this->usingPostgres10()) {
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, "column1" CHARACTER VARYING (255) ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING (255) NOT NULL DEFAULT \'test\', CONSTRAINT ' .
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, "column1" CHARACTER VARYING ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING NOT NULL DEFAULT \'test\', CONSTRAINT ' .
'"table1_pkey" PRIMARY KEY ("id"));';
} else {
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" SERIAL NOT NULL, "column1" CHARACTER VARYING (255) ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING (255) NOT NULL DEFAULT \'test\', CONSTRAINT ' .
$expectedOutput = 'CREATE TABLE "schema1"."table1" ("id" SERIAL NOT NULL, "column1" CHARACTER VARYING ' .
'NULL, "column2" INTEGER NULL, "column3" CHARACTER VARYING NOT NULL DEFAULT \'test\', CONSTRAINT ' .
'"table1_pkey" PRIMARY KEY ("id"));';
}
$actualOutput = $consoleOutput->fetch();
Expand Down Expand Up @@ -2639,13 +2639,13 @@ public function testDumpCreateTableAndThenInsert()
])->save();

$expectedOutput = <<<'OUTPUT'
CREATE TABLE "schema1"."table1" ("column1" CHARACTER VARYING (255) NOT NULL, "column2" INTEGER NULL, CONSTRAINT "table1_pkey" PRIMARY KEY ("column1"));
CREATE TABLE "schema1"."table1" ("column1" CHARACTER VARYING NOT NULL, "column2" INTEGER NULL, CONSTRAINT "table1_pkey" PRIMARY KEY ("column1"));
INSERT INTO "schema1"."table1" ("column1", "column2") OVERRIDING SYSTEM VALUE VALUES ('id1', 1);
OUTPUT;

if (!$this->usingPostgres10()) {
$expectedOutput = <<<'OUTPUT'
CREATE TABLE "schema1"."table1" ("column1" CHARACTER VARYING (255) NOT NULL, "column2" INTEGER NULL, CONSTRAINT "table1_pkey" PRIMARY KEY ("column1"));
CREATE TABLE "schema1"."table1" ("column1" CHARACTER VARYING NOT NULL, "column2" INTEGER NULL, CONSTRAINT "table1_pkey" PRIMARY KEY ("column1"));
INSERT INTO "schema1"."table1" ("column1", "column2") VALUES ('id1', 1);
OUTPUT;
}
Expand Down
Loading