diff --git a/start.sh b/start.sh index 30f9d40..a46a049 100755 --- a/start.sh +++ b/start.sh @@ -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 +