feat(start.sh): add migrations and seed reset options

- Reorganize menu with sections: Services, Database, Testing
- Add option 4: Run Migrations (psql each migration file)
- Add option 6: Seed Reset with confirmation prompt
- Renumber tests to option 7
This commit is contained in:
Tiago Yamamoto 2025-12-24 10:44:07 -03:00
parent bb408b5c87
commit db1a9b9edc

View file

@ -27,14 +27,21 @@ echo -e "${NC}"
# Interactive menu
echo -e "${GREEN}Select an option:${NC}\n"
echo -e " ${CYAN}── Services ──${NC}"
echo -e " ${YELLOW}1)${NC} 🚀 Start (Frontend + Backend)"
echo -e " ${YELLOW}2)${NC} 🌱 Start with Seed (Reset DB + Seed + Start)"
echo -e " ${YELLOW}3)${NC} 📦 Start All (Frontend + Backend + Backoffice)"
echo -e " ${YELLOW}4)${NC} 🧪 Run Tests (Backend E2E)"
echo -e " ${YELLOW}5)${NC} 🌿 Seed Only (No restart)"
echo -e ""
echo -e " ${CYAN}── Database ──${NC}"
echo -e " ${YELLOW}4)${NC} 🗄️ Run Migrations"
echo -e " ${YELLOW}5)${NC} 🌿 Seed Only (append data)"
echo -e " ${YELLOW}6)${NC} 🔄 Seed Reset (drop all + seed fresh)"
echo -e ""
echo -e " ${CYAN}── Testing ──${NC}"
echo -e " ${YELLOW}7)${NC} 🧪 Run Tests (Backend E2E)"
echo -e " ${YELLOW}0)${NC} ❌ Exit"
echo ""
read -p "Enter option [1-5, 0]: " choice
read -p "Enter option [0-7]: " choice
case $choice in
1)
@ -156,9 +163,27 @@ case $choice in
;;
4)
echo -e "\n${GREEN}🧪 Running Backend E2E Tests...${NC}\n"
cd backend && go test -tags=e2e -v ./tests/e2e/... 2>&1
echo -e "\n${GREEN}✅ Tests completed!${NC}"
echo -e "\n${GREEN}🗄️ Running Migrations...${NC}\n"
cd backend
# Load DB config from .env
if [ -f .env ]; then
source .env
fi
DB_HOST=${DB_HOST:-localhost}
DB_PORT=${DB_PORT:-5432}
DB_USER=${DB_USER:-postgres}
DB_NAME=${DB_NAME:-gohorsejobs}
echo -e "${BLUE}🔹 Connecting to ${DB_HOST}:${DB_PORT}/${DB_NAME}...${NC}"
for file in migrations/*.sql; do
echo -e "${YELLOW}🔹 Running: $(basename $file)${NC}"
PGPASSWORD=$DB_PASSWORD psql -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME -f "$file" 2>&1 | head -5
done
echo -e "\n${GREEN}✅ Migrations completed!${NC}"
;;
5)
@ -169,6 +194,28 @@ case $choice in
echo -e "\n${GREEN}✅ Seeding completed!${NC}"
;;
6)
echo -e "\n${GREEN}🔄 Resetting Database & Seeding Fresh...${NC}\n"
cd seeder-api
[ ! -d "node_modules" ] && npm install
echo -e "${YELLOW}⚠️ This will DROP all tables and recreate!${NC}"
read -p "Are you sure? [y/N]: " confirm
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then
npm run seed:reset
echo -e "\n${GREEN}✅ Database reset and seeded!${NC}"
else
echo -e "${YELLOW}Cancelled.${NC}"
fi
;;
7)
echo -e "\n${GREEN}🧪 Running Backend E2E Tests...${NC}\n"
cd backend && go test -tags=e2e -v ./tests/e2e/... 2>&1
echo -e "\n${GREEN}✅ Tests completed!${NC}"
;;
0)
echo -e "${YELLOW}Bye! 👋${NC}"
exit 0
@ -179,3 +226,4 @@ case $choice in
exit 1
;;
esac