-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-line-signup-tables.sh
More file actions
executable file
·231 lines (197 loc) · 11.2 KB
/
deploy-line-signup-tables.sh
File metadata and controls
executable file
·231 lines (197 loc) · 11.2 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
###############################################################################
# LINE Signup Tables Deployment Script
# Purpose: สร้างตาราง line_signup_* ทั้งหมด (8 ตาราง)
# Version: 1.0.0
# Date: 2025-11-17
###############################################################################
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ LINE Signup Tables Deployment Script ║"
echo "║ กำลังสร้างตาราง line_signup_* (8 ตาราง) ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Function to print colored messages
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if we're in the right directory
if [ ! -f "artisan" ]; then
print_error "ไม่พบไฟล์ artisan - กรุณารันสคริปต์นี้จาก root directory ของ Laravel"
exit 1
fi
print_success "พบไฟล์ artisan - อยู่ใน Laravel root directory"
# Check PHP version
print_info "ตรวจสอบ PHP version..."
PHP_VERSION=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1 -d"-")
print_success "PHP version: $PHP_VERSION"
# Check if migration file exists
MIGRATION_FILE="database/migrations/2025_11_12_000001_create_line_membership_signup_system.php"
if [ ! -f "$MIGRATION_FILE" ]; then
print_error "ไม่พบไฟล์ migration: $MIGRATION_FILE"
exit 1
fi
print_success "พบไฟล์ migration: $MIGRATION_FILE"
# Check database connection
print_info "ตรวจสอบการเชื่อมต่อฐานข้อมูล..."
if php artisan db:show >/dev/null 2>&1; then
print_success "เชื่อมต่อฐานข้อมูลสำเร็จ"
else
print_error "ไม่สามารถเชื่อมต่อฐานข้อมูลได้"
print_warning "กรุณาตรวจสอบการตั้งค่าใน .env:"
print_warning " - DB_HOST"
print_warning " - DB_DATABASE"
print_warning " - DB_USERNAME"
print_warning " - DB_PASSWORD"
exit 1
fi
# Get database name
DB_NAME=$(php artisan tinker --execute="echo config('database.connections.mysql.database');" 2>/dev/null || echo "unknown")
print_info "ฐานข้อมูล: $DB_NAME"
# Check if tables already exist
print_info "ตรวจสอบว่าตารางมีอยู่แล้วหรือไม่..."
TABLES_EXIST=0
for table in line_signup_sessions line_signup_step_logs line_signup_conversations line_signup_templates line_signup_rewards line_signup_invitations line_signup_analytics line_signup_webhook_logs; do
if php artisan tinker --execute="echo \Illuminate\Support\Facades\Schema::hasTable('$table') ? 'yes' : 'no';" 2>/dev/null | grep -q "yes"; then
print_warning "ตาราง $table มีอยู่แล้ว"
TABLES_EXIST=$((TABLES_EXIST + 1))
fi
done
if [ $TABLES_EXIST -eq 8 ]; then
print_success "ตารางทั้งหมดมีอยู่แล้ว (8/8)"
print_info "ไม่จำเป็นต้องรัน migration อีก"
echo ""
print_info "หากต้องการสร้างใหม่ กรุณารัน:"
echo " php artisan migrate:rollback --step=1"
echo " php artisan migrate --force"
exit 0
fi
# Backup database (optional)
print_warning "คำแนะนำ: ควร backup ฐานข้อมูลก่อนรัน migration"
read -p "ต้องการ backup ฐานข้อมูลก่อนหรือไม่? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
BACKUP_FILE="backup_before_line_signup_$(date +%Y%m%d_%H%M%S).sql"
print_info "กำลัง backup ฐานข้อมูลไปที่ storage/backups/$BACKUP_FILE..."
mkdir -p storage/backups
if command_exists mysqldump; then
DB_HOST=$(php artisan tinker --execute="echo config('database.connections.mysql.host');" 2>/dev/null || echo "127.0.0.1")
DB_USER=$(php artisan tinker --execute="echo config('database.connections.mysql.username');" 2>/dev/null || echo "root")
DB_PASS=$(php artisan tinker --execute="echo config('database.connections.mysql.password');" 2>/dev/null || echo "")
if [ -z "$DB_PASS" ]; then
mysqldump -h "$DB_HOST" -u "$DB_USER" "$DB_NAME" > "storage/backups/$BACKUP_FILE" 2>/dev/null || print_warning "ไม่สามารถ backup ได้ แต่จะดำเนินการต่อ"
else
mysqldump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "storage/backups/$BACKUP_FILE" 2>/dev/null || print_warning "ไม่สามารถ backup ได้ แต่จะดำเนินการต่อ"
fi
if [ -f "storage/backups/$BACKUP_FILE" ]; then
print_success "Backup สำเร็จ: storage/backups/$BACKUP_FILE"
fi
else
print_warning "ไม่พบคำสั่ง mysqldump - ข้าม backup"
fi
fi
# Clear caches
print_info "Clear caches..."
php artisan config:clear
php artisan cache:clear
php artisan route:clear
print_success "Caches cleared"
# Run migration
echo ""
print_info "═══════════════════════════════════════════════════════════════"
print_info "กำลังรัน Migration สร้างตาราง LINE Signup (8 ตาราง)..."
print_info "═══════════════════════════════════════════════════════════════"
echo ""
if php artisan migrate --force 2>&1; then
echo ""
print_success "═══════════════════════════════════════════════════════════════"
print_success "Migration สำเร็จ! ตารางถูกสร้างเรียบร้อยแล้ว"
print_success "═══════════════════════════════════════════════════════════════"
echo ""
else
echo ""
print_error "═══════════════════════════════════════════════════════════════"
print_error "Migration ล้มเหลว!"
print_error "═══════════════════════════════════════════════════════════════"
echo ""
print_warning "กรุณาตรวจสอบ error messages ด้านบน"
exit 1
fi
# Verify tables
print_info "ตรวจสอบว่าตารางถูกสร้างแล้ว..."
echo ""
TABLES_CREATED=0
for table in line_signup_sessions line_signup_step_logs line_signup_conversations line_signup_templates line_signup_rewards line_signup_invitations line_signup_analytics line_signup_webhook_logs; do
if php artisan tinker --execute="echo \Illuminate\Support\Facades\Schema::hasTable('$table') ? 'yes' : 'no';" 2>/dev/null | grep -q "yes"; then
print_success "✓ ตาราง $table ถูกสร้างแล้ว"
TABLES_CREATED=$((TABLES_CREATED + 1))
else
print_error "✗ ตาราง $table ไม่พบ"
fi
done
echo ""
if [ $TABLES_CREATED -eq 8 ]; then
print_success "════════════════════════════════════════════════════════════════"
print_success " ✅ สำเร็จ! ตารางทั้งหมดถูกสร้างแล้ว ($TABLES_CREATED/8)"
print_success "════════════════════════════════════════════════════════════════"
else
print_warning "════════════════════════════════════════════════════════════════"
print_warning " ⚠️ พบตารางเพียง $TABLES_CREATED/8 ตาราง"
print_warning "════════════════════════════════════════════════════════════════"
fi
# Optional: Run seeders
echo ""
read -p "ต้องการรัน Seeder สำหรับข้อมูลทดสอบหรือไม่? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_info "กำลังรัน Seeders..."
php artisan db:seed --class=LineSignupTemplateSeeder --force
php artisan db:seed --class=LineSignupFlowSeeder --force
php artisan db:seed --class=LineSignupSessionSeeder --force
print_success "Seeders รันสำเร็จ"
fi
# Final summary
echo ""
print_success "╔════════════════════════════════════════════════════════════════╗"
print_success "║ 🎉 Deployment Complete! 🎉 ║"
print_success "╚════════════════════════════════════════════════════════════════╝"
echo ""
print_info "ตารางที่ถูกสร้าง:"
echo " 1. ✅ line_signup_sessions"
echo " 2. ✅ line_signup_step_logs"
echo " 3. ✅ line_signup_conversations"
echo " 4. ✅ line_signup_templates"
echo " 5. ✅ line_signup_rewards"
echo " 6. ✅ line_signup_invitations"
echo " 7. ✅ line_signup_analytics"
echo " 8. ✅ line_signup_webhook_logs"
echo ""
print_info "ขั้นตอนถัดไป:"
echo " 1. ทดสอบ Admin Dashboard:"
echo " → https://member123.thaiprompt.online/admin/line-membership-signup"
echo ""
echo " 2. Setup LINE Rich Menu (optional):"
echo " → php artisan line:setup-signup-richmenu --set-default"
echo ""
print_success "ระบบพร้อมใช้งาน 100%! 🚀"
echo ""