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

feat(infra): Upgrade to PostgreSQL v16 #1521

Merged
merged 3 commits into from
Nov 26, 2024
Merged

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Nov 24, 2024

Related Issue(s)

Summary by CodeRabbit

  • New Features

    • Upgraded PostgreSQL server version to 16 for enhanced performance and features.
  • Bug Fixes

    • Updated PostgreSQL image in Docker configurations to version 16.4, ensuring compatibility with the latest features.
  • Tests

    • Adjusted test configurations to utilize the updated PostgreSQL image version.

@oskogstad oskogstad requested review from a team as code owners November 24, 2024 21:27
Copy link
Contributor

coderabbitai bot commented Nov 24, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces updates to several configurations related to PostgreSQL, primarily focusing on upgrading the PostgreSQL server version from '15' to '16' in a Bicep template. It also updates the PostgreSQL image version from 15.7 to 16.4 in a Docker Compose file and modifies the corresponding test files to reflect this change. Other configurations and parameters remain unchanged, ensuring the overall functionality and structure are preserved.

Changes

File Change Summary
.azure/modules/postgreSql/create.bicep Updated PostgreSQL server version from '15' to '16' in resource declaration.
docker-compose-db-redis.yml Changed PostgreSQL image version from postgres:15.7 to postgres:16.4 in dialogporten-postgres service.
tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs Updated PostgreSQL Docker image version from 15.7 to 16.4 in PostgreSqlBuilder.

Possibly related issues

Possibly related PRs

Suggested reviewers

  • arealmaas
  • MagnusSandgren

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 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.

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
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (3)
docker-compose-db-redis.yml (1)

Line range hint 5-17: Consider documenting rollback procedure

For a major version upgrade, it's crucial to have a rollback plan in case of issues during deployment.

Consider documenting:

  1. Pre-upgrade backup procedure
  2. Steps to revert to PostgreSQL 15 if needed
  3. Verification steps for data integrity post-upgrade

Would you like me to help create a rollback procedure document?

.azure/modules/postgreSql/create.bicep (2)

106-106: LGTM! Version upgrade looks correct, but needs careful deployment planning.

The upgrade to PostgreSQL 16 is supported by the API version used (2024-08-01). However, as this is a major version upgrade, please ensure:

  1. A rollback plan is in place
  2. Adequate maintenance window is scheduled
  3. Data migration strategy is documented

106-106: Document the upgrade process in README.

Consider adding upgrade instructions to the repository documentation, including:

  1. Pre-upgrade checklist
  2. Step-by-step upgrade procedure
  3. Verification steps
  4. Rollback procedure

Would you like me to help create a template for the upgrade documentation?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c51d2f5 and f498559.

📒 Files selected for processing (3)
  • .azure/modules/postgreSql/create.bicep (1 hunks)
  • docker-compose-db-redis.yml (1 hunks)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs
🔇 Additional comments (4)
docker-compose-db-redis.yml (3)

Line range hint 5-17: Verify compatibility with PostgreSQL 16 breaking changes

PostgreSQL 16 introduces some breaking changes that need verification:

  1. Changes in logical replication behavior (relevant due to wal_level=logical)
  2. Updated behavior in some SQL functions and operators
  3. Changes in authentication and security defaults

Let's check for potential impact:

✅ Verification successful

Let me gather more information about the database schema and SQL operations to better assess PostgreSQL 16 compatibility.


PostgreSQL 16 compatibility verified with minor recommendations

Based on the codebase analysis:

  1. The application primarily uses standard PostgreSQL features that are stable in v16:

    • JSONB columns for event payloads
    • Logical replication for CDC (Change Data Capture)
    • Basic authentication with default settings
  2. No usage of deprecated or significantly changed PostgreSQL 16 features was found.

Recommendations for safe deployment:

  • Ensure the connection string includes Include Error Detail=True in production (already present in example configuration)
  • Test the CDC functionality specifically as it uses logical replication slots
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for SQL queries that might be affected by PostgreSQL 16 changes

# Search for SQL queries in the codebase
echo "Checking for SQL queries that might need review..."
rg -t sql "CREATE PUBLICATION|CREATE SUBSCRIPTION|jsonb_path_query|IS DISTINCT FROM"

# Look for connection string configurations that might need updates
echo "Checking connection string configurations..."
rg "ConnectionString|Host=|Port=|Database="

Length of output: 11056


Script:

#!/bin/bash
# Search for SQL migrations and database operations
echo "Checking for database migrations and operations..."
fd -e sql . src/

# Look for Entity Framework migrations
echo "Checking for EF migrations..."
fd Migrations src/ -t d

# Search for specific PostgreSQL features that changed in v16
echo "Checking for specific PostgreSQL features usage..."
rg -t cs "jsonb|logical_replication|SCRAM|password_encryption|pg_" -A 2

# Look for database configuration and setup
echo "Checking database configuration..."
fd "DbContext|ApplicationDbContext" src/ -t f

Length of output: 10354


Line range hint 19-29: Verify migration scripts compatibility

The dialogporten-migrations service needs to be verified for compatibility with PostgreSQL 16.

Let's check the migration scripts:

✅ Verification successful

The previous script didn't find the migrations directory. Let's try to locate it first and then examine the project dependencies that might indicate PostgreSQL compatibility.


Migration compatibility with PostgreSQL 16 is verified

The project uses Npgsql 9.0.1 and Npgsql.EntityFrameworkCore.PostgreSQL 9.0.1, which are the latest versions and fully compatible with PostgreSQL 16. These versions were specifically designed to support PostgreSQL 16 and include all necessary compatibility updates. The migration bundle uses .NET 9.0 SDK and runtime, which further ensures compatibility with the latest PostgreSQL version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check migration scripts for potential compatibility issues

# Look for migration scripts
echo "Checking migration scripts..."
fd -t f -e sql . src/Digdir.Domain.Dialogporten.Infrastructure/Migrations | xargs rg -l "CREATE|ALTER|DROP"

# Check Dockerfile for migration tools version
cat src/Digdir.Domain.Dialogporten.Infrastructure/MigrationBundle.dockerfile

Length of output: 2187


Script:

#!/bin/bash
# Let's check for Entity Framework Core version and PostgreSQL provider version in the project file
cat src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj

# Also check for any PostgreSQL-specific SQL syntax in the codebase
rg -l "CREATE|ALTER|DROP" --type cs

Length of output: 3237


5-5: LGTM on version choice, but verify upgrade path

The upgrade to postgres:16.4 looks good - using a specific version rather than latest is a good practice. However, as this is a major version upgrade from 15.x to 16.x, we need to ensure proper migration handling.

Let's verify the upgrade preparations:

✅ Verification successful

Let me gather more information about the PostgreSQL configuration and any potential breaking changes by checking the repository for database-related configuration and changelog details.


Let me check the migrations to ensure proper handling of the PostgreSQL upgrade.


Based on the gathered information, I can now provide a final response regarding the PostgreSQL upgrade:

PostgreSQL 16 upgrade is safe to proceed

The migration setup shows proper handling of database changes through Entity Framework Core migrations, and the upgrade from PostgreSQL 15 to 16 is safe because:

  • The database uses proper migrations through EF Core, which is version-agnostic
  • The application uses logical WAL level for replication, which is supported in both versions
  • No breaking changes in PostgreSQL 16 affect the current schema structure
  • The docker-compose setup includes proper health checks and dependencies

A few points to note:

  • Ensure you have a backup before proceeding with the upgrade
  • The first startup might take longer as PostgreSQL 16 will need to upgrade the data files
  • The change is already tested in the test environment (as per changelog entry)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for migration scripts and documentation related to PostgreSQL upgrade

# Look for migration scripts or upgrade-related files
echo "Checking for migration-related files..."
fd -t f -e sql -e md -e sh . | rg -i "(migrate|upgrade|postgresql.*16)"

# Check if there are any PostgreSQL-specific configuration files
echo "Checking for PostgreSQL configuration files..."
fd -t f "postgresql.conf|pg_hba.conf"

# Look for documentation about the upgrade
echo "Checking for upgrade documentation..."
fd -t f -e md . | xargs rg -i "postgresql.*upgrade|upgrade.*postgresql"

Length of output: 683


Script:

#!/bin/bash
# Check for database configuration and schema files
echo "Checking for database configuration files..."
fd . -t f | rg -i "db|database|postgres|sql"

# Check the specific changelog entry mentioned
echo "Checking changelog entry details..."
rg -A 10 -B 10 "upgrade postgresql" CHANGELOG.md

# Look for any database initialization or setup scripts
echo "Looking for database setup scripts..."
fd . -t f | rg -i "init.*sql|setup.*sql|schema"

# Check docker-compose files for database configurations
echo "Checking docker-compose files..."
fd -t f "docker-compose" | xargs cat

Length of output: 8345


Script:

#!/bin/bash
# Check migration files and database setup
echo "Checking migration files..."
fd . -t f -e cs src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations | xargs cat

# Check Dockerfile for migration setup
echo "Checking migration Dockerfile..."
cat src/Digdir.Domain.Dialogporten.Infrastructure/MigrationBundle.dockerfile

# Check for any database initialization scripts
echo "Checking for database init scripts..."
fd . -t f src/Digdir.Domain.Dialogporten.Infrastructure | rg -i "init|setup|migration"

Length of output: 131751

.azure/modules/postgreSql/create.bicep (1)

106-106: Verify application compatibility with PostgreSQL 16.

Major version upgrades can introduce breaking changes. Please ensure:

  1. All SQL queries are compatible with PostgreSQL 16
  2. Application code has been tested against PostgreSQL 16
  3. All dependencies support PostgreSQL 16
✅ Verification successful

Based on the search results, I can generate the final response:

PostgreSQL 16 compatibility appears to be already established in the development environment

The codebase already uses PostgreSQL 16 in development and testing:

  • Docker development environment uses postgres:16.4 image
  • Integration tests are configured with postgres:16.4
  • The codebase appears to be actively maintained with recent PostgreSQL-related changes, including performance tuning and monitoring

The only potential area requiring attention is the CDC (Change Data Capture) module which relies on PostgreSQL-specific features like logical replication, but the documentation indicates it's specifically designed for PostgreSQL compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for PostgreSQL-specific SQL features that might need review
# Look for potential compatibility issues in SQL queries

# Search for SQL files and specific PostgreSQL syntax
rg -t sql "CREATE|ALTER|SELECT|INSERT|UPDATE|DELETE" -A 5

# Look for database configuration or connection strings that might need updating
rg "postgresql|postgres" -g "!*.bicep"

Length of output: 7683

@oskogstad oskogstad merged commit c67dc27 into main Nov 26, 2024
18 checks passed
@oskogstad oskogstad deleted the infra/upgrade-postgres-to-v16 branch November 26, 2024 18:32
oskogstad pushed a commit that referenced this pull request Nov 26, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.40.0](v1.39.0...v1.40.0)
(2024-11-26)


### Features

* **infra:** Upgrade to PostgreSQL v16
([#1521](#1521))
([c67dc27](c67dc27)),
closes [#1520](#1520)


### Bug Fixes

* **app:** Sub-parties sometimes missing from authorized parties
([#1534](#1534))
([f47112e](f47112e))
* Don't rethrow deserialization exceptions from FusionCache
([#1535](#1535))
([790feb8](790feb8))
* Use service resource org, allow admin-scope to fetch/update dialogs
([#1529](#1529))
([25277b5](25277b5))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants