Skip to content

Commit

Permalink
Merge pull request #14876 from phalcon/fix/#14862-pgsql-null-columns
Browse files Browse the repository at this point in the history
#14862 - Swap condition if column allows null values in PostgreSQL
  • Loading branch information
Jeckerson authored Feb 27, 2020
2 parents 2ce20b7 + 44af1b0 commit d15ae7a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 31 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ jobs:
- 5432
env:
POSTGRES_PASSWORD: secret
POSTGRES_USER: phalcon
POSTGRES_DB: phalcon
redis:
image: redis:5-alpine
Expand Down Expand Up @@ -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'] }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Db/Adapter/Pdo/Postgresql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
49 changes: 34 additions & 15 deletions tests/_data/assets/schemas/pgsql.sql
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,53 +32,53 @@ 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
constraint ord_pk
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
constraint prd_pk
primary key,
prd_name varchar(70)
);




Expand Down
8 changes: 6 additions & 2 deletions tests/_data/fixtures/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;'
);
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion tests/_data/fixtures/Migrations/CustomersMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/database/Mvc/Model/CreateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function _before(DatabaseTester $I)
*
* @group mysql
* @group sqlite
* @group pgsql
*/
public function mvcModelCreate(DatabaseTester $I)
{
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/database/Mvc/Model/UpdateCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function _before(DatabaseTester $I)
*
* @group mysql
* @group sqlite
* @group pgsql
*/
public function mvcModelUpdate(DatabaseTester $I)
{
Expand All @@ -55,7 +56,6 @@ public function mvcModelUpdate(DatabaseTester $I)
$invoice = new Invoices();
$invoice->assign(
[
'inv_id' => 123,
'inv_title' => $title,
]
);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d15ae7a

Please sign in to comment.