diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 544af4b3edb..f308cecbd7a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -141,7 +141,6 @@ jobs: - 5432 env: POSTGRES_PASSWORD: secret - POSTGRES_USER: phalcon POSTGRES_DB: phalcon redis: image: redis:5-alpine @@ -249,13 +248,13 @@ jobs: DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }} run: vendor/bin/codecept run --ext DotReporter database --env sqlite -g sqlite -# # TODO Enable these one at a time and also for MacOS/Windows -# - name: Run database tests Postgres -# env: -# DATA_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }} -# DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }} -# DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }} -# run: vendor/bin/codecept run --ext DotReporter database --env pgsql + - name: Run database tests Postgres + env: + DATA_POSTGRES_USER: postgres + DATA_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }} + DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }} + DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }} + run: vendor/bin/codecept run --ext DotReporter database --env pgsql -g pgsql # - name: Run integrations tests SQL Server # env: # DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }} diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md index 36be71d50e1..396c8519695 100644 --- a/CHANGELOG-4.0.md +++ b/CHANGELOG-4.0.md @@ -5,6 +5,7 @@ ## Fixed - Fixed `Phalcon\Db::fetchAll` to correctly return data when `Enum::FETCH_COLUMN` is supplied. [#13321](https://github.com/phalcon/cphalcon/issues/13321) +- Fixed Postgres NULL values to not be required during model update. [#14862](https://github.com/phalcon/cphalcon/issues/14862) # [4.0.4](https://github.com/phalcon/cphalcon/releases/tag/v4.0.4) (2020-02-15) ## Added diff --git a/phalcon/Db/Adapter/Pdo/Postgresql.zep b/phalcon/Db/Adapter/Pdo/Postgresql.zep index a7cd294b165..e0827c9b38a 100644 --- a/phalcon/Db/Adapter/Pdo/Postgresql.zep +++ b/phalcon/Db/Adapter/Pdo/Postgresql.zep @@ -487,8 +487,8 @@ class Postgresql extends PdoAdapter /** * Check if the column allows null values */ - if field[5] == "NO" { - let definition["notNull"] = true; + if field[5] == "YES" { + let definition["notNull"] = false; } /** diff --git a/tests/_data/assets/schemas/pgsql.sql b/tests/_data/assets/schemas/pgsql.sql index de38cb0ebbe..a9663e6647c 100644 --- a/tests/_data/assets/schemas/pgsql.sql +++ b/tests/_data/assets/schemas/pgsql.sql @@ -1,9 +1,28 @@ +drop table if exists co_customers; + +create table co_customers +( + cst_id serial not null constraint co_customers_pk primary key, + cst_status_flag smallint null, + cst_name_last varchar(100) null, + cst_name_first varchar(50) null +); + +create index co_customers_cst_status_flag_index + on co_customers (cst_status_flag); + +create index co_customers_cst_name_last_index + on co_customers (cst_name_last); + +create index co_customers_cst_name_first_index + on co_customers (cst_name_first); + drop table if exists co_invoices; - + create table co_invoices ( inv_id serial not null constraint co_invoices_pk primary key, @@ -13,22 +32,22 @@ create table co_invoices inv_total numeric(10, 2), inv_created_at timestamp ); - + create index co_invoices_inv_created_at_index on co_invoices (inv_created_at); - + create index co_invoices_inv_cst_id_index on co_invoices (inv_cst_id); - + create index co_invoices_inv_status_flag_index on co_invoices (inv_status_flag); - -drop table if exists co_orders; - + +drop table if exists co_orders; + create table co_orders ( ord_id serial not null @@ -36,22 +55,22 @@ create table co_orders primary key, ord_name varchar(70) ); - -drop table if exists private.co_orders_x_products; - -create table private.co_orders_x_products + +drop table if exists public.co_orders_x_products; + +create table public.co_orders_x_products ( oxp_ord_id int not null, oxp_prd_id int not null, oxp_quantity int not null ); - -drop table if exists co_products; - + +drop table if exists co_products; + create table co_products ( prd_id serial not null @@ -59,7 +78,7 @@ create table co_products primary key, prd_name varchar(70) ); - + diff --git a/tests/_data/fixtures/Migrations/AbstractMigration.php b/tests/_data/fixtures/Migrations/AbstractMigration.php index 27fc4f6719c..9d87e0a6074 100644 --- a/tests/_data/fixtures/Migrations/AbstractMigration.php +++ b/tests/_data/fixtures/Migrations/AbstractMigration.php @@ -69,14 +69,18 @@ public function clear() ->connection ->getAttribute(PDO::ATTR_DRIVER_NAME) ; - if ('sqlite' !== $driver) { + if ($driver === 'mysql') { $this->connection->exec( 'truncate table ' . $this->table . ';' ); - } else { + } elseif ($driver === 'sqlite') { $this->connection->exec( 'delete from ' . $this->table . ';' ); + } else { + $this->connection->exec( + 'truncate table ' . $this->table . ' cascade;' + ); } } } diff --git a/tests/_data/fixtures/Migrations/CustomersMigration.php b/tests/_data/fixtures/Migrations/CustomersMigration.php index bb58fb09685..73c9c61bc4b 100644 --- a/tests/_data/fixtures/Migrations/CustomersMigration.php +++ b/tests/_data/fixtures/Migrations/CustomersMigration.php @@ -108,7 +108,32 @@ protected function getSqlSqlite(): array protected function getSqlPgsql(): array { - return []; + return [ + " +drop table if exists co_customers; + ", + " +create table co_customers +( + cst_id serial not null constraint co_customers_pk primary key, + cst_status_flag smallint null, + cst_name_last varchar(100) null, + cst_name_first varchar(50) null +); + ", + " +create index co_customers_cst_status_flag_index + on co_customers (cst_status_flag); + ", + " +create index co_customers_cst_name_last_index + on co_customers (cst_name_last); + ", + " +create index co_customers_cst_name_first_index + on co_customers (cst_name_first); + ", + ]; } protected function getSqlSqlsrv(): array diff --git a/tests/database/Mvc/Model/CreateCest.php b/tests/database/Mvc/Model/CreateCest.php index 7fce2b587cd..06dde790c17 100644 --- a/tests/database/Mvc/Model/CreateCest.php +++ b/tests/database/Mvc/Model/CreateCest.php @@ -47,6 +47,7 @@ public function _before(DatabaseTester $I) * * @group mysql * @group sqlite + * @group pgsql */ public function mvcModelCreate(DatabaseTester $I) { @@ -55,7 +56,6 @@ public function mvcModelCreate(DatabaseTester $I) $title = uniqid('inv-'); $date = date('Y-m-d H:i:s'); $invoice = new Invoices(); - $invoice->inv_id = 1; $invoice->inv_cst_id = 2; $invoice->inv_status_flag = 3; $invoice->inv_title = $title; diff --git a/tests/database/Mvc/Model/UpdateCest.php b/tests/database/Mvc/Model/UpdateCest.php index 7dfb08d4f43..c5e1b40f8d6 100644 --- a/tests/database/Mvc/Model/UpdateCest.php +++ b/tests/database/Mvc/Model/UpdateCest.php @@ -46,6 +46,7 @@ public function _before(DatabaseTester $I) * * @group mysql * @group sqlite + * @group pgsql */ public function mvcModelUpdate(DatabaseTester $I) { @@ -55,7 +56,6 @@ public function mvcModelUpdate(DatabaseTester $I) $invoice = new Invoices(); $invoice->assign( [ - 'inv_id' => 123, 'inv_title' => $title, ] ); @@ -83,7 +83,7 @@ public function mvcModelUpdate(DatabaseTester $I) $I->assertEquals( [ - 'inv_id' => 123, + 'inv_id' => $invoice->inv_id, 'inv_title' => $title, 'inv_cst_id' => 456, 'inv_status_flag' => 2,