Skip to content

chore: Add script to upgrade Postgres 13 data to 14#34317

Merged
sharat87 merged 10 commits intoreleasefrom
chore/deps/pg-14
Jun 21, 2024
Merged

chore: Add script to upgrade Postgres 13 data to 14#34317
sharat87 merged 10 commits intoreleasefrom
chore/deps/pg-14

Conversation

@sharat87
Copy link
Member

@sharat87 sharat87 commented Jun 19, 2024

We're upgrading embedded Postgres from 13 to 14, and this PR includes a script to perform the upgrade of the data folder from v13 schema to v14 schema. This script temporarily installs Postgres 13, if not available, for the upgrade process, so will continue to work when and if we choose to remove postgresql-13 from the base image.

Tested this manually as well, running an Appsmith with Postgres 13, executing some workflows via webhook, getting some run data generated, then upgrading Postgres with the script in this PR, and ensuring that the workflow run history is still there and visible on the UI exactly the same. It is.

No conflicts or additional changes needed on EE. All server and Cypress tests pass on EE.

shot-2024-06-20-02-13-26

/test sanity

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9590240540
Commit: 9c75da5
Cypress dashboard.
Tags: @tag.Sanity

Summary by CodeRabbit

  • New Features

    • Added automation script for upgrading PostgreSQL to the latest version.
    • Introduced testing script for PostgreSQL upgrades in Docker environments.
  • Improvements

    • Upgraded PostgreSQL from version 13 to 14 in Docker setup, ensuring compatibility and performance enhancements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Warning

Rate limit exceeded

@sharat87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 48 minutes and 23 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 8a62f96 and 7c5ab1e.

Walkthrough

The updates enhance PostgreSQL support by upgrading from version 13 to 14 in the Docker environment, alongside improving the initialization and upgrade processes. Key changes include path updates, automation scripts for PostgreSQL upgrades, and test scripts to ensure successful upgrades.

Changes

Files Change Summaries
deploy/docker/base.dockerfile Install PostgreSQL 14, update path environment variable to version 14
deploy/docker/fs/opt/appsmith/entrypoint.sh Removed temporary path export for PostgreSQL 13, updated initialization logic to check existing version and execute upgrade script
deploy/docker/fs/opt/appsmith/pg-upgrade.sh New script automating the PostgreSQL upgrade process
deploy/docker/tests/pg-upgrade/run.sh New test script for validating PostgreSQL upgrade in Docker environment

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Docker Container
    participant Entrypoint Script
    participant PG Upgrade Script

    User->>Docker Container: Start Container
    Docker Container->>Entrypoint Script: Execute entrypoint.sh
    Entrypoint Script->>PG Upgrade Script: Check PG_VERSION, run pg-upgrade.sh if exists
    PG Upgrade Script->>PostgreSQL: Perform Upgrade (check version, data migration)
    PG Upgrade Script->>Entrypoint Script: Complete Upgrade
    Entrypoint Script->>Docker Container: Continue Initialization
    Docker Container->>User: Container Ready with PostgreSQL 14
Loading

Poem

In Docker's realm, where codes reside,
PostgreSQL blooms in newer tides.
From thirteen's roots to fourteen's grace,
Scripts and tests ensure no trace,
Of errors lodged or data fears,
Upgrades smooth, bring cheers and gears.
🎉🐇🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jun 19, 2024
@sharat87
Copy link
Member Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9575843921.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34317.
recreate: .

@github-actions
Copy link

Deploy-Preview-URL: https://ce-34317.dp.appsmith.com

@sharat87 sharat87 added the ok-to-test Required label for CI label Jun 19, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 19, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 20, 2024
@sharat87 sharat87 marked this pull request as ready for review June 20, 2024 02:14
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: 6

Outside diff range and nitpick comments (3)
deploy/docker/tests/pg-upgrade/run.sh (2)

3-3: Consider removing the "WIP" tag if the script is ready for production.


18-18: Clarify the TODO comment about --pull always or remove it if no longer relevant.

deploy/docker/fs/opt/appsmith/pg-upgrade.sh (1)

6-19: Ensure that the script's assumptions and contract are clearly documented and validated at runtime.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f718bfb and 54e9157.

Files selected for processing (4)
  • deploy/docker/base.dockerfile (1 hunks)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (2 hunks)
  • deploy/docker/fs/opt/appsmith/pg-upgrade.sh (1 hunks)
  • deploy/docker/tests/pg-upgrade/run.sh (1 hunks)
Files not reviewed due to errors (1)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (no review received)
Additional context used
Shellcheck
deploy/docker/tests/pg-upgrade/run.sh

[error] 87-87: Couldn't parse this test expression. Fix to allow more checks. (SC1073)


[error] 87-87: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again. (SC1072)

deploy/docker/fs/opt/appsmith/entrypoint.sh

[warning] 62-62: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 66-66: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 70-70: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 74-74: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 86-86: ShellCheck can't follow non-constant source. Use a directive to specify location. (SC1090)

Hadolint
deploy/docker/base.dockerfile

[warning] 17-17: Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version> (DL3008)


[info] 17-17: Delete the apt-get lists after installing something (DL3009)


[warning] 17-17: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check (DL4006)


[warning] 17-17: Do not use apt as it is meant to be a end-user tool, use apt-get or apt-cache instead (DL3027)


[warning] 38-38: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check (DL4006)


[info] 38-38: Double quote to prevent globbing and word splitting. (SC2086)


[warning] 49-49: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check (DL4006)


[warning] 55-55: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check (DL4006)

Additional comments not posted (4)
deploy/docker/tests/pg-upgrade/run.sh (1)

91-96: Ensure that the cleanup process does not inadvertently remove necessary resources.

Verification successful

The cleanup commands docker rm --force "$container_name" and docker volume rm --force "$container_name" are used within a specific test script (deploy/docker/tests/pg-upgrade/run.sh). These commands are intended to remove the test container and its associated volume, which is a common practice to ensure a clean state for subsequent tests.

  • docker rm -f "$container_name": Removes the container forcefully.
  • docker volume rm --force "$container_name": Removes the volume forcefully.

Given that these commands are used in a controlled test environment and are specifically targeting a test container and volume (appsmith-pg-upgrade-test), there is no indication that they would inadvertently remove necessary resources outside the scope of the test.

  • Lines in deploy/docker/tests/pg-upgrade/run.sh:
    • docker rm --force "$container_name"
    • docker volume rm --force "$container_name"

Therefore, the cleanup process appears to be safe and does not indicate any removal of necessary resources beyond the test scope.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for potential issues in the cleanup process.
# Test: Search for patterns that might indicate risky cleanup operations.
rg --type bash $'docker rm --force|docker volume rm --force'

Length of output: 90



Script:

#!/bin/bash
# Description: Check for potential issues in the cleanup process.
# Test: Search for patterns that might indicate risky cleanup operations.
rg 'docker rm --force|docker volume rm --force'

Length of output: 446



Script:

#!/bin/bash
# Description: Extract and review the context of cleanup commands in the specified script.
# Extract lines around the identified commands for context.
rg -C 5 'docker rm --force|docker volume rm --force' deploy/docker/tests/pg-upgrade/run.sh

Length of output: 477

deploy/docker/base.dockerfile (1)

35-35: Ensure that the PATH environment variable correctly prioritizes the necessary PostgreSQL version.

deploy/docker/fs/opt/appsmith/pg-upgrade.sh (2)

36-39: Ensure that the error message is clear and provides actionable steps if Postgres was not shutdown cleanly.


47-84: Review the upgrade logic to ensure that it handles different scenarios robustly, particularly around version checks and data migration.

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: 1

Outside diff range and nitpick comments (3)
deploy/docker/tests/pg-upgrade/run.sh (3)

15-16: Consider adding error handling for Docker commands.

Given the nature of this script, adding error handling for Docker commands such as docker rm -f and docker volume rm --force could prevent the script from failing silently if these commands do not execute as expected. This would make the script more robust, especially in environments where Docker resources might be in a varied state.


18-18: Clarify the TODO comment regarding --pull always.

The TODO comment on line 18 is a bit unclear. It would be beneficial to expand on this comment to specify under what conditions or in which scenarios the --pull always option would be beneficial. This will help future maintainers understand the intent and evaluate the necessity of this change.


72-72: Remove unused variable or clarify its usage.

The variable sample_table_contents is set but never used within the script. If this variable is meant to be used externally, consider exporting it; otherwise, it should be removed to avoid confusion.

Tools
Shellcheck

[warning] 72-72: sample_table_contents appears unused. Verify use (or export if used externally). (SC2034)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54e9157 and 8a62f96.

Files selected for processing (1)
  • deploy/docker/tests/pg-upgrade/run.sh (1 hunks)
Additional context used
Learnings (1)
deploy/docker/tests/pg-upgrade/run.sh (1)
User: sharat87
PR: appsmithorg/appsmith#34317
File: deploy/docker/tests/pg-upgrade/run.sh:37-52
Timestamp: 2024-06-20T02:20:27.587Z
Learning: sharat87 indicated that explicit error handling for `supervisorctl` and `psql` is not a priority, as the assumption is that if these commands fail, the entire system is likely down. This reflects a high confidence in the stability of these components under normal conditions.
Shellcheck
deploy/docker/tests/pg-upgrade/run.sh

[warning] 72-72: sample_table_contents appears unused. Verify use (or export if used externally). (SC2034)

Additional comments not posted (2)
deploy/docker/tests/pg-upgrade/run.sh (2)

37-53: Ensure consistent error handling in the script block.

The script block executed within the Docker container (lines 37-53) does not handle potential errors from commands like supervisorctl stop and psql. Considering the previous feedback and current practices, it might be beneficial to add checks after these commands to ensure they succeed before proceeding. This would prevent the script from continuing in an inconsistent state.

Skipped due to learnings
User: sharat87
PR: appsmithorg/appsmith#34317
File: deploy/docker/tests/pg-upgrade/run.sh:37-52
Timestamp: 2024-06-20T02:20:27.587Z
Learning: sharat87 indicated that explicit error handling for `supervisorctl` and `psql` is not a priority, as the assumption is that if these commands fail, the entire system is likely down. This reflects a high confidence in the stability of these components under normal conditions.

42-48: Verify SQL commands execution.

This segment inserts sample data into the PostgreSQL database. It's crucial to ensure that these SQL commands execute successfully, especially in a testing script where data integrity is significant for subsequent tests.

@sharat87 sharat87 requested a review from srix June 20, 2024 05:29
@sharat87 sharat87 merged commit 26c0f07 into release Jun 21, 2024
@sharat87 sharat87 deleted the chore/deps/pg-14 branch June 21, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants