From b562ef042f6d888e4d8fa9de95a23bbb204e3b40 Mon Sep 17 00:00:00 2001 From: Mapiiik <45870742+Mapiiik@users.noreply.github.com> Date: Mon, 30 Oct 2023 00:04:14 +0100 Subject: [PATCH 1/2] PostgreSQL - possibility to create "character varying" column without limit This change in the PostgreSQL adapter allows you to create a "character varying" column without a limit. Otherwise, even if we set the limit to "null" it still takes this default. --- src/Phinx/Db/Adapter/PostgresAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 843cb8306..05667f073 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -1067,7 +1067,7 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array case static::PHINX_TYPE_DOUBLE: return ['name' => 'double precision']; case static::PHINX_TYPE_STRING: - return ['name' => 'character varying', 'limit' => 255]; + return ['name' => 'character varying']; case static::PHINX_TYPE_CHAR: return ['name' => 'character', 'limit' => 255]; case static::PHINX_TYPE_BIG_INTEGER: From 5bfaecb0e5532a29d17d6e95d12cac77a19cc142 Mon Sep 17 00:00:00 2001 From: Mapiiik <45870742+Mapiiik@users.noreply.github.com> Date: Mon, 30 Oct 2023 00:26:02 +0100 Subject: [PATCH 2/2] Tests - PostgreSQL - "character varying" without limit PostgreSQL - fix tests after adding the ability to create "character varying" without limit --- .../Phinx/Db/Adapter/PostgresAdapterTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 65a8e3b6c..5c5f698b6 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -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(); @@ -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(); @@ -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; }