refactor: 拆分 postgres 为 per-domain 数据库
This commit is contained in:
+194
-25
@@ -1,19 +1,10 @@
|
|||||||
services:
|
x-postgres-base: &postgres-base
|
||||||
# ==================== 基础设施 ====================
|
|
||||||
postgres:
|
|
||||||
image: postgres:17-bookworm
|
image: postgres:17-bookworm
|
||||||
container_name: juwan-postgres
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment: &postgres-env
|
||||||
POSTGRES_USER: ${PD_USERNAME}
|
POSTGRES_USER: ${PD_USERNAME}
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
POSTGRES_DB: ${DB_NAME}
|
POSTGRES_DB: ${DB_NAME}
|
||||||
ports:
|
|
||||||
- "15432:5432"
|
|
||||||
volumes:
|
|
||||||
- pgdata:/var/lib/postgresql/data
|
|
||||||
- ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
|
|
||||||
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${PD_USERNAME} -d ${DB_NAME}"]
|
test: ["CMD-SHELL", "pg_isready -U ${PD_USERNAME} -d ${DB_NAME}"]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
@@ -21,6 +12,129 @@ services:
|
|||||||
start_period: 30s
|
start_period: 30s
|
||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
|
services:
|
||||||
|
# ==================== 基础设施 ====================
|
||||||
|
users-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-users-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: users
|
||||||
|
volumes:
|
||||||
|
- users-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
game-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-game-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: game
|
||||||
|
volumes:
|
||||||
|
- game-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
player-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-player-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: player
|
||||||
|
volumes:
|
||||||
|
- player-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
shop-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-shop-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: shop
|
||||||
|
volumes:
|
||||||
|
- shop-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
order-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-order-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: order
|
||||||
|
volumes:
|
||||||
|
- order-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
wallet-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-wallet-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: wallet
|
||||||
|
volumes:
|
||||||
|
- wallet-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
community-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-community-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: community
|
||||||
|
volumes:
|
||||||
|
- community-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
review-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-review-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: review
|
||||||
|
volumes:
|
||||||
|
- review-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
dispute-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-dispute-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: dispute
|
||||||
|
volumes:
|
||||||
|
- dispute-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
notification-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-notification-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: notification
|
||||||
|
volumes:
|
||||||
|
- notification-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
|
search-db:
|
||||||
|
<<: *postgres-base
|
||||||
|
container_name: juwan-search-db
|
||||||
|
environment:
|
||||||
|
<<: *postgres-env
|
||||||
|
POSTGRES_DOMAIN: search
|
||||||
|
volumes:
|
||||||
|
- search-pgdata:/var/lib/postgresql/data
|
||||||
|
- ./init-domain.sh:/docker-entrypoint-initdb.d/00-init-domain.sh:ro
|
||||||
|
- ../../desc/sql:/docker-entrypoint-initdb.d/sql:ro
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:8-alpine
|
image: redis:8-alpine
|
||||||
container_name: juwan-redis
|
container_name: juwan-redis
|
||||||
@@ -173,11 +287,13 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
|
DB_HOST: users-db
|
||||||
|
DB_HOST_RO: users-db
|
||||||
ADMIN_USERNAME: ${ADMIN_USERNAME}
|
ADMIN_USERNAME: ${ADMIN_USERNAME}
|
||||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
||||||
ADMIN_EMAIL: ${ADMIN_EMAIL}
|
ADMIN_EMAIL: ${ADMIN_EMAIL}
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
users-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -189,8 +305,11 @@ services:
|
|||||||
container_name: juwan-user-verifications-rpc
|
container_name: juwan-user-verifications-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: users-db
|
||||||
|
DB_HOST_RO: users-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
users-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -204,8 +323,11 @@ services:
|
|||||||
container_name: juwan-player-rpc
|
container_name: juwan-player-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: player-db
|
||||||
|
DB_HOST_RO: player-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
player-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -217,8 +339,11 @@ services:
|
|||||||
container_name: juwan-game-rpc
|
container_name: juwan-game-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: game-db
|
||||||
|
DB_HOST_RO: game-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
game-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -230,8 +355,11 @@ services:
|
|||||||
container_name: juwan-shop-rpc
|
container_name: juwan-shop-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: shop-db
|
||||||
|
DB_HOST_RO: shop-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
shop-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -245,8 +373,11 @@ services:
|
|||||||
container_name: juwan-order-rpc
|
container_name: juwan-order-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: order-db
|
||||||
|
DB_HOST_RO: order-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
order-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -258,8 +389,11 @@ services:
|
|||||||
container_name: juwan-wallet-rpc
|
container_name: juwan-wallet-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: wallet-db
|
||||||
|
DB_HOST_RO: wallet-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
wallet-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -271,8 +405,11 @@ services:
|
|||||||
container_name: juwan-community-rpc
|
container_name: juwan-community-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: community-db
|
||||||
|
DB_HOST_RO: community-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
community-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -290,8 +427,11 @@ services:
|
|||||||
container_name: juwan-review-rpc
|
container_name: juwan-review-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: review-db
|
||||||
|
DB_HOST_RO: review-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
review-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -303,8 +443,11 @@ services:
|
|||||||
container_name: juwan-dispute-rpc
|
container_name: juwan-dispute-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: dispute-db
|
||||||
|
DB_HOST_RO: dispute-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
dispute-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -316,8 +459,11 @@ services:
|
|||||||
container_name: juwan-notification-rpc
|
container_name: juwan-notification-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: notification-db
|
||||||
|
DB_HOST_RO: notification-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
notification-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -329,8 +475,11 @@ services:
|
|||||||
container_name: juwan-search-rpc
|
container_name: juwan-search-rpc
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
DB_HOST: search-db
|
||||||
|
DB_HOST_RO: search-db
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
search-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -527,8 +676,28 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
pgdata:
|
users-pgdata:
|
||||||
name: juwan-pgdata
|
name: juwan-users-pgdata
|
||||||
|
game-pgdata:
|
||||||
|
name: juwan-game-pgdata
|
||||||
|
player-pgdata:
|
||||||
|
name: juwan-player-pgdata
|
||||||
|
shop-pgdata:
|
||||||
|
name: juwan-shop-pgdata
|
||||||
|
order-pgdata:
|
||||||
|
name: juwan-order-pgdata
|
||||||
|
wallet-pgdata:
|
||||||
|
name: juwan-wallet-pgdata
|
||||||
|
community-pgdata:
|
||||||
|
name: juwan-community-pgdata
|
||||||
|
review-pgdata:
|
||||||
|
name: juwan-review-pgdata
|
||||||
|
dispute-pgdata:
|
||||||
|
name: juwan-dispute-pgdata
|
||||||
|
notification-pgdata:
|
||||||
|
name: juwan-notification-pgdata
|
||||||
|
search-pgdata:
|
||||||
|
name: juwan-search-pgdata
|
||||||
redisdata:
|
redisdata:
|
||||||
name: juwan-redisdata
|
name: juwan-redisdata
|
||||||
mongodata:
|
mongodata:
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
SQL_DIR="/docker-entrypoint-initdb.d/sql"
|
|
||||||
|
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f "$SQL_DIR/common/update_updated_at_column.sql"
|
|
||||||
|
|
||||||
ordered=(
|
|
||||||
users/users.sql
|
|
||||||
users/user_follows.sql
|
|
||||||
users/user_preferences.sql
|
|
||||||
users/user_verifications.sql
|
|
||||||
game/games.sql
|
|
||||||
player/players.sql
|
|
||||||
player/player_services.sql
|
|
||||||
shop/shop.sql
|
|
||||||
shop/shop_players.sql
|
|
||||||
shop/shop_invitations.sql
|
|
||||||
order/00-orders.sql
|
|
||||||
order/order_state_log.sql
|
|
||||||
wallet/00-wallets.sql
|
|
||||||
wallet/wallet_transactions.sql
|
|
||||||
community/posts.sql
|
|
||||||
community/comments.sql
|
|
||||||
community/post_likes.sql
|
|
||||||
community/comment_likes.sql
|
|
||||||
dispute/disputes.sql
|
|
||||||
dispute/dispute_timeline.sql
|
|
||||||
review/reviews.sql
|
|
||||||
notification/notifications.sql
|
|
||||||
search/favorites.sql
|
|
||||||
)
|
|
||||||
|
|
||||||
for f in "${ordered[@]}"; do
|
|
||||||
[ -f "$SQL_DIR/$f" ] || continue
|
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f "$SQL_DIR/$f"
|
|
||||||
done
|
|
||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SQL_DIR="/docker-entrypoint-initdb.d/sql"
|
||||||
|
DOMAIN="${POSTGRES_DOMAIN:?POSTGRES_DOMAIN env required}"
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" \
|
||||||
|
-f "$SQL_DIR/common/update_updated_at_column.sql"
|
||||||
|
|
||||||
|
for f in "$SQL_DIR/$DOMAIN"/*.sql; do
|
||||||
|
[ -f "$f" ] || continue
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f "$f"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user