From 13acfaa7c343bb2c0b766dd100a82c9665d87146 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 18:35:38 +0000 Subject: [PATCH 01/24] #14862 - Swap condition if column allows null values --- phalcon/Db/Adapter/Pdo/Postgresql.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } /** From 104a76725e9e5386eac9e025e0ca7e4f29cdc61e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 18:47:04 +0000 Subject: [PATCH 02/24] #14862 - Enable CI step to run database tests with Postgres --- .github/workflows/build-and-test.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 544af4b3edb..f2ef2e25e38 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -249,13 +249,12 @@ 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_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'] }} From ec9b51a1f175d2d61e13e7a992400f284b4cef3c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 18:47:36 +0000 Subject: [PATCH 03/24] #14862 - Add 'pgsql' group for some tests --- tests/database/Mvc/Model/CreateCest.php | 1 + tests/database/Mvc/Model/UpdateCest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/database/Mvc/Model/CreateCest.php b/tests/database/Mvc/Model/CreateCest.php index 7fce2b587cd..671e855a93f 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) { diff --git a/tests/database/Mvc/Model/UpdateCest.php b/tests/database/Mvc/Model/UpdateCest.php index 7dfb08d4f43..23336bd056b 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) { From 375bf79c53bbb13ee0be4cef7513981d1b19dd6a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:13:31 +0000 Subject: [PATCH 04/24] #14862 - Rename 'private' schema to 'public' --- tests/_data/assets/schemas/pgsql.sql | 48 +++++++++++----------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/tests/_data/assets/schemas/pgsql.sql b/tests/_data/assets/schemas/pgsql.sql index f39ce6a79bf..20d6cf3c54f 100644 --- a/tests/_data/assets/schemas/pgsql.sql +++ b/tests/_data/assets/schemas/pgsql.sql @@ -1,9 +1,5 @@ - - - - drop table if exists co_invoices; - + create table co_invoices ( inv_id serial not null constraint co_invoices_pk primary key, @@ -13,24 +9,23 @@ create table co_invoices inv_total numeric(10, 2), inv_created_at timestamp ); - + alter table co_invoices owner to postgres; - + 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 @@ -38,26 +33,26 @@ create table co_orders primary key, ord_name varchar(70) ); - + alter table public.co_orders owner to postgres; - -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 ); - -alter table private.co_orders_x_products owner to postgres; - + +alter table public.co_orders_x_products owner to postgres; + -drop table if exists co_products; - +drop table if exists co_products; + create table co_products ( prd_id serial not null @@ -65,12 +60,5 @@ create table co_products primary key, prd_name varchar(70) ); - -alter table public.co_products owner to postgres; - - - - - - +alter table public.co_products owner to postgres; From 711311919a34f225c93361322e95e6319d390974 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:24:58 +0000 Subject: [PATCH 05/24] #14862 - Add debug info of env variable --- .github/workflows/build-and-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f2ef2e25e38..2afa45b856b 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -254,7 +254,9 @@ jobs: 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 + run: | + echo ${DATA_POSTGRES_SCHEMA} + 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'] }} From e35f9eb98bb5d463c96a5fb97c6641f01ae1b559 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:41:03 +0000 Subject: [PATCH 06/24] #14862 - Rename 'private' schema to 'public' --- tests/_data/assets/schemas/mysql.sql | 54 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/_data/assets/schemas/mysql.sql b/tests/_data/assets/schemas/mysql.sql index 48e2e8d6b8e..936d1950dd2 100644 --- a/tests/_data/assets/schemas/mysql.sql +++ b/tests/_data/assets/schemas/mysql.sql @@ -1,7 +1,7 @@ drop table if exists `co_customers`; - + create table co_customers ( `cst_id` int(10) auto_increment primary key, @@ -9,20 +9,20 @@ create table co_customers `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` int(10) auto_increment primary key, @@ -32,90 +32,90 @@ create table co_invoices `inv_total` float(10, 2) null, `inv_created_at` datetime null ); - + 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`); - + create index co_invoices_inv_created_at_index on `co_invoices` (`inv_created_at`); - + drop table if exists objects; - + create table objects ( `obj_id` int(10) auto_increment primary key, `obj_name` varchar(100) not null, `obj_type` tinyint(3) unsigned not null ); - + drop table if exists `co_orders`; - + CREATE TABLE `co_orders` ( `ord_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ord_name` VARCHAR(70) NULL, PRIMARY KEY (`ord_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -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(10) unsigned NOT NULL, `oxp_prd_id` int(10) unsigned NOT NULL, `oxp_quantity` int(10) unsigned NOT NULL, PRIMARY KEY (`oxp_ord_id`, `oxp_prd_id` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + drop table if exists `co_products`; - + CREATE TABLE `co_products` ( `prd_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `prd_name` VARCHAR(70) NULL, PRIMARY KEY (`prd_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + drop table if exists `co_sources`; - + create table co_sources ( `id` int(10) auto_increment primary key, `username` varchar(100) null, `source` varchar(100) null ); - + create index co_sources_username_index on co_sources (username); - + drop table if exists `table_with_uuid_primary`; - + create table table_with_uuid_primary ( `uuid` char(36) not null primary key, `int_field` int null ); - + drop table if exists `stuff`; - + create table stuff ( `stf_id` int(10) auto_increment primary key, `stf_name` varchar(100) not null, `stf_type` tinyint(3) unsigned not null ); - + From ae3b985091a03a094f5283d180ea87954ebf4a90 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:43:24 +0000 Subject: [PATCH 07/24] #14862 - Rename 'private' schema to 'public' --- tests/_data/fixtures/models/OrdersProducts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_data/fixtures/models/OrdersProducts.php b/tests/_data/fixtures/models/OrdersProducts.php index b13e6ecd13e..2a15754093a 100644 --- a/tests/_data/fixtures/models/OrdersProducts.php +++ b/tests/_data/fixtures/models/OrdersProducts.php @@ -29,7 +29,7 @@ class OrdersProducts extends Model public function initialize() { - $this->setSchema('private'); + $this->setSchema('public'); $this->setSource('co_orders_x_products'); } } From 73b88a6d0d132a8763e22802a719ef0295200ae4 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:43:50 +0000 Subject: [PATCH 08/24] #14862 - Rename 'private' schema to 'public' --- tests/_envs/mysql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_envs/mysql.yml b/tests/_envs/mysql.yml index fac9699a8d0..3176890b6cb 100644 --- a/tests/_envs/mysql.yml +++ b/tests/_envs/mysql.yml @@ -12,4 +12,4 @@ modules: waitlock: 10 initial_queries: - "SET NAMES utf8;" - - "CREATE SCHEMA IF NOT EXISTS private" + - "CREATE SCHEMA IF NOT EXISTS public" From 054d1f68e39b463d781ea122597a22f6e7a4599a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 19:55:59 +0000 Subject: [PATCH 09/24] #14862 - Rename 'private' schema to 'public' --- tests/database/Mvc/Model/Criteria/JoinCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/database/Mvc/Model/Criteria/JoinCest.php b/tests/database/Mvc/Model/Criteria/JoinCest.php index 8c79b049ac4..6b9fbda71f2 100644 --- a/tests/database/Mvc/Model/Criteria/JoinCest.php +++ b/tests/database/Mvc/Model/Criteria/JoinCest.php @@ -94,7 +94,7 @@ public function mvcModelCriteriaJoinManyToManyMultipleSchema(DatabaseTester $I) $expected = 'SELECT `co_orders`.`ord_id`, `co_orders`.`ord_name` ' . 'FROM `co_orders` ' - . 'INNER JOIN `private`.`co_orders_x_products` ' + . 'INNER JOIN `public`.`co_orders_x_products` ' . 'ON `co_orders`.`ord_id` = `co_orders_x_products`.`oxp_ord_id` ' . 'INNER JOIN `co_products` ON `co_orders_x_products`.`oxp_prd_id` = `co_products`.`prd_id`'; $actual = $builder->getQuery()->getSql(); From ef7b79737412bda9306a65d7137ee729042a8418 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 20:09:28 +0000 Subject: [PATCH 10/24] #14862 - Review private/public schemas --- tests/_data/assets/schemas/mysql.sql | 4 ++-- tests/_data/fixtures/Migrations/OrdersProductsMigration.php | 6 +++--- tests/_envs/mysql.yml | 2 +- tests/database/Mvc/Model/Criteria/JoinCest.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/_data/assets/schemas/mysql.sql b/tests/_data/assets/schemas/mysql.sql index 936d1950dd2..5b701f1aeb5 100644 --- a/tests/_data/assets/schemas/mysql.sql +++ b/tests/_data/assets/schemas/mysql.sql @@ -65,9 +65,9 @@ CREATE TABLE `co_orders` ( -drop table if exists public.`co_orders_x_products`; +drop table if exists private.`co_orders_x_products`; -CREATE TABLE public.`co_orders_x_products` ( +CREATE TABLE private.`co_orders_x_products` ( `oxp_ord_id` int(10) unsigned NOT NULL, `oxp_prd_id` int(10) unsigned NOT NULL, `oxp_quantity` int(10) unsigned NOT NULL, diff --git a/tests/_data/fixtures/Migrations/OrdersProductsMigration.php b/tests/_data/fixtures/Migrations/OrdersProductsMigration.php index 5592525df6b..b3e6d0ceac4 100644 --- a/tests/_data/fixtures/Migrations/OrdersProductsMigration.php +++ b/tests/_data/fixtures/Migrations/OrdersProductsMigration.php @@ -71,10 +71,10 @@ protected function getSqlPgsql(): array { return [ " -drop table if exists private.co_orders_x_products; +drop table if exists public.co_orders_x_products; ", " -create table private.co_orders_x_products +create table public.co_orders_x_products ( oxp_ord_id int not null, oxp_prd_id int not null, @@ -82,7 +82,7 @@ protected function getSqlPgsql(): array ); ", " -alter table private.co_orders_x_products owner to postgres; +alter table public.co_orders_x_products owner to postgres; " ]; } diff --git a/tests/_envs/mysql.yml b/tests/_envs/mysql.yml index 3176890b6cb..fac9699a8d0 100644 --- a/tests/_envs/mysql.yml +++ b/tests/_envs/mysql.yml @@ -12,4 +12,4 @@ modules: waitlock: 10 initial_queries: - "SET NAMES utf8;" - - "CREATE SCHEMA IF NOT EXISTS public" + - "CREATE SCHEMA IF NOT EXISTS private" diff --git a/tests/database/Mvc/Model/Criteria/JoinCest.php b/tests/database/Mvc/Model/Criteria/JoinCest.php index 6b9fbda71f2..8c79b049ac4 100644 --- a/tests/database/Mvc/Model/Criteria/JoinCest.php +++ b/tests/database/Mvc/Model/Criteria/JoinCest.php @@ -94,7 +94,7 @@ public function mvcModelCriteriaJoinManyToManyMultipleSchema(DatabaseTester $I) $expected = 'SELECT `co_orders`.`ord_id`, `co_orders`.`ord_name` ' . 'FROM `co_orders` ' - . 'INNER JOIN `public`.`co_orders_x_products` ' + . 'INNER JOIN `private`.`co_orders_x_products` ' . 'ON `co_orders`.`ord_id` = `co_orders_x_products`.`oxp_ord_id` ' . 'INNER JOIN `co_products` ON `co_orders_x_products`.`oxp_prd_id` = `co_products`.`prd_id`'; $actual = $builder->getQuery()->getSql(); From 1ac8a3171ed9b2fc4618f8e6e82930c8ed11676a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 20:19:32 +0000 Subject: [PATCH 11/24] #14862 - Rename 'public' schema to 'private' --- tests/_data/fixtures/models/OrdersProducts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_data/fixtures/models/OrdersProducts.php b/tests/_data/fixtures/models/OrdersProducts.php index 2a15754093a..b13e6ecd13e 100644 --- a/tests/_data/fixtures/models/OrdersProducts.php +++ b/tests/_data/fixtures/models/OrdersProducts.php @@ -29,7 +29,7 @@ class OrdersProducts extends Model public function initialize() { - $this->setSchema('public'); + $this->setSchema('private'); $this->setSource('co_orders_x_products'); } } From ccdaf826cbd983df0cc3771edcfdd869994413b6 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 21:06:31 +0000 Subject: [PATCH 12/24] #14862 - Add IF EXISTS --- tests/_envs/pgsql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/_envs/pgsql.yml b/tests/_envs/pgsql.yml index 859c7018e9d..210f804a801 100644 --- a/tests/_envs/pgsql.yml +++ b/tests/_envs/pgsql.yml @@ -11,8 +11,8 @@ modules: reconnect: true waitlock: 10 initial_queries: - - 'DROP SCHEMA public CASCADE;' - - 'DROP SCHEMA private CASCADE;' + - 'DROP SCHEMA IF EXISTS public CASCADE;' + - 'DROP SCHEMA IF EXISTS private CASCADE;' - 'CREATE SCHEMA public;' - 'CREATE SCHEMA private;' - 'REVOKE ALL ON SCHEMA public FROM PUBLIC;' From b8681da6542de334812b9896e9dfcabb085b6763 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 21:06:52 +0000 Subject: [PATCH 13/24] #14862 - Clean debug code --- .github/workflows/build-and-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 2afa45b856b..f2ef2e25e38 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -254,9 +254,7 @@ jobs: 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: | - echo ${DATA_POSTGRES_SCHEMA} - vendor/bin/codecept run --ext DotReporter database --env pgsql -g pgsql + 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'] }} From f29776f96a4c799b8d4f4cbfdd7916420cbc43fb Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 21:22:23 +0000 Subject: [PATCH 14/24] #14862 - Add env variable DATA_POSTGRES_USER in Postgres tests --- .github/workflows/build-and-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f2ef2e25e38..d571b285861 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -251,6 +251,7 @@ jobs: - name: Run database tests Postgres env: + DATA_POSTGRES_USER: phalcon DATA_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }} DATA_REDIS_PORT: ${{ job.services.redis.ports['6379'] }} DATA_MEMCACHED_PORT: ${{ job.services.memcached.ports['11211'] }} From 89637daaab613dcf3e6557bea48de61fc1a3f131 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 21:46:37 +0000 Subject: [PATCH 15/24] #14862 - Set POSTGRES_USER to default 'postgres' --- .github/workflows/build-and-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d571b285861..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 @@ -251,7 +250,7 @@ jobs: - name: Run database tests Postgres env: - DATA_POSTGRES_USER: phalcon + 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'] }} From df71cf186d6bb4ed793f1e28d833e1bde3feecf9 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 22:05:33 +0000 Subject: [PATCH 16/24] #14862 - Fix postgresql driver name --- tests/_data/fixtures/Traits/DiTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_data/fixtures/Traits/DiTrait.php b/tests/_data/fixtures/Traits/DiTrait.php index 3e2112b7f34..56bd58d0d94 100644 --- a/tests/_data/fixtures/Traits/DiTrait.php +++ b/tests/_data/fixtures/Traits/DiTrait.php @@ -99,7 +99,7 @@ protected function newDbConnection(string $driver): AdapterInterface break; case 'pgsql': $options = getOptionsPostgresql(); - $service = 'postgresql'; + $driver = 'postgresql'; break; case 'sqlite': $options = getOptionsSqlite(); From f59d6cb1fa4a02378b595c44b0878e1cd43832b4 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 22:41:15 +0000 Subject: [PATCH 17/24] #14862 - Refactor method clear() by adding support of Postgres --- .../fixtures/Migrations/AbstractMigration.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/_data/fixtures/Migrations/AbstractMigration.php b/tests/_data/fixtures/Migrations/AbstractMigration.php index 27fc4f6719c..eab196399ad 100644 --- a/tests/_data/fixtures/Migrations/AbstractMigration.php +++ b/tests/_data/fixtures/Migrations/AbstractMigration.php @@ -69,14 +69,25 @@ 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 { + $schema = getenv('DATA_POSTGRES_SCHEMA'); + $exists = $this + ->connection + ->query("SELECT to_regclass('$schema.$this->table') AS exists;") + ->fetchColumn(); + if ($exists) { + $this->connection->exec( + 'truncate table ' . $this->table . ' cascade;' + ); + } } } } From f5d07a0a2fceca951d2b7eaa59d497ab547bce34 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 23:41:09 +0000 Subject: [PATCH 18/24] #14862 - Remove 'initial_queries' step --- tests/_envs/pgsql.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/_envs/pgsql.yml b/tests/_envs/pgsql.yml index 210f804a801..7e8b8f060c3 100644 --- a/tests/_envs/pgsql.yml +++ b/tests/_envs/pgsql.yml @@ -10,12 +10,3 @@ modules: cleanup: false reconnect: true waitlock: 10 - initial_queries: - - 'DROP SCHEMA IF EXISTS public CASCADE;' - - 'DROP SCHEMA IF EXISTS private CASCADE;' - - 'CREATE SCHEMA public;' - - 'CREATE SCHEMA private;' - - 'REVOKE ALL ON SCHEMA public FROM PUBLIC;' - - 'REVOKE ALL ON SCHEMA public FROM %DATA_POSTGRES_USER%;' - - 'GRANT ALL ON SCHEMA public TO %DATA_POSTGRES_USER%;' - - 'GRANT ALL ON SCHEMA public TO public;' From 6cceb591f2e467b0690d9c9c38375a05c751f74f Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 23:42:18 +0000 Subject: [PATCH 19/24] #14862 - Update CustomersMigration and InvoicesMigration postgres queries --- .../Migrations/CustomersMigration.php | 27 ++++++++++++++++++- .../fixtures/Migrations/InvoicesMigration.php | 3 --- 2 files changed, 26 insertions(+), 4 deletions(-) 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/_data/fixtures/Migrations/InvoicesMigration.php b/tests/_data/fixtures/Migrations/InvoicesMigration.php index d44d44f51f2..fa97a1c9d19 100644 --- a/tests/_data/fixtures/Migrations/InvoicesMigration.php +++ b/tests/_data/fixtures/Migrations/InvoicesMigration.php @@ -135,9 +135,6 @@ protected function getSqlPgsql(): array ); ", " -alter table co_invoices owner to postgres; - ", - " create index co_invoices_inv_created_at_index on co_invoices (inv_created_at); ", From 7976dcb28f72a3d4c6dfeb1c7281a1cdfc381e5e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 23:43:11 +0000 Subject: [PATCH 20/24] #14862 - Update tests for postgres group --- tests/database/Mvc/Model/CreateCest.php | 1 - tests/database/Mvc/Model/UpdateCest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/database/Mvc/Model/CreateCest.php b/tests/database/Mvc/Model/CreateCest.php index 671e855a93f..06dde790c17 100644 --- a/tests/database/Mvc/Model/CreateCest.php +++ b/tests/database/Mvc/Model/CreateCest.php @@ -56,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 23336bd056b..bee8df736be 100644 --- a/tests/database/Mvc/Model/UpdateCest.php +++ b/tests/database/Mvc/Model/UpdateCest.php @@ -56,7 +56,6 @@ public function mvcModelUpdate(DatabaseTester $I) $invoice = new Invoices(); $invoice->assign( [ - 'inv_id' => 123, 'inv_title' => $title, ] ); From 3bf94122642cdce47daa0a1aa586f82237a887d6 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 23:43:34 +0000 Subject: [PATCH 21/24] #14862 - Update schemas --- tests/_data/assets/schemas/mysql.sql | 50 +++++++++++------------ tests/_data/assets/schemas/pgsql.sql | 61 ++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 41 deletions(-) diff --git a/tests/_data/assets/schemas/mysql.sql b/tests/_data/assets/schemas/mysql.sql index 5b701f1aeb5..48e2e8d6b8e 100644 --- a/tests/_data/assets/schemas/mysql.sql +++ b/tests/_data/assets/schemas/mysql.sql @@ -1,7 +1,7 @@ drop table if exists `co_customers`; - + create table co_customers ( `cst_id` int(10) auto_increment primary key, @@ -9,20 +9,20 @@ create table co_customers `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` int(10) auto_increment primary key, @@ -32,90 +32,90 @@ create table co_invoices `inv_total` float(10, 2) null, `inv_created_at` datetime null ); - + 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`); - + create index co_invoices_inv_created_at_index on `co_invoices` (`inv_created_at`); - + drop table if exists objects; - + create table objects ( `obj_id` int(10) auto_increment primary key, `obj_name` varchar(100) not null, `obj_type` tinyint(3) unsigned not null ); - + drop table if exists `co_orders`; - + CREATE TABLE `co_orders` ( `ord_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ord_name` VARCHAR(70) NULL, PRIMARY KEY (`ord_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + drop table if exists private.`co_orders_x_products`; - + CREATE TABLE private.`co_orders_x_products` ( `oxp_ord_id` int(10) unsigned NOT NULL, `oxp_prd_id` int(10) unsigned NOT NULL, `oxp_quantity` int(10) unsigned NOT NULL, PRIMARY KEY (`oxp_ord_id`, `oxp_prd_id` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + drop table if exists `co_products`; - + CREATE TABLE `co_products` ( `prd_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `prd_name` VARCHAR(70) NULL, PRIMARY KEY (`prd_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - + drop table if exists `co_sources`; - + create table co_sources ( `id` int(10) auto_increment primary key, `username` varchar(100) null, `source` varchar(100) null ); - + create index co_sources_username_index on co_sources (username); - + drop table if exists `table_with_uuid_primary`; - + create table table_with_uuid_primary ( `uuid` char(36) not null primary key, `int_field` int null ); - + drop table if exists `stuff`; - + create table stuff ( `stf_id` int(10) auto_increment primary key, `stf_name` varchar(100) not null, `stf_type` tinyint(3) unsigned not null ); - + diff --git a/tests/_data/assets/schemas/pgsql.sql b/tests/_data/assets/schemas/pgsql.sql index 20d6cf3c54f..11805dc8e44 100644 --- a/tests/_data/assets/schemas/pgsql.sql +++ b/tests/_data/assets/schemas/pgsql.sql @@ -1,5 +1,28 @@ -drop table if exists co_invoices; + +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, @@ -9,23 +32,22 @@ create table co_invoices inv_total numeric(10, 2), inv_created_at timestamp ); - -alter table co_invoices owner to postgres; - + 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 @@ -33,26 +55,26 @@ create table co_orders primary key, ord_name varchar(70) ); - + alter table public.co_orders owner to postgres; - + 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 ); - + alter table public.co_orders_x_products owner to postgres; + - -drop table if exists co_products; - +drop table if exists co_products; + create table co_products ( prd_id serial not null @@ -60,5 +82,12 @@ create table co_products primary key, prd_name varchar(70) ); - + alter table public.co_products owner to postgres; + + + + + + + From 4015877191556e80ed06c83cc97e28741e841b0a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Tue, 25 Feb 2020 23:59:45 +0000 Subject: [PATCH 22/24] #14862 - Change value of 'inv_id' key --- tests/database/Mvc/Model/UpdateCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/database/Mvc/Model/UpdateCest.php b/tests/database/Mvc/Model/UpdateCest.php index bee8df736be..c5e1b40f8d6 100644 --- a/tests/database/Mvc/Model/UpdateCest.php +++ b/tests/database/Mvc/Model/UpdateCest.php @@ -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, From 6384c54d2c25f66819294026a0f99a407c87efc2 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 26 Feb 2020 20:45:46 +0000 Subject: [PATCH 23/24] #14862 - Remove condition if table exists --- .../_data/fixtures/Migrations/AbstractMigration.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/_data/fixtures/Migrations/AbstractMigration.php b/tests/_data/fixtures/Migrations/AbstractMigration.php index eab196399ad..9d87e0a6074 100644 --- a/tests/_data/fixtures/Migrations/AbstractMigration.php +++ b/tests/_data/fixtures/Migrations/AbstractMigration.php @@ -78,16 +78,9 @@ public function clear() 'delete from ' . $this->table . ';' ); } else { - $schema = getenv('DATA_POSTGRES_SCHEMA'); - $exists = $this - ->connection - ->query("SELECT to_regclass('$schema.$this->table') AS exists;") - ->fetchColumn(); - if ($exists) { - $this->connection->exec( - 'truncate table ' . $this->table . ' cascade;' - ); - } + $this->connection->exec( + 'truncate table ' . $this->table . ' cascade;' + ); } } } From 44af1b05812a8cfe7e0ba77ad1797ba57829aff3 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 26 Feb 2020 21:59:36 +0000 Subject: [PATCH 24/24] #14862 - Update changelog [ci skip] --- CHANGELOG-4.0.md | 1 + 1 file changed, 1 insertion(+) 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