Files
pos-system/scripts/db/setup-neon.sh
Ho Ngoc Hai 29c40ea681 Update project documentation and scripts for improved setup and bilingual support
- Enhanced `README.md` with a quick start guide and detailed project structure.
- Updated `SETUP_GUIDE.md` by removing it as it was redundant.
- Improved `local-development.md` and `development.md` with clearer instructions for database migrations.
- Added bilingual comments in various scripts for better understanding and usability.
- Updated `.gitignore` to include specific build scripts while ignoring others.
- Enhanced `scripts` for database management, including backup and seeding functionalities with bilingual support.
2025-12-27 10:12:46 +07:00

72 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "🚀 Neon Database Setup Script"
echo ""
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${YELLOW}This script helps you set up Neon database for all environments.${NC}"
echo ""
# EN: Check if .env.local exists
# VI: Kiểm tra xem .env.local có tồn tại không
ENV_LOCAL="deployments/local/.env.local"
if [ ! -f "$ENV_LOCAL" ]; then
echo "📝 Creating $ENV_LOCAL from example..."
cp deployments/local/env.local.example "$ENV_LOCAL"
echo -e "${GREEN}✅ Created $ENV_LOCAL${NC}"
echo ""
fi
echo "📋 Setup Steps:"
echo ""
echo "1. Go to https://console.neon.tech"
echo "2. Create a project (or use existing): goodgo-platform"
echo "3. Create branches:"
echo " - staging (from main)"
echo " - production (from main)"
echo ""
echo "4. Get connection strings for each branch from Neon Console"
echo " Format: postgresql://user:password@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true"
echo ""
read -p "Enter development DATABASE_URL (main branch): " dev_url
if [ -n "$dev_url" ]; then
# EN: Update .env.local with new URL
# VI: Cập nhật .env.local với URL mới
if grep -q "DATABASE_URL=" "$ENV_LOCAL"; then
sed -i.bak "s|DATABASE_URL=.*|DATABASE_URL=$dev_url|" "$ENV_LOCAL"
rm -f "${ENV_LOCAL}.bak"
else
echo "DATABASE_URL=$dev_url" >> "$ENV_LOCAL"
fi
echo -e "${GREEN}✅ Updated $ENV_LOCAL${NC}"
fi
echo ""
echo "📝 Next Steps:"
echo ""
echo "1. Add to GitHub Secrets (for CI/CD):"
echo " - NEON_DATABASE_URL_STAGING"
echo " - NEON_DATABASE_URL_PRODUCTION"
echo " - NEON_DATABASE_URL_TEST (optional, for CI tests)"
echo ""
echo "2. Create Kubernetes secrets for staging/production:"
echo " See: deployments/staging/kubernetes/secrets.yaml.example"
echo " See: deployments/production/kubernetes/secrets.yaml.example"
echo ""
echo "3. Run initial migration:"
echo " ./scripts/db/migrate.sh auth-service dev"
echo ""
echo "4. Seed database (optional):"
echo " ./scripts/db/seed.sh auth-service"
echo ""
echo -e "${GREEN}✅ Setup instructions complete!${NC}"
echo ""
echo "For more details, see: infra/databases/neon/README.md"