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

Add refreshMaterializedView command #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gerych1984
Copy link

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

Add new command to refresh PgSql materialized views. I think it can be added in CommandInterface

@Gerych1984 Gerych1984 force-pushed the refresh-mat-view branch 2 times, most recently from aaff285 to 08b86eb Compare January 19, 2024 14:14
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (02a2a87) 100.00% compared to head (f07182c) 99.85%.
Report is 2 commits behind head on master.

Files Patch % Lines
src/Command.php 95.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              master     #332      +/-   ##
=============================================
- Coverage     100.00%   99.85%   -0.15%     
- Complexity       241      252      +11     
=============================================
  Files             16       16              
  Lines            694      714      +20     
=============================================
+ Hits             694      713      +19     
- Misses             0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -20,4 +24,56 @@ public function showDatabases(): array

return $this->setSql($sql)->queryColumn();
}

/**
* @see {https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html}
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
* @see {https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html}
* @see https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html

$tableSchema = $this->db->getTableSchema($viewName);

if ($tableSchema) {
$hasUnique = count($this->db->getSchema()->findUniqueIndexes($tableSchema)) > 0;
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
$hasUnique = count($this->db->getSchema()->findUniqueIndexes($tableSchema)) > 0;
$hasUnique = !empty($this->db->getSchema()->findUniqueIndexes($tableSchema));

*/
public function refreshMaterializedView(string $viewName, ?bool $concurrently = null, ?bool $withData = null): bool
{
if ($concurrently || ($concurrently === null || $withData === null)) {
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
if ($concurrently || ($concurrently === null || $withData === null)) {
if ($concurrently !== false) {

);
}

if ($concurrently && !$hasUnique) {
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
if ($concurrently && !$hasUnique) {
if ($concurrently === true && !$hasUnique) {

@vjik vjik requested review from darkdef and Tigrov January 20, 2024 11:40
@vjik vjik added the status:code review The pull request needs review. label Jan 20, 2024
Copy link
Member

@Tigrov Tigrov left a comment

Choose a reason for hiding this comment

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

Good idea.

  • This method should be added in base yii-db package and should be consistent with other DBMS.

  • The part of generating SQL query shold be in DDLQueryBuilder

@Gerych1984
Copy link
Author

God idea.

  • This method should be added in base yii-db package and should be consistent with other DBMS.
  • The part of generating SQL query shold be in DDLQueryBuilder

I create this PR and i think they must be merged first

@Tigrov Tigrov added status:under development Someone is working on a pull request. and removed status:code review The pull request needs review. labels Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants