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

devops-2410 update psql to v17 and add scripts migrate db from 13 to 17 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,18 @@ templates:
proxy: [default]
variables:
DB_NAME: cms_cms
```
```

## Upgrade postgres from 13 to 17 version

Just run script `migrate-db-from-13-to-17.sh` from workspace folder
```
./scripts/migrate-db-from-13-to-15.sh
```
it can prompt a sudo password, because it works with postgres data dir.

Script makes two backups:
- `backup.sql` in current folder
- `data-13-backup` in database service folder

Keep this files until you prove that database works correct.
36 changes: 36 additions & 0 deletions scripts/scripts/migrate-db-from-13-to-17.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -xe

elc stop database

sudo cp -r $PWD/services/database/data $PWD/services/database/data-13-backup

docker rm -f pg_13_for_migrate

docker run -d --name pg_13_for_migrate \
-v $PWD/services/database/data:/var/lib/postgresql/data \
dockerhub.greensight.ru/services/postgis:13-3.1

sleep 5

while ! docker exec -it pg_13_for_migrate pg_isready; do
sleep 1
done

echo Done

docker exec -it pg_13_for_migrate pg_dumpall -U postgres --clean > backup.sql

docker rm -f pg_13_for_migrate

sudo rm -rf $PWD/services/database/data
sudo mkdir $PWD/services/database/data
sudo chmod 777 $PWD/services/database/data

elc start database
sleep 5

cat backup.sql | elc exec --no-tty -c database psql -U postgres

echo "ALTER USER postgres WITH PASSWORD 'example';" | elc exec --no-tty -c database psql -U postgres
2 changes: 1 addition & 1 deletion workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ services:
database:
path: ${WORKSPACE_PATH}/services/database
variables:
APP_IMAGE: dockerhub.greensight.ru/services/postgis:13-3.1 #original docker image - postgis/postgis:13-3.1
APP_IMAGE: dockerhub.greensight.ru/services/postgis:17-3.4 #original docker image - postgis/postgis:17-3.4
tags:
- system

Expand Down