Skip to content

[OSDEV-1515] Database. Upgrade the PostgreSQL version to 16.#490

Merged
vladsha-dev merged 11 commits intomainfrom
OSDEV-1515-database-upgrade-the-postgresql-version-to-17
Jan 29, 2025
Merged

[OSDEV-1515] Database. Upgrade the PostgreSQL version to 16.#490
vladsha-dev merged 11 commits intomainfrom
OSDEV-1515-database-upgrade-the-postgresql-version-to-17

Conversation

@vladsha-dev
Copy link
Contributor

@vladsha-dev vladsha-dev commented Jan 24, 2025

[OSDEV-1515] Upgraded PostgreSQL version to 16.

  • Upgraded the PostgreSQL version from 13 to 16 for the database used in local development, DB anonymization, DB restore setup, and environments in the AWS cloud. Additionally, the pg_trgm extension has been upgraded to version 1.6 based on the available extension version for PostgreSQL 16.3 in AWS RDS.
  • 0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py - Updated the SQL script within the migration that upgrades the DB extension versions to handle previously failure cases when a higher version is available for upgrade or when the extension is not installed. This is primarily useful for local development or DB resets in the Development environment, where migrations are applied from scratch, one by one. This fix will not negatively affect other environments, as the migration has already been applied and will not be reapplied. Additionally, the changes are backward compatible.
  • 0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py - Created the migration that refreshes the pg_statistic table after the upgrade to PostgreSQL 16 and upgrades the pg_trgm extension to version 1.6. The SQL script within the migration that upgrades the DB extension versions handles previously failure cases where a higher version is available for upgrade or where the extension is not installed.

@vladsha-dev vladsha-dev self-assigned this Jan 24, 2025
@vladsha-dev vladsha-dev marked this pull request as draft January 24, 2025 17:36
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:36 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:38 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Jan 24, 2025

React App | Jest test suite - Code coverage report

Total: 28.37%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:42 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Jan 24, 2025

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:43 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:43 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Jan 24, 2025

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented Jan 24, 2025

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 24, 2025 17:53 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Jan 24, 2025

Django App | Unittest test suite - Code coverage report

Total: 80.38%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 27, 2025 16:57 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 27, 2025 16:57 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment January 28, 2025 10:53 — with GitHub Actions Inactive
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2025

📝 Walkthrough

Walkthrough

This pull request involves a comprehensive upgrade of PostgreSQL from version 13 to version 16 across multiple environments and components. The changes span Terraform configuration files, Dockerfiles, migration scripts, and SQL scripts. The upgrade affects development, pre-production, production, staging, and test environments, ensuring consistent database engine versioning. The modifications include updating RDS engine versions, parameter group families, base images, and adding migration scripts to handle the version transition smoothly.

Changes

File/Path Change Summary
deployment/environments/*.tfvars Updated rds_engine_version from "13" to "16" and rds_parameter_group_family from "postgres13" to "postgres16" in development, preprod, production, staging, and test environments.
deployment/terraform/database.tf Updated module source reference from version 3.1.0 to 3.2.0.
deployment/terraform/variables.tf Modified default values for rds_engine_version and rds_parameter_group_family.
**/Dockerfile* Updated base images from PostGIS 13-3.4-alpine to 16-3.4-alpine in multiple Dockerfiles.
src/database/Dockerfile.local Updated base image from PostgreSQL 13 to 16 and corresponding development package.
src/django/Dockerfile Changed base image to Python 3.7-slim-bookworm and PostgreSQL client version.
src/django/api/migrations/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py Added new migration script for PostgreSQL extension handling.
src/django/api/migrations/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py Added new migration script for refreshing statistics and upgrading extensions post-upgrade.
src/django/sqls/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.sql Enhanced SQL script for managing PostgreSQL extension upgrades with procedural logic.
src/django/sqls/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.sql Introduced SQL script for analyzing and upgrading the pg_trgm extension.

Sequence Diagram

sequenceDiagram
    participant DB as PostgreSQL Database
    participant Migrator as Database Migrator
    participant Extensions as PostgreSQL Extensions

    DB->>Migrator: Initiate Version Upgrade
    Migrator->>Extensions: Check Current Versions
    Extensions-->>Migrator: Return Current Versions
    Migrator->>Extensions: Upgrade pg_trgm to 1.6
    Migrator->>DB: Refresh pg_statistic
    Migrator->>DB: Analyze Database
Loading

Possibly related PRs

Suggested reviewers

  • Innavin369
  • roman-stolar
  • VadimKovalenkoSNF
  • mazursasha1990

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e217ce4 and 07df03a.

📒 Files selected for processing (1)
  • doc/release/RELEASE-NOTES.md (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


42-42: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


43-43: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


44-44: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-contricleaner-cov
🔇 Additional comments (1)
doc/release/RELEASE-NOTES.md (1)

41-44: 🛠️ Refactor suggestion

Improve clarity of release instructions for the PostgreSQL upgrade.

The current format makes it difficult to understand the sequence of operations. Consider restructuring the instructions into a clearer format with explicit steps and dependencies.

Apply this diff to improve readability:

-* This release will upgrade PostgreSQL from version 13 to version 16.
-    * The upgrade will be performed automatically by Terrafrom and AWS, but some steps need to be completed **before** and **after** the upgrade. Please refer to [the Confluence article](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16) for detailed instructions.
-    * Steps to be completed before the upgrade are marked with the statement: "**This should be done before deploying the upgraded database.**". Post-upgrade tasks can be found under the [After the PostgreSQL major version upgrade](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16#After-the-PostgreSQL-major-version-upgrade) section.
-    * In case of an unsuccessful release along with the database upgrade, follow the instructions under the [Guide for rolling back the PostgreSQL major version upgrade](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16#Guide-for-rolling-back-the-PostgreSQL-major-version-upgrade) section.
+### PostgreSQL Upgrade Instructions (13 to 16)
+
+#### Pre-Upgrade Steps
+1. Review and complete all tasks marked as "**This should be done before deploying the upgraded database.**" in the [PostgreSQL Upgrade Guide](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16).
+
+#### Upgrade Process
+1. The PostgreSQL upgrade from 13 to 16 will be performed automatically by Terraform and AWS.
+2. Monitor the upgrade process for any errors or warnings.
+
+#### Post-Upgrade Steps
+1. Complete all tasks listed under [After the PostgreSQL major version upgrade](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16#After-the-PostgreSQL-major-version-upgrade).
+
+#### Rollback Instructions
+If the upgrade fails, follow the [Guide for rolling back the PostgreSQL major version upgrade](https://opensupplyhub.atlassian.net/wiki/spaces/SD/pages/640155649/PostgreSQL+database+upgrade+from+version+13+to+version+16#Guide-for-rolling-back-the-PostgreSQL-major-version-upgrade).

Likely invalid or redundant comment.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

42-42: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


43-43: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


44-44: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
deployment/environments/terraform-preprod.tfvars (1)

Line range hint 21-22: Consider enabling Multi-AZ deployment for high availability during upgrade.

The rds_multi_az = false setting could impact availability during the major version upgrade.

Consider enabling Multi-AZ deployment to minimize downtime:

-rds_multi_az = false
+rds_multi_az = true
src/django/sqls/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.sql (1)

3-30: Consider adding database version logging for better traceability.

The extension upgrade logic is robust, but it would be helpful to log the current PostgreSQL version for debugging purposes.

Add version logging at the beginning of the script:

 ANALYZE VERBOSE;
+
+DO $$
+BEGIN
+  RAISE NOTICE 'Current PostgreSQL version: %', current_setting('server_version');
+END $$;
 
 DO $$
 DECLARE
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbd9037 and 9ebefe3.

📒 Files selected for processing (17)
  • deployment/environments/terraform-development.tfvars (1 hunks)
  • deployment/environments/terraform-preprod.tfvars (1 hunks)
  • deployment/environments/terraform-production.tfvars (1 hunks)
  • deployment/environments/terraform-staging.tfvars (1 hunks)
  • deployment/environments/terraform-test.tfvars (1 hunks)
  • deployment/terraform/anonymized_database_dump_scheduled_task/docker/Dockerfile (1 hunks)
  • deployment/terraform/database.tf (1 hunks)
  • deployment/terraform/variables.tf (1 hunks)
  • doc/release/RELEASE-NOTES.md (2 hunks)
  • src/anon-tools/Dockerfile.dump (1 hunks)
  • src/anon-tools/Dockerfile.restore (1 hunks)
  • src/database/Dockerfile.local (2 hunks)
  • src/django/Dockerfile (2 hunks)
  • src/django/api/migrations/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py (1 hunks)
  • src/django/api/migrations/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py (1 hunks)
  • src/django/sqls/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.sql (1 hunks)
  • src/django/sqls/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.sql (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • src/anon-tools/Dockerfile.dump
  • src/django/api/migrations/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py
  • deployment/terraform/database.tf
  • src/anon-tools/Dockerfile.restore
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


42-42: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


43-43: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


44-44: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-django-cov
🔇 Additional comments (18)
deployment/environments/terraform-staging.tfvars (1)

15-16: LGTM! Proper configuration for major version upgrade.

The configuration includes all necessary flags and settings for a safe PostgreSQL upgrade.

Also applies to: 23-24

deployment/environments/terraform-development.tfvars (1)

17-18: LGTM! Development environment properly configured.

The configuration includes all necessary flags and appropriate instance type for development.

Also applies to: 24-25

deployment/environments/terraform-production.tfvars (1)

Line range hint 16-24: Verify PostgreSQL 16 upgrade prerequisites.

Ensure all prerequisites for PostgreSQL 16 upgrade are met:

  1. Check for any incompatible extensions
  2. Verify application compatibility with PostgreSQL 16
  3. Test the upgrade process in lower environments first

Run this script to check for potential compatibility issues:

✅ Verification successful

PostgreSQL 16 upgrade prerequisites verified successfully

The codebase shows proper preparation for PostgreSQL 16:

  • Django 3.2 LTS is compatible with PostgreSQL 16
  • Migration files handle PostGIS and pg_trgm extension upgrades
  • Database adapter (psycopg2 2.9.4) supports PostgreSQL 16
  • No incompatible syntax or features detected
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for PostgreSQL version compatibility issues

# Check for installed extensions and their versions
rg -A 5 "CREATE EXTENSION|ALTER EXTENSION" 

# Look for potential PostgreSQL version-specific syntax
rg -g '*.sql' -g '*.py' '\b(?:IS NOT DISTINCT FROM|IS DISTINCT FROM|jsonb_path_query|jsonb_path_exists)\b'

# Check for custom PostgreSQL functions that might need updates
ast-grep --pattern 'CREATE [OR REPLACE] FUNCTION'

Length of output: 3350


Script:

#!/bin/bash
# Check Django version and its PostgreSQL 16 compatibility
rg -g 'requirements*.txt' -g 'setup.py' -g 'pyproject.toml' "Django==" -A 1

Length of output: 71


Script:

#!/bin/bash
# Try broader search patterns for requirements and DB config
echo "=== Checking requirements files ==="
fd requirements.txt
cat $(fd requirements.txt)

echo -e "\n=== Checking database settings ==="
rg -g '*.py' "DATABASES" -A 5

Length of output: 2585

deployment/environments/terraform-test.tfvars (1)

17-18: LGTM! Version upgrade configuration looks correct.

The RDS engine version and parameter group family are properly updated to PostgreSQL 16. The configuration includes rds_allow_major_version_upgrade = true which is required for this upgrade.

src/django/api/migrations/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py (2)

10-15: LGTM! Migration function is well structured.

The function correctly uses the helper to execute the SQL file for refreshing statistics and upgrading extensions.


18-43: Excellent documentation of the migration purpose and context.

The docstring provides comprehensive information about:

  • The need to refresh statistics after major version upgrade
  • Current extensions in use
  • Version compatibility with AWS RDS
deployment/terraform/anonymized_database_dump_scheduled_task/docker/Dockerfile (1)

1-1: LGTM! PostGIS base image version aligns with PostgreSQL upgrade.

The base image is correctly updated to PostgreSQL 16 while maintaining the same PostGIS version (3.4) for compatibility.

src/django/sqls/0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.sql (2)

1-2: LGTM! Database statistics refresh is properly implemented.

The ANALYZE VERBOSE command will rebuild statistics crucial for query optimization after the major version upgrade.


20-29: Verify pg_trgm version compatibility across environments.

While version 1.6 is specified as compatible with PostgreSQL 16.3 in AWS RDS, ensure this version is available in all environments.

src/django/Dockerfile (1)

1-1: Verify PostgreSQL client compatibility with PostgreSQL 16.

The PostgreSQL client version 15 should be verified for compatibility with PostgreSQL 16 server. While PostgreSQL generally maintains backward compatibility for clients, it's good practice to confirm there are no known issues.

Also applies to: 15-15

src/database/Dockerfile.local (2)

1-8: LGTM! Clear documentation of version constraints.

The comments effectively explain why only the major version 16 is specified in the Docker image, despite using 16.3 in AWS RDS.


32-32: LGTM! Development package version aligned.

The PostgreSQL server development package version is correctly aligned with the base image version.

src/django/sqls/0163_refresh_pg_statistic_and_upgrade_postgres_extensions.sql (3)

3-13: LGTM! Well-structured version management.

The script properly declares and initializes version variables for both extensions, making it maintainable for future version updates.


24-32: LGTM! Robust error handling for postgis extension.

The script includes proper error handling with informative messages:

  • Checks if extension is installed
  • Verifies version before upgrade
  • Provides status notifications

44-53: LGTM! Consistent error handling for pg_trgm extension.

The error handling pattern is consistently applied to the pg_trgm extension, maintaining code quality.

deployment/terraform/variables.tf (1)

73-73: LGTM! PostgreSQL version configuration updated.

The RDS engine version and parameter group family are correctly updated to PostgreSQL 16.

Also applies to: 77-77

doc/release/RELEASE-NOTES.md (2)

13-17: LGTM! Clear documentation of database changes.

The release notes effectively document the PostgreSQL upgrade and extension updates, with proper references to AWS documentation.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


41-44: LGTM! Comprehensive release instructions.

The release instructions are thorough, including:

  • Pre and post-upgrade steps
  • Links to detailed instructions
  • Rollback procedures
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

42-42: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


43-43: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


44-44: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

Copy link
Contributor

@roninzp roninzp 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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
doc/release/RELEASE-NOTES.md (2)

13-14: Enhance the PostgreSQL upgrade documentation.

The description could be more specific about the upgrade process and its impact. Consider adding:

  • The exact PostgreSQL versions (13.x to 16.x)
  • Any downtime expectations during the upgrade
  • Impact on existing extensions and configurations
* [OSDEV-1515](https://opensupplyhub.atlassian.net/browse/OSDEV-1515) - Upgraded the PostgreSQL version from 13 to 16 for the database used in local development, DB anonymization, DB restore setup, and environments in the AWS cloud. Additionally, the pg_trgm extension has been upgraded to version 1.6 based on the available extension version for PostgreSQL 16.3 in AWS RDS. For more information, see [Extensions supported for RDS for PostgreSQL 16](https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-extensions.html#postgresql-extensions-16x).
+* [OSDEV-1515](https://opensupplyhub.atlassian.net/browse/OSDEV-1515) - Upgraded the PostgreSQL version from 13.x to 16.3 for the database used in local development, DB anonymization, DB restore setup, and environments in the AWS cloud. This upgrade requires a maintenance window and may result in brief downtime. The pg_trgm extension has been upgraded to version 1.6 to maintain compatibility with PostgreSQL 16.3 in AWS RDS. All existing extensions and configurations have been validated for compatibility. For more information, see [Extensions supported for RDS for PostgreSQL 16](https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-extensions.html#postgresql-extensions-16x).

16-17: Enhance migration script descriptions.

The migration script descriptions could be more detailed about their purpose and impact.

-* 0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py - Updated the SQL script within the migration that upgrades the DB extension versions to handle previously failure cases when a higher version is available for upgrade or when the extension is not installed. This is primarily useful for local development or DB resets in the Development environment, where migrations are applied from scratch, one by one. This fix will not negatively affect other environments, as the migration has already been applied and will not be reapplied. Additionally, the changes are backward compatible.
-* 0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py - This migration refreshes the `pg_statistic` table after the upgrade to PostgreSQL 16 and upgrades the pg_trgm extension to version 1.6. The SQL script within the migration that upgrades the DB extension versions handles previously failure cases where a higher version is available for upgrade or where the extension is not installed.
+* 0163_refresh_pg_statistic_and_upgrade_postgres_extensions.py
+  - Purpose: Handles extension version upgrades and installations
+  - Key Changes:
+    * Implements robust error handling for extension upgrades
+    * Handles cases where extensions are not installed
+    * Ensures backward compatibility with existing data
+  - Impact: Safe to run in all environments as it's idempotent
+
+* 0164_refresh_pg_statistic_and_upgrade_postgres_extensions_after_db_upgrade_to_postgres_16.py
+  - Purpose: Post-PostgreSQL 16 upgrade maintenance
+  - Key Changes:
+    * Refreshes pg_statistic table to ensure query optimizer has current statistics
+    * Upgrades pg_trgm extension to version 1.6
+    * Implements same robust error handling as 0163
+  - Execution: Must be run after PostgreSQL 16 upgrade is complete
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ebefe3 and 6744638.

📒 Files selected for processing (1)
  • doc/release/RELEASE-NOTES.md (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
doc/release/RELEASE-NOTES.md

15-15: Trailing punctuation in heading
Punctuation: ':'

(MD026, no-trailing-punctuation)


42-42: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


43-43: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)


44-44: Unordered list indentation
Expected: 2; Actual: 4

(MD007, ul-indent)

⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: run-fe-code-quality

@sonarqubecloud
Copy link

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants