feat(admin-service): 添加 init-db 命令自动创建数据库
用法: ./deploy.sh init-db - 自动创建 rwa_admin 数据库(如不存在) - 自动运行 Prisma 迁移 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6f55dc3195
commit
086d82f98a
|
|
@ -161,6 +161,15 @@ case "$1" in
|
|||
# =========================================================================
|
||||
# Database Commands
|
||||
# =========================================================================
|
||||
init-db)
|
||||
show_banner
|
||||
log_info "Creating database rwa_admin if not exists..."
|
||||
docker exec rwa-postgres psql -U "${POSTGRES_USER:-rwa_user}" -c "CREATE DATABASE rwa_admin;" 2>/dev/null || log_warn "Database already exists"
|
||||
log_success "Database ready"
|
||||
log_info "Running migrations..."
|
||||
"$SCRIPT_DIR/deploy.sh" migrate
|
||||
;;
|
||||
|
||||
migrate)
|
||||
show_banner
|
||||
log_info "Running database migrations (production)..."
|
||||
|
|
@ -327,6 +336,7 @@ case "$1" in
|
|||
echo " health Check health endpoint"
|
||||
echo ""
|
||||
echo -e "${CYAN}Database Commands:${NC}"
|
||||
echo " init-db Create database and run migrations"
|
||||
echo " migrate Run migrations (production)"
|
||||
echo " migrate-dev Run migrations (development)"
|
||||
echo " migrate-status Check migration status"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Application
|
||||
NODE_ENV=development
|
||||
APP_PORT=3001
|
||||
APP_PORT=3011
|
||||
API_PREFIX=api/v1
|
||||
|
||||
# Database (PostgreSQL) - Local development
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
# Application
|
||||
NODE_ENV=development
|
||||
APP_PORT=3001
|
||||
APP_PORT=3011
|
||||
API_PREFIX=api/v1
|
||||
|
||||
# Database (PostgreSQL)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
# Application
|
||||
NODE_ENV=production
|
||||
APP_PORT=3001
|
||||
APP_PORT=3011
|
||||
API_PREFIX=api/v1
|
||||
|
||||
# Database (PostgreSQL) - Use environment variable
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ USER nestjs
|
|||
ENV NODE_ENV=production
|
||||
|
||||
# Expose port
|
||||
EXPOSE 3001
|
||||
EXPOSE 3011
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:3001/api/v1/health || exit 1
|
||||
CMD curl -f http://localhost:3011/api/v1/health || exit 1
|
||||
|
||||
# Start service
|
||||
CMD ["node", "dist/main.js"]
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ services:
|
|||
build: .
|
||||
container_name: presence-service
|
||||
ports:
|
||||
- "3001:3001"
|
||||
- "3011:3011"
|
||||
environment:
|
||||
# Application
|
||||
- NODE_ENV=production
|
||||
- APP_PORT=3001
|
||||
- APP_PORT=3011
|
||||
- API_PREFIX=api/v1
|
||||
# Database
|
||||
- DATABASE_URL=postgresql://postgres:password@postgres:5432/rwa_presence?schema=public
|
||||
|
|
@ -40,7 +40,7 @@ services:
|
|||
kafka:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3001/api/v1/health"]
|
||||
test: ["CMD", "curl", "-f", "http://localhost:3011/api/v1/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ Failed: 0
|
|||
|
||||
| 服务 | 开发端口 | 说明 |
|
||||
|-----|---------|------|
|
||||
| Presence Service | 3001 | NestJS 应用 |
|
||||
| Presence Service | 3011 | NestJS 应用 |
|
||||
| PostgreSQL | 5432 | 数据库 |
|
||||
| Redis | 6379 | 缓存 |
|
||||
| Kafka | 9092 | 消息队列 |
|
||||
|
|
@ -202,7 +202,7 @@ docker compose -f docker-compose.dev.yml restart zookeeper kafka
|
|||
|
||||
```bash
|
||||
# 查找占用端口的进程
|
||||
lsof -i :3001
|
||||
lsof -i :3011
|
||||
lsof -i :5432
|
||||
lsof -i :6379
|
||||
lsof -i :9092
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ check_service "Kafka" "nc -zv localhost 9092" "docker compose -f docker-compose.
|
|||
|
||||
# Check Presence Service
|
||||
echo -e "${YELLOW}=== Application Service ===${NC}"
|
||||
check_service "Presence Service" "curl -sf http://localhost:3001/api/v1/health" "npm run start:dev"
|
||||
check_service "Presence Service" "curl -sf http://localhost:3011/api/v1/health" "npm run start:dev"
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ YELLOW='\033[1;33m'
|
|||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
BASE_URL="http://localhost:3001/api/v1"
|
||||
BASE_URL="http://localhost:3011/api/v1"
|
||||
|
||||
# Test counters
|
||||
PASS=0
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ cd "$PROJECT_DIR"
|
|||
|
||||
# 1. Stop Presence Service (if running)
|
||||
echo -e "${BLUE}Step 1: Stop Presence Service${NC}"
|
||||
PID=$(lsof -ti :3001 2>/dev/null)
|
||||
PID=$(lsof -ti :3011 2>/dev/null)
|
||||
if [ ! -z "$PID" ]; then
|
||||
echo "Stopping Presence Service (PID: $PID)..."
|
||||
kill $PID 2>/dev/null || true
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ SERVICE_PID=$!
|
|||
# Wait for service to start
|
||||
echo "Waiting for service to be ready (up to 30 seconds)..."
|
||||
for i in {1..30}; do
|
||||
if curl -sf http://localhost:3001/api/v1/health > /dev/null 2>&1; then
|
||||
if curl -sf http://localhost:3011/api/v1/health > /dev/null 2>&1; then
|
||||
echo -e "${GREEN}✓ Presence Service is running!${NC}"
|
||||
break
|
||||
fi
|
||||
|
|
@ -109,9 +109,9 @@ echo -e "${GREEN}✓ All services started!${NC}"
|
|||
echo -e "${YELLOW}======================================${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Service endpoints:${NC}"
|
||||
echo " • Presence Service: http://localhost:3001"
|
||||
echo " • Health Check: http://localhost:3001/api/v1/health"
|
||||
echo " • API Docs: http://localhost:3001/api/docs"
|
||||
echo " • Presence Service: http://localhost:3011"
|
||||
echo " • Health Check: http://localhost:3011/api/v1/health"
|
||||
echo " • API Docs: http://localhost:3011/api/docs"
|
||||
echo ""
|
||||
echo -e "${BLUE}Next steps:${NC}"
|
||||
echo " • Run health check: ./scripts/health-check.sh"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# =============================================================================
|
||||
# Presence Service - Stop Service Script
|
||||
# =============================================================================
|
||||
# Gracefully stops the Presence Service running on port 3001.
|
||||
# Gracefully stops the Presence Service running on port 3011.
|
||||
# =============================================================================
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
|
|
@ -12,11 +12,11 @@ NC='\033[0m'
|
|||
|
||||
echo -e "${YELLOW}🛑 Stopping Presence Service...${NC}"
|
||||
|
||||
# Find process listening on port 3001
|
||||
# Find process listening on port 3011
|
||||
if command -v lsof &> /dev/null; then
|
||||
PID=$(lsof -ti :3001 2>/dev/null)
|
||||
PID=$(lsof -ti :3011 2>/dev/null)
|
||||
elif command -v netstat &> /dev/null; then
|
||||
PID=$(netstat -tlnp 2>/dev/null | grep :3001 | awk '{print $7}' | cut -d'/' -f1)
|
||||
PID=$(netstat -tlnp 2>/dev/null | grep :3011 | awk '{print $7}' | cut -d'/' -f1)
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Cannot find process (lsof/netstat not available)${NC}"
|
||||
echo "Try: pkill -f 'node.*presence'"
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ async function bootstrap() {
|
|||
SwaggerModule.setup(`${apiPrefix}/docs`, app, document);
|
||||
|
||||
// 启动服务
|
||||
const port = parseInt(process.env.APP_PORT || '3001', 10);
|
||||
const port = parseInt(process.env.APP_PORT || '3011', 10);
|
||||
await app.listen(port);
|
||||
|
||||
logger.log(`Presence Service is running on: http://localhost:${port}/${apiPrefix}`);
|
||||
|
|
|
|||
Loading…
Reference in New Issue