DockerPostgresMigration/README.md
2024-12-07 23:09:37 +01:00

23 lines
1.1 KiB
Markdown

# Docker migration helper
This repo contains a `Dockerfile` that can helps you in performing your Docker images migration.
This repository will:
* Perform a temporary copy the old database
* Initialize a new empty database with the default user / password couple provided as environment variables (`POSTGRES_USER` and `POSTGRES_PASSWORD`)
* Run `pg_upgrade` from the copy of the old database to the new database
* Replace the old database with the new one
* Move the copy of the old database as sub-directory of the new database (in `old_db` directory, to allow rollback in case of failure)
## Perform the migration
Create an outdated database:
```bash
mkdir test-db
docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:16
```
Perform the migration (you need to replace `POSTGRES_USER` and `POSTGRES_PASSWORD` with the credentials of the root user of the database):
```bash
docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17
```