From 8e62760d6951bac368d6d2923994ebda664a2c24 Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Sat, 16 Sep 2023 15:41:19 +0900 Subject: [PATCH] create postgres migration --- postgres-migration/.env | 2 ++ postgres-migration/compose.yml | 40 +++++++++++++++++++++++++++++++++ postgres-migration/servers.json | 13 +++++++++++ 3 files changed, 55 insertions(+) create mode 100644 postgres-migration/.env create mode 100644 postgres-migration/compose.yml create mode 100644 postgres-migration/servers.json diff --git a/postgres-migration/.env b/postgres-migration/.env new file mode 100644 index 0000000..7b28698 --- /dev/null +++ b/postgres-migration/.env @@ -0,0 +1,2 @@ +# touch .env && chmod 600 .env && echo POSTGRES_PASSWORD=$(openssl rand -hex 32) >> .env +POSTGRES_PASSWORD=18bc0402c8e8a7d95ed49c2d9b93a4cae9d5970c9fc6c6f328977b93f77bb48a diff --git a/postgres-migration/compose.yml b/postgres-migration/compose.yml new file mode 100644 index 0000000..b0d9dcb --- /dev/null +++ b/postgres-migration/compose.yml @@ -0,0 +1,40 @@ +services: + pgadmin: + image: dpage/pgadmin4 + ports: + - "8080:80" + environment: + PGADMIN_DEFAULT_EMAIL: postgres@db.host.docker.internal + PGADMIN_DEFAULT_PASSWORD: ${POSTGRES_PASSWORD:?} + volumes: + - ./servers.json:/pgadmin4/servers.json:ro + db: + image: postgres:16-alpine + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?} + volumes: + - postgres_data_v16:/var/lib/postgresql/data + # - postgres_data_v17:/var/lib/postgresql/data + old_db: + profiles: + - migration + image: postgres:16-alpine + # image: postgres:16-alpine + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?} + volumes: + - postgres_data_v16:/var/lib/postgresql/data +volumes: + postgres_data_v16: + # postgres_data_v17: +# docker compose down +# editor compose.yml +# add new version volume +# replace old_db.image new → old version +# replace db.volumes old → new version +# docker compose --profile=migration up -d old_db db +# docker compose exec old_db pg_dumpall --clean -U postgres | docker compose exec -T db psql -U postgres +# docker compose up -d +# docker compose --profile=migration down old_db +# editor compose.yml +# remove volume diff --git a/postgres-migration/servers.json b/postgres-migration/servers.json new file mode 100644 index 0000000..6fce1be --- /dev/null +++ b/postgres-migration/servers.json @@ -0,0 +1,13 @@ +{ + "Servers": { + "1": { + "Name": "postgres@db", + "Group": "docker", + "Port": 5432, + "Username": "postgres", + "Host": "db", + "SSLMode": "prefer", + "MaintenanceDB": "postgres" + } + } +}