PromucFlow_constructor/deploy/docker/tests/pg-upgrade/run.sh
Shrikant Sharat Kandula 26c0f07e14
chore: Add script to upgrade Postgres 13 data to 14 (#34317)
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](https://github.com/appsmithorg/appsmith-ee/pull/4493).


![shot-2024-06-20-02-13-26](https://github.com/appsmithorg/appsmith/assets/120119/9bb60e3a-6cc9-4df9-9064-caead78729a6)


**/test sanity**



<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9590240540>
> Commit: 9c75da53f871ffb912015c18a7504327cba88f2c
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9590240540&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`

<!-- end of auto-generated comment: Cypress test results  -->





<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## 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.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-21 19:34:08 +05:30

94 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# A script to test Postgres upgrades. WIP.
set -o errexit
set -o nounset
set -o xtrace
from_tag=appsmith/appsmith-ce:v1.28
to_tag=appsmith/appsmith-ce:latest
container_name=appsmith-pg-upgrade-test
port=20080
docker rm -f "$container_name"
docker volume rm --force "$container_name"
# TODO: Add `--pull always` for images that have a manifest?
docker volume create "$container_name"
docker run \
--name "$container_name" \
--detach \
--publish "$port":80 \
--volume "$container_name":/appsmith-stacks \
"$from_tag"
wait-for-supervisor() {
while ! docker exec "$container_name" test -e /tmp/appsmith/supervisor.sock; do
sleep 1
done
sleep 2
}
wait-for-supervisor
docker exec "$container_name" bash -exc '
supervisorctl status \
| awk '\''$1 != "postgres" && $1 != "stdout" {print $1}'\'' \
| xargs supervisorctl stop
# Insert some sample data
su postgres -c "psql -h 127.0.0.1 -c \"
create table t (id serial, name text);
insert into t values (1, '\''one'\'');
insert into t values (2, '\''two'\'');
insert into t values (3, '\''three'\'');
\""
supervisorctl stop postgres
cat /appsmith-stacks/data/postgres/main/PG_VERSION
'
docker rm -f "$container_name"
docker run \
--name "$container_name" \
--detach \
--publish "$port":80 \
--volume "$container_name":/appsmith-stacks \
"$to_tag"
wait-for-supervisor
status=0
if [[ 14 != "$(docker exec "$container_name" cat /appsmith-stacks/data/postgres/main/PG_VERSION)" ]]; then
echo "Version isn't 14"
status=1
else
sample_table_contents="$(su postgres -c 'psql -h 127.0.0.1 -c "select * from t"')"
expected_contents=' id | name
----+-------
1 | one
2 | two
3 | three
(3 rows)'
if ! diff <(echo "$expected_contents") <(su postgres -c 'psql -h 127.0.0.1 -c "select * from t"'); then
status=1
echo "Table contents mismatch. Found this:"
su postgres -c 'psql -h 127.0.0.1 -c "select * from t"'
echo "Instead of this:"
echo "$expected_contents"
fi
fi
docker exec -it "$container_name" bash
docker rm --force "$container_name"
docker volume rm --force "$container_name"
exit "$status"