refactor: migrate patch test schema from service-level to dedicated tables

- Remove patch_test_duration_hours from services table
- Add new patch_tests table with service_ids array, notice_duration_hours, expiry_months
- Add new user_patch_tests table linking users to patch_tests with tested_at
- Update services handler to check patch_tests.service_ids for eligibility
- Update booking creation to validate patch test requirements (24h notice, 6mo expiry)
- Update booking completion to extend patch test validity (reset tested_at)
- Update admin handlers for new patch test CRUD operations
- Update test fixtures and test cases for new schema
- Update seeding script to create patch_tests and link to gel services
This commit is contained in:
2026-02-24 22:17:50 +00:00
parent f59595eeec
commit c6fe9e92a7
5 changed files with 173 additions and 443 deletions
+28 -14
View File
@@ -290,14 +290,14 @@ sleep 1
# 3. Create Services
echo -e "\n${C_BLUE}💅 Creating Services...${C_RESET}"
SERVICES=(
'{"name":"Classic Manicure","description":"Nail shaping, cuticle care, hand massage, and polish.","price":25.00,"duration_minutes":45,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Gel Manicure (BIAB)","description":"Hard-wearing gel polish with Builder In A Bottle base.","price":35.00,"duration_minutes":60,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Luxury Pedicure","description":"Foot soak, scrub, mask, extended massage, and polish.","price":45.00,"duration_minutes":75,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Express Mani & Pedi","description":"Quick file, shape, and polish for both hands and feet.","price":40.00,"duration_minutes":60,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Gel Polish Removal","description":"Safe removal of existing gel polish.","price":10.00,"duration_minutes":20,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Nail Art Add-on","description":"Custom nail art, per two fingers.","price":5.00,"duration_minutes":15,"patch_test_duration_hours":0,"minimum_age_required":0}'
'{"name":"Gel Polish Full Set","description":"Full gel polish application - requires patch test 48h before.","price":45.00,"duration_minutes":60,"patch_test_duration_hours":48,"minimum_age_required":0}'
'{"name":"Luxury Gel Manicure","description":"Premium gel polish with extended massage - requires patch test 48h before.","price":55.00,"duration_minutes":75,"patch_test_duration_hours":48,"minimum_age_required":0}'
'{"name":"Classic Manicure","description":"Nail shaping, cuticle care, hand massage, and polish.","price":25.00,"duration_minutes":45,"minimum_age_required":0}'
'{"name":"Gel Manicure (BIAB)","description":"Hard-wearing gel polish with Builder In A Bottle base.","price":35.00,"duration_minutes":60,"minimum_age_required":0}'
'{"name":"Luxury Pedicure","description":"Foot soak, scrub, mask, extended massage, and polish.","price":45.00,"duration_minutes":75,"minimum_age_required":0}'
'{"name":"Express Mani & Pedi","description":"Quick file, shape, and polish for both hands and feet.","price":40.00,"duration_minutes":60,"minimum_age_required":0}'
'{"name":"Gel Polish Removal","description":"Safe removal of existing gel polish.","price":10.00,"duration_minutes":20,"minimum_age_required":0}'
'{"name":"Nail Art Add-on","description":"Custom nail art, per two fingers.","price":5.00,"duration_minutes":15,"minimum_age_required":0}'
'{"name":"Gel Polish Full Set","description":"Full gel polish application - requires patch test 24h before.","price":45.00,"duration_minutes":60,"minimum_age_required":0}'
'{"name":"Luxury Gel Manicure","description":"Premium gel polish with extended massage - requires patch test 24h before.","price":55.00,"duration_minutes":75,"minimum_age_required":0}'
)
SERVICE_IDS=()
@@ -315,6 +315,26 @@ for svc in "${SERVICES[@]}"; do
done
echo "${C_GREEN}✅ Created $success/$total Services${C_RESET}"
# 3b. Create Patch Tests (for gel services that require testing)
echo -e "\n${C_BLUE}🧪 Creating Patch Tests...${C_RESET}"
# Get the gel service IDs (indices 6 and 7)
GEL_SERVICE_IDS=("${SERVICE_IDS[6]}" "${SERVICE_IDS[7]}")
# Create patch test linking to gel services
docker exec postgres psql -U myuser -d mydb -c "
INSERT INTO patch_tests (name, description, notice_duration_hours, expiry_months, service_ids)
VALUES (
'Gel Allergy Test',
'Patch test for gel polish products - must be completed 24h before first gel service',
24,
6,
ARRAY['${GEL_SERVICE_IDS[0]}', '${GEL_SERVICE_IDS[1]}']
);
" > /dev/null 2>&1
echo "${C_GREEN}✅ Created patch test for gel services${C_RESET}"
# 4. Create Bookings
echo -e "\n${C_BLUE}📅 Creating Bookings...${C_RESET}"
@@ -485,12 +505,6 @@ if api_post "$BASE_URL/scheduling/exceptional-groups" "$NOV_BREAK" "November Bre
if api_post "$BASE_URL/scheduling/exceptional-groups" "$XMAS_BREAK" "Christmas Holiday" "$ADMIN_TOKEN" > /dev/null; then success=$((success+1)); fi
echo "${C_GREEN}✅ Created $success/$total Exceptional Groups${C_RESET}"
# --- UPDATE DB PANE STATS ---
if [ -n "$SESSION_NAME" ]; then
echo -e "\n⏳ Updating DB pane stats..."
tmux send-keys -t "$SESSION_NAME:0.0" 'SELECT relname AS table_name, n_live_tup AS row_count FROM pg_stat_user_tables ORDER BY table_name\;'
fi
echo -e "\n${C_GREEN}🎉 Seeding Complete!${C_RESET}"
echo -e "${C_YELLOW}Press ENTER to run tests...${C_RESET}"
read -r