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

#14862 - Swap condition if column allows null values in PostgreSQL #14876

Merged
merged 25 commits into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13acfaa
#14862 - Swap condition if column allows null values
Jeckerson Feb 25, 2020
104a767
#14862 - Enable CI step to run database tests with Postgres
Jeckerson Feb 25, 2020
ec9b51a
#14862 - Add 'pgsql' group for some tests
Jeckerson Feb 25, 2020
375bf79
#14862 - Rename 'private' schema to 'public'
Jeckerson Feb 25, 2020
7113119
#14862 - Add debug info of env variable
Jeckerson Feb 25, 2020
e35f9eb
#14862 - Rename 'private' schema to 'public'
Jeckerson Feb 25, 2020
ae3b985
#14862 - Rename 'private' schema to 'public'
Jeckerson Feb 25, 2020
73b88a6
#14862 - Rename 'private' schema to 'public'
Jeckerson Feb 25, 2020
054d1f6
#14862 - Rename 'private' schema to 'public'
Jeckerson Feb 25, 2020
ef7b797
#14862 - Review private/public schemas
Jeckerson Feb 25, 2020
1ac8a31
#14862 - Rename 'public' schema to 'private'
Jeckerson Feb 25, 2020
ccdaf82
#14862 - Add IF EXISTS
Jeckerson Feb 25, 2020
b8681da
#14862 - Clean debug code
Jeckerson Feb 25, 2020
f29776f
#14862 - Add env variable DATA_POSTGRES_USER in Postgres tests
Jeckerson Feb 25, 2020
89637da
#14862 - Set POSTGRES_USER to default 'postgres'
Jeckerson Feb 25, 2020
df71cf1
#14862 - Fix postgresql driver name
Jeckerson Feb 25, 2020
f59d6cb
#14862 - Refactor method clear() by adding support of Postgres
Jeckerson Feb 25, 2020
f5d07a0
#14862 - Remove 'initial_queries' step
Jeckerson Feb 25, 2020
6cceb59
#14862 - Update CustomersMigration and InvoicesMigration postgres que…
Jeckerson Feb 25, 2020
7976dcb
#14862 - Update tests for postgres group
Jeckerson Feb 25, 2020
3bf9412
#14862 - Update schemas
Jeckerson Feb 25, 2020
4015877
#14862 - Change value of 'inv_id' key
Jeckerson Feb 25, 2020
a4b3b63
Merge branch '4.0.x' into fix/#14862-pgsql-null-columns
Jeckerson Feb 26, 2020
6384c54
#14862 - Remove condition if table exists
Jeckerson Feb 26, 2020
44af1b0
#14862 - Update changelog [ci skip]
Jeckerson Feb 26, 2020
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
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