-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-missing-line-tables.sh
More file actions
executable file
Β·219 lines (202 loc) Β· 9.17 KB
/
fix-missing-line-tables.sh
File metadata and controls
executable file
Β·219 lines (202 loc) Β· 9.17 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
#!/bin/bash
###############################################################################
# Fix LINE Signup Tables - Create Missing Tables Manually
# Purpose: ΰΈͺΰΈ£ΰΉΰΈ²ΰΈΰΈΰΈ²ΰΈ£ΰΈ²ΰΈΰΈΰΈ΅ΰΉΰΈ«ΰΈ²ΰΈ’ΰΉΰΈ 6 ΰΈΰΈ²ΰΈ£ΰΈ²ΰΈ (line_signup_step_logs ΰΉΰΈ₯ΰΈ°ΰΈΰΈ·ΰΉΰΈΰΉ)
# Version: 1.0.0
# Date: 2025-11-17
###############################################################################
set -e
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β Fix Missing LINE Signup Tables β"
echo "β ΰΈΰΈ³ΰΈ₯ΰΈ±ΰΈΰΈͺΰΈ£ΰΉΰΈ²ΰΈΰΈΰΈ²ΰΈ£ΰΈ²ΰΈΰΈΰΈ΅ΰΉΰΈ«ΰΈ²ΰΈ’ΰΉΰΈ 6 ΰΈΰΈ²ΰΈ£ΰΈ²ΰΈ β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Create missing tables using raw SQL
php artisan tinker --execute="
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
echo 'π§ Creating missing tables...' . PHP_EOL . PHP_EOL;
// 1. line_signup_step_logs
if (!Schema::hasTable('line_signup_step_logs')) {
DB::statement(\"
CREATE TABLE line_signup_step_logs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
session_id BIGINT UNSIGNED NOT NULL,
step_name VARCHAR(255) NOT NULL,
status ENUM('started', 'completed', 'skipped', 'failed') DEFAULT 'started',
step_data JSON NULL,
error_message TEXT NULL,
attempts INT NOT NULL DEFAULT 1,
started_at TIMESTAMP NOT NULL,
completed_at TIMESTAMP NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
KEY idx_session_step (session_id, step_name),
CONSTRAINT fk_step_logs_session
FOREIGN KEY (session_id)
REFERENCES line_signup_sessions(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_step_logs' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_step_logs' . PHP_EOL;
}
// 2. line_signup_conversations
if (!Schema::hasTable('line_signup_conversations')) {
DB::statement(\"
CREATE TABLE line_signup_conversations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
session_id BIGINT UNSIGNED NOT NULL,
role ENUM('user', 'assistant', 'system') NOT NULL,
message TEXT NOT NULL,
metadata JSON NULL,
message_type VARCHAR(255) DEFAULT 'text',
line_message_payload JSON NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
KEY idx_session_created (session_id, created_at),
CONSTRAINT fk_conversations_session
FOREIGN KEY (session_id)
REFERENCES line_signup_sessions(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_conversations' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_conversations' . PHP_EOL;
}
// 3. line_signup_analytics
if (!Schema::hasTable('line_signup_analytics')) {
DB::statement(\"
CREATE TABLE line_signup_analytics (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
date DATE NOT NULL,
step_name VARCHAR(255) NOT NULL,
visitors INT NOT NULL DEFAULT 0,
completions INT NOT NULL DEFAULT 0,
drop_offs INT NOT NULL DEFAULT 0,
average_time_seconds DECIMAL(10,2) NOT NULL DEFAULT 0,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
UNIQUE KEY uk_date_step (date, step_name),
KEY idx_date (date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_analytics' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_analytics' . PHP_EOL;
}
// 4. line_signup_rewards
if (!Schema::hasTable('line_signup_rewards')) {
DB::statement(\"
CREATE TABLE line_signup_rewards (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
session_id BIGINT UNSIGNED NOT NULL,
reward_type VARCHAR(255) NOT NULL,
reward_name VARCHAR(255) NOT NULL,
reward_amount DECIMAL(15,2) NOT NULL DEFAULT 0,
reward_description TEXT NULL,
status ENUM('pending', 'granted', 'claimed', 'expired') DEFAULT 'pending',
granted_at TIMESTAMP NULL,
claimed_at TIMESTAMP NULL,
expires_at TIMESTAMP NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
KEY idx_user_status (user_id, status),
CONSTRAINT fk_rewards_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE,
CONSTRAINT fk_rewards_session
FOREIGN KEY (session_id)
REFERENCES line_signup_sessions(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_rewards' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_rewards' . PHP_EOL;
}
// 5. line_signup_invitations
if (!Schema::hasTable('line_signup_invitations')) {
DB::statement(\"
CREATE TABLE line_signup_invitations (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
inviter_user_id BIGINT UNSIGNED NOT NULL,
invitation_token VARCHAR(255) NOT NULL UNIQUE,
line_user_id VARCHAR(255) NULL,
referral_code VARCHAR(255) NOT NULL,
max_uses INT NOT NULL DEFAULT 1,
uses_count INT NOT NULL DEFAULT 0,
status ENUM('active', 'used', 'expired') DEFAULT 'active',
metadata JSON NULL,
expires_at TIMESTAMP NULL,
first_used_at TIMESTAMP NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
KEY idx_token_status (invitation_token, status),
KEY idx_referral_code (referral_code),
CONSTRAINT fk_invitations_user
FOREIGN KEY (inviter_user_id)
REFERENCES users(id)
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_invitations' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_invitations' . PHP_EOL;
}
// 6. line_signup_webhook_logs
if (!Schema::hasTable('line_signup_webhook_logs')) {
DB::statement(\"
CREATE TABLE line_signup_webhook_logs (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
line_user_id VARCHAR(255) NULL,
event_type VARCHAR(255) NOT NULL,
webhook_payload JSON NOT NULL,
response_payload JSON NULL,
processing_status ENUM('received', 'processing', 'completed', 'failed') DEFAULT 'received',
error_message TEXT NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
KEY idx_user_created (line_user_id, created_at),
KEY idx_event_type (event_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
\");
echo 'β
Created: line_signup_webhook_logs' . PHP_EOL;
} else {
echo 'βοΈ Exists: line_signup_webhook_logs' . PHP_EOL;
}
echo PHP_EOL . 'β
All missing tables created successfully!' . PHP_EOL;
"
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " β
Done! Verifying tables..."
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
# Verify tables
php artisan tinker --execute="
use Illuminate\Support\Facades\Schema;
\$tables = [
'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',
];
echo 'Tables verification:' . PHP_EOL;
foreach (\$tables as \$table) {
\$exists = Schema::hasTable(\$table);
echo (\$exists ? 'β
' : 'β') . ' ' . \$table . PHP_EOL;
}
"
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β π Fix Complete! π β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""