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

fix: PostgreSQL getVersion() logic #7488

Merged

Conversation

marekmosna
Copy link
Contributor

@marekmosna marekmosna commented May 9, 2023

Description
Fixes #7484

Fixies logic of PostgreSQL getVersion() method.

Copy link
Collaborator

@ddevsr ddevsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove below code in phpstan-baseline.neon.dist

-
			message: "#^Strict comparison using \\=\\=\\= between array<string, int|string|null> and false will always evaluate to false\\.$#"
			count: 1
			path: system/Database/Postgre/Connection.php

@ddevsr
Copy link
Collaborator

ddevsr commented May 10, 2023

By the way,

Following step how to create PR in https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#php-style

Dont forget signing your commit
https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#gpg-signing-old-commits

@ddevsr ddevsr added the bug Verified issues on the current code behavior or pull requests that will fix them label May 10, 2023
@marekmosna marekmosna force-pushed the 7484-postgresql-server-version branch 2 times, most recently from 7ee8775 to 8064aab Compare May 11, 2023 16:44
@michalsn
Copy link
Member

@marekmosna Almost there! Could you follow the suggestion from #7488 (review) to fix the PHPStan error?

@kenjis kenjis added the database Issues or pull requests that affect the database layer label May 12, 2023
@kenjis kenjis changed the title Fixes 7484: PostgreSQL getVersion() logic fix: PostgreSQL getVersion() logic May 12, 2023
$this->initialize();
}

$pgVersion = pg_version($this->connID);

return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface is public function getVersion(): string;. So false should not be returned.

@marekmosna marekmosna force-pushed the 7484-postgresql-server-version branch from 98362e6 to efbf68c Compare May 12, 2023 18:06
@kenjis kenjis added the tests needed Pull requests that need tests label May 12, 2023
@marekmosna marekmosna force-pushed the 7484-postgresql-server-version branch from efbf68c to 3292e43 Compare May 13, 2023 11:05
$this->initialize();
}

return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false;
$pgVersion = pg_version($this->connID);
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVersion() returns the version number like '12.1', and the number should be used with version_compare()

Is it impossible to get the version number 7.4 or lower?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pg_version() returns an array with the client, protocol and server version. Protocol and server versions are only available if PHP was compiled with PostgreSQL 7.4 or later.
https://www.php.net/manual/en/function.pg-version.php#refsect1-function.pg-version-description

There is no version requirement in the docs:
https://codeigniter4.github.io/CodeIgniter4/intro/requirements.html#supported-databases

But PostgreSQL 11 will stop receiving fixes on November 9, 2023.
https://www.postgresql.org/about/news/postgresql-153-148-1311-1215-and-1120-released-2637/

@codeigniter4/core-team @codeigniter4/database-team
Do we need to support versions prior to 7.4?
Why don't we add (version 7.4 and above only) in the docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostgreSQL 7.4 seems too old, it seems it need to be documented in docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getVersion() returns the version number like '12.1', and the number should be used with version_compare()

that was the question in the related issue #7488

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no $pgVersion['server'], we should return an empty string.

Adding a note (version 7.4 and above only) is a good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sent a PR: #7507

$this->initialize();
}

return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false;
$pgVersion = pg_version($this->connID);
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower';
$this->dataCache['version'] = $pgVersion['server'] ?? '';

@kenjis
Copy link
Member

kenjis commented May 18, 2023

@marekmosna It seems there is no test code for getVersion().
If you can write test code, add test code.
We would appreciate it.

@marekmosna marekmosna force-pushed the 7484-postgresql-server-version branch from 3292e43 to 4c6e4ec Compare May 20, 2023 07:13
@marekmosna
Copy link
Contributor Author

@marekmosna It seems there is no test code for getVersion(). If you can write test code, add test code. We would appreciate it.

I'm sorry @kenjis but I'm not a php developer so I can't

@kenjis
Copy link
Member

kenjis commented May 20, 2023

@marekmosna Okay, I got it.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kenjis kenjis merged commit d334a2a into codeigniter4:develop May 21, 2023
51 checks passed
@kenjis kenjis mentioned this pull request May 21, 2023
4 tasks
@kenjis
Copy link
Member

kenjis commented May 21, 2023

@codeigniter4/database-team
It seems PostgreSQL may return the version like '15.3 (Debian 15.3-1.pgdg110+1)'.
https://github.com/codeigniter4/CodeIgniter4/actions/runs/5035338925/jobs/9030854318

Is this okay?

@michalsn
Copy link
Member

Good point. I think we should filter out the version.

$this->initialize();
}

return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false;
$pgVersion = pg_version($this->connID);
$this->dataCache['version'] = $pgVersion['server'] ?? '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->dataCache['version'] = $pgVersion['server'] ?? '';
$this->dataCache['version'] = isset($pgVersion['server']) ?
preg_match('/^(\d+\.\d+)/', $pgVersion['server'], $matches) ? $matches[1] : '' :
'';

This should work if we deal with something like 15.3 (Debian 15.3-1.pgdg110+1) - as Kenjis pointed out earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will take care of it in #7509

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer tests needed Pull requests that need tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: PosgreSQL server version
5 participants