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.
This commit is contained in:
Ho Ngoc Hai
2025-12-27 10:12:46 +07:00
parent 79866e22cf
commit 29c40ea681
23 changed files with 528 additions and 392 deletions

View File

@@ -5,30 +5,43 @@ set -e
SERVICE=$1
BACKUP_DIR="${2:-./backups}"
# EN: Validate arguments
# VI: Xác thực tham số
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name> [backup-dir]"
echo "Example: $0 auth-service"
exit 1
fi
# EN: Create backup directory if not exists
# VI: Tạo thư mục backup nếu chưa tồn tại
mkdir -p "$BACKUP_DIR"
# EN: Generate timestamped filename
# VI: Tạo tên file với dấu thời gian
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/${SERVICE}_${TIMESTAMP}.sql"
echo "💾 Backing up database for $SERVICE..."
# Extract database URL from .env or environment
# EN: Extract database URL from .env or environment
# VI: Trích xuất database URL từ .env hoặc biến môi trường
cd "services/$SERVICE"
if [ -z "$DATABASE_URL" ]; then
# EN: Check local .env file
# VI: Kiểm tra file .env cục bộ
if [ -f ".env" ]; then
DATABASE_URL=$(grep DATABASE_URL .env | cut -d '=' -f2- | tr -d '"' | tr -d "'")
# EN: Check shared env file
# VI: Kiểm tra file env chia sẻ
elif [ -f "../../deployments/local/.env.local" ]; then
DATABASE_URL=$(grep DATABASE_URL ../../deployments/local/.env.local | cut -d '=' -f2- | tr -d '"' | tr -d "'")
fi
fi
# EN: Validate DATABASE_URL is set
# VI: Xác thực DATABASE_URL đã được thiết lập
if [ -z "$DATABASE_URL" ]; then
echo "❌ DATABASE_URL not found. Please set it in:"
echo " - services/$SERVICE/.env"
@@ -37,17 +50,23 @@ if [ -z "$DATABASE_URL" ]; then
exit 1
fi
# Use pg_dump directly with DATABASE_URL (works with Neon and standard PostgreSQL)
# EN: Use pg_dump directly with DATABASE_URL (works with Neon and standard PostgreSQL)
# VI: Sử dụng pg_dump trực tiếp với DATABASE_URL (hoạt động với Neon và PostgreSQL chuẩn)
#
# Neon URLs format: postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require
# Standard format: postgresql://user:pass@host:port/dbname
# Check if pg_dump supports connection string (PostgreSQL 11+)
# EN: Check if pg_dump supports connection string (PostgreSQL 11+)
# VI: Kiểm tra xem pg_dump có hỗ trợ connection string không (PostgreSQL 11+)
if pg_dump --version | grep -qE "1[1-9]|2[0-9]"; then
# Use connection string directly (supports Neon)
# EN: Use connection string directly (supports Neon)
# VI: Sử dụng connection string trực tiếp (hỗ trợ Neon)
pg_dump "$DATABASE_URL" > "../$BACKUP_FILE"
else
# Fallback: Parse connection string for older pg_dump
# Remove query parameters for parsing
# EN: Fallback: Parse connection string for older pg_dump
# VI: Dự phòng: Phân tích connection string cho bản pg_dump cũ hơn
# EN: Remove query parameters for parsing
# VI: Loại bỏ các tham số query để phân tích
CLEAN_URL=$(echo $DATABASE_URL | sed 's/?.*//')
DB_USER=$(echo $CLEAN_URL | sed -n 's/.*:\/\/\([^:]*\):.*/\1/p')
DB_PASS=$(echo $CLEAN_URL | sed -n 's/.*:\/\/[^:]*:\([^@]*\)@.*/\1/p')

View File

@@ -4,12 +4,16 @@ set -e
SERVICE=$1
# EN: Validate argument
# VI: Xác thực tham số
if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service-name>"
echo "Example: $0 auth-service"
exit 1
fi
# EN: Check if service exists
# VI: Kiểm tra xem service có tồn tại không
if [ ! -d "services/$SERVICE" ]; then
echo "❌ Service $SERVICE not found"
exit 1
@@ -19,7 +23,8 @@ echo "🌱 Seeding database for $SERVICE..."
cd "services/$SERVICE"
# Check if DATABASE_URL is set
# EN: Check if DATABASE_URL is set
# VI: Kiểm tra DATABASE_URL đã được thiết lập chưa
if [ -z "$DATABASE_URL" ]; then
if [ -f ".env" ]; then
export $(grep -v '^#' .env | xargs)

View File

@@ -13,7 +13,8 @@ NC='\033[0m' # No Color
echo -e "${YELLOW}This script helps you set up Neon database for all environments.${NC}"
echo ""
# Check if .env.local exists
# 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..."
@@ -36,7 +37,8 @@ echo ""
read -p "Enter development DATABASE_URL (main branch): " dev_url
if [ -n "$dev_url" ]; then
# Update .env.local
# 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"