File size: 2,812 Bytes
fdd1575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82c1146
 
fdd1575
 
 
82c1146
fdd1575
 
 
 
 
 
 
 
 
82c1146
fdd1575
 
 
 
82c1146
fdd1575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82c1146
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash

# ============================================================================
# SmartEye OCR Database Reset Script (v2.1)
# ============================================================================
# κΈ°λŠ₯:
# - Docker MySQL μ»¨ν…Œμ΄λ„ˆμ—μ„œ DB μ™„μ „ μ΄ˆκΈ°ν™”
# - init_db_complete.sql μžλ™ μ‹€ν–‰ (ν…Œμ΄λΈ” + 초기 데이터)
# - combined_text: MEDIUMTEXT (16MB 지원)
# ============================================================================

set -e  # μ—λŸ¬ μ‹œ μ¦‰μ‹œ 쀑단

# 색상 μ •μ˜
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${YELLOW}======================================${NC}"
echo -e "${YELLOW}SmartEye OCR Database Reset${NC}"
echo -e "${YELLOW}======================================${NC}"

# 1. Docker μ»¨ν…Œμ΄λ„ˆ 확인
CONTAINER_NAME="smart_mysql"
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo -e "${RED}Error: Docker container '${CONTAINER_NAME}' is not running${NC}"
    echo -e "${YELLOW}Please start with: cd Backend && docker-compose up -d${NC}"
    exit 1
fi

# 2. 슀크립트 경둜 확인
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SQL_FILE="${SCRIPT_DIR}/init_db_complete.sql"

if [ ! -f "$SQL_FILE" ]; then
    echo -e "${RED}Error: $SQL_FILE not found${NC}"
    exit 1
fi

# 3. μ‚¬μš©μž 확인
echo -e "${YELLOW}⚠️  Warning: This will DELETE all existing data!${NC}"
echo -e "${YELLOW}Database: smarteyessen_db${NC}"
read -p "Continue? (yes/no): " confirm

if [ "$confirm" != "yes" ]; then
    echo -e "${GREEN}Cancelled.${NC}"
    exit 0
fi

# 4. DB μ΄ˆκΈ°ν™” μ‹€ν–‰
echo -e "${GREEN}Resetting database...${NC}"
docker exec -i ${CONTAINER_NAME} mysql -u root -p1q2w3e4r < "$SQL_FILE"

if [ $? -eq 0 ]; then
    echo -e "${GREEN}======================================${NC}"
    echo -e "${GREEN}βœ… Database reset completed!${NC}"
    echo -e "${GREEN}======================================${NC}"
    echo ""
    echo "πŸ“‹ Created tables:"
    echo "  - users, document_types, projects, pages"
    echo "  - layout_elements, text_contents, ai_descriptions"
    echo "  - question_groups, question_elements"
    echo "  - text_versions, formatting_rules"
    echo "  - combined_results (LONGTEXT, up to 4GB)"
    echo ""
    echo "οΏ½ Initial data:"
    echo "  - 2 document types (worksheet, document)"
    echo "  - 25+ formatting rules (auto-generated)"
    echo ""
    echo "πŸš€ Next steps:"
    echo "  1. Start backend: uvicorn Backend.app.main:app --reload"
    echo "  2. Check health: curl http://localhost:8000/health"
else
    echo -e "${RED}❌ Database reset failed!${NC}"
    exit 1
fi

echo "βœ… Table initialization complete."

echo "πŸŽ‰ Database reset finished. You can now rerun backend services or seed data as needed."