ts-glitter 22.3.5 → 22.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,71 +15,22 @@ export class ApiPublic {
15
15
  //301轉址
16
16
  public static app301: { app_name: string; router: { legacy_url: string; new_url: string }[] }[] = [];
17
17
 
18
- public static async createScheme(appName: string) {
19
- //已通過則直接回傳執行
20
- if (
21
- ApiPublic.checkedApp.find(dd => {
22
- return dd.app_name === appName;
23
- })
24
- ) {
25
- return;
26
- }
27
-
28
- //已經正在檢查中的話,等檢查結束
29
- if (
30
- ApiPublic.checkingApp.find(dd => {
31
- return dd.app_name === appName;
32
- })
33
- ) {
34
- const result = await new Promise(resolve => {
35
- const interval = setInterval(() => {
36
- if (
37
- ApiPublic.checkedApp.find(dd => {
38
- return dd.app_name === appName;
39
- })
40
- ) {
41
- resolve(true);
42
- clearInterval(interval);
43
- } else if (
44
- !ApiPublic.checkingApp.find(dd => {
45
- return dd.app_name === appName;
46
- })
47
- ) {
48
- resolve(false);
49
- clearInterval(interval);
50
- }
51
- }, 500);
52
- });
53
- if (result) {
54
- return;
55
- }
56
- }
57
- ApiPublic.checkingApp.push({
58
- app_name: appName,
59
- refer_app: (
60
- await db.query(
61
- `select refer_app
62
- from \`${saasConfig.SAAS_NAME}\`.app_config
63
- where appName = ?`,
64
- [appName]
65
- )
66
- )[0]['refer_app'],
67
- });
68
- try {
69
- await db.execute(
70
- `CREATE SCHEMA if not exists \`${appName}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`,
71
- []
72
- );
73
- await db.execute(
74
- `CREATE SCHEMA if not exists \`${appName}_recover\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`,
75
- []
76
- );
77
- const groupSize = 15;
78
- const sqlArray: { scheme?: string; table: string; sql: string }[] = [
79
- {
80
- scheme: appName,
81
- table: 't_chat_detail',
82
- sql: `(
18
+ //CreateTable
19
+ public static async createTable(appName:string){
20
+ const groupSize = 15;
21
+ await db.query(
22
+ `CREATE SCHEMA if not exists \`${appName}\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`,
23
+ []
24
+ );
25
+ await db.query(
26
+ `CREATE SCHEMA if not exists \`${appName}_recover\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;`,
27
+ []
28
+ );
29
+ const sqlArray: { scheme?: string; table: string; sql: string }[] = [
30
+ {
31
+ scheme: appName,
32
+ table: 't_chat_detail',
33
+ sql: `(
83
34
  \`id\` int NOT NULL AUTO_INCREMENT,
84
35
  \`chat_id\` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
85
36
  \`user_id\` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -90,11 +41,11 @@ export class ApiPublic {
90
41
  KEY \`index3\` (\`user_id\`),
91
42
  KEY \`index4\` (\`created_time\`)
92
43
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
93
- },
94
- {
95
- scheme: appName,
96
- table: `t_invoice_memory`,
97
- sql: `(
44
+ },
45
+ {
46
+ scheme: appName,
47
+ table: `t_invoice_memory`,
48
+ sql: `(
98
49
  \`id\` int NOT NULL AUTO_INCREMENT,
99
50
  \`status\` int NOT NULL DEFAULT 1,
100
51
  \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -107,11 +58,11 @@ export class ApiPublic {
107
58
  KEY \`index4\` (\`create_date\`),
108
59
  KEY \`index5\` (\`status\`)
109
60
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
110
- },
111
- {
112
- scheme: appName,
113
- table: `t_allowance_memory`,
114
- sql: `(
61
+ },
62
+ {
63
+ scheme: appName,
64
+ table: `t_allowance_memory`,
65
+ sql: `(
115
66
  \`id\` int NOT NULL AUTO_INCREMENT,
116
67
  \`status\` int NOT NULL DEFAULT 1,
117
68
  \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -125,39 +76,39 @@ export class ApiPublic {
125
76
  KEY \`index4\` (\`create_date\`),
126
77
  KEY \`index5\` (\`status\`)
127
78
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
128
- },
129
- // {
130
- // scheme: appName,
131
- // table: `t_invoice_credit`,
132
- // sql: `(
133
- // \`id\` int NOT NULL AUTO_INCREMENT,
134
- // \`status\` int NOT NULL DEFAULT 1,
135
- // \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
136
- // \`invoice_no\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
137
- // \`invoice_data\` json DEFAULT NULL,
138
- // \`create_date\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
139
- // PRIMARY KEY (\`id\`),
140
- // KEY \`index2\` (\`order_id\`),
141
- // KEY \`index3\` (\`invoice_no\`),
142
- // KEY \`index4\` (\`create_date\`),
143
- // KEY \`index5\` (\`status\`)
144
- // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`
145
- // },
146
- {
147
- scheme: appName,
148
- table: 't_variants',
149
- sql: `(
79
+ },
80
+ // {
81
+ // scheme: appName,
82
+ // table: `t_invoice_credit`,
83
+ // sql: `(
84
+ // \`id\` int NOT NULL AUTO_INCREMENT,
85
+ // \`status\` int NOT NULL DEFAULT 1,
86
+ // \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
87
+ // \`invoice_no\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
88
+ // \`invoice_data\` json DEFAULT NULL,
89
+ // \`create_date\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
90
+ // PRIMARY KEY (\`id\`),
91
+ // KEY \`index2\` (\`order_id\`),
92
+ // KEY \`index3\` (\`invoice_no\`),
93
+ // KEY \`index4\` (\`create_date\`),
94
+ // KEY \`index5\` (\`status\`)
95
+ // ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`
96
+ // },
97
+ {
98
+ scheme: appName,
99
+ table: 't_variants',
100
+ sql: `(
150
101
  \`id\` int NOT NULL AUTO_INCREMENT,
151
102
  \`product_id\` int DEFAULT NULL,
152
103
  \`content\` json NOT NULL,
153
104
  PRIMARY KEY (\`id\`),
154
105
  KEY \`index2\` (\`product_id\`)
155
106
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
156
- },
157
- {
158
- scheme: appName,
159
- table: 't_recommend_users',
160
- sql: `(
107
+ },
108
+ {
109
+ scheme: appName,
110
+ table: 't_recommend_users',
111
+ sql: `(
161
112
  \`id\` int NOT NULL AUTO_INCREMENT,
162
113
  \`email\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
163
114
  \`content\` json NOT NULL,
@@ -165,11 +116,11 @@ export class ApiPublic {
165
116
  PRIMARY KEY (\`id\`),
166
117
  UNIQUE KEY \`email_UNIQUE\` (\`email\`)
167
118
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
168
- },
169
- {
170
- scheme: appName,
171
- table: 't_recommend_links',
172
- sql: `(
119
+ },
120
+ {
121
+ scheme: appName,
122
+ table: 't_recommend_links',
123
+ sql: `(
173
124
  \`id\` int NOT NULL AUTO_INCREMENT,
174
125
  \`code\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
175
126
  \`content\` json NOT NULL,
@@ -177,11 +128,11 @@ export class ApiPublic {
177
128
  PRIMARY KEY (\`id\`),
178
129
  UNIQUE KEY \`code_UNIQUE\` (\`code\`)
179
130
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
180
- },
181
- {
182
- scheme: appName,
183
- table: 't_triggers',
184
- sql: `(
131
+ },
132
+ {
133
+ scheme: appName,
134
+ table: 't_triggers',
135
+ sql: `(
185
136
  \`id\` int NOT NULL AUTO_INCREMENT,
186
137
  \`tag\` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
187
138
  \`content\` json NOT NULL,
@@ -189,11 +140,11 @@ export class ApiPublic {
189
140
  \`status\` int NOT NULL DEFAULT '1',
190
141
  PRIMARY KEY (\`id\`)
191
142
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
192
- },
193
- {
194
- scheme: appName,
195
- table: 't_api_router',
196
- sql: `(
143
+ },
144
+ {
145
+ scheme: appName,
146
+ table: 't_api_router',
147
+ sql: `(
197
148
  \`id\` int NOT NULL AUTO_INCREMENT,
198
149
  \`name\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
199
150
  \`port\` int NOT NULL,
@@ -205,11 +156,11 @@ export class ApiPublic {
205
156
  UNIQUE KEY \`name_UNIQUE\` (\`name\`),
206
157
  UNIQUE KEY \`port_UNIQUE\` (\`port\`)
207
158
  ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
208
- },
209
- {
210
- scheme: appName,
211
- table: `t_domain_setting`,
212
- sql: `(
159
+ },
160
+ {
161
+ scheme: appName,
162
+ table: `t_domain_setting`,
163
+ sql: `(
213
164
  \`id\` int NOT NULL AUTO_INCREMENT,
214
165
  \`domain\` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
215
166
  \`port\` int NOT NULL,
@@ -218,11 +169,11 @@ export class ApiPublic {
218
169
  UNIQUE KEY \`domain_UNIQUE\` (\`domain\`),
219
170
  UNIQUE KEY \`port_UNIQUE\` (\`port\`)
220
171
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
221
- },
222
- {
223
- scheme: appName,
224
- table: 'public_config',
225
- sql: ` (
172
+ },
173
+ {
174
+ scheme: appName,
175
+ table: 'public_config',
176
+ sql: ` (
226
177
  \`id\` int NOT NULL AUTO_INCREMENT,
227
178
  \`key\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
228
179
  \`value\` json NOT NULL,
@@ -230,11 +181,11 @@ export class ApiPublic {
230
181
  PRIMARY KEY (\`id\`),
231
182
  UNIQUE KEY \`index2\` (\`key\`)
232
183
  ) ENGINE=InnoDB AUTO_INCREMENT=295 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
233
- },
234
- {
235
- scheme: appName,
236
- table: 't_user_public_config',
237
- sql: ` (
184
+ },
185
+ {
186
+ scheme: appName,
187
+ table: 't_user_public_config',
188
+ sql: ` (
238
189
  \`id\` int NOT NULL AUTO_INCREMENT,
239
190
  \`user_id\` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL,
240
191
  \`key\` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -243,11 +194,11 @@ export class ApiPublic {
243
194
  PRIMARY KEY (\`id\`),
244
195
  UNIQUE KEY \`index2\` (\`user_id\`,\`key\`)
245
196
  ) ENGINE=InnoDB AUTO_INCREMENT=309 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
246
- },
247
- {
248
- scheme: appName,
249
- table: 't_chat_list',
250
- sql: ` (
197
+ },
198
+ {
199
+ scheme: appName,
200
+ table: 't_chat_list',
201
+ sql: ` (
251
202
  \`id\` int NOT NULL AUTO_INCREMENT,
252
203
  \`chat_id\` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
253
204
  \`type\` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'user',
@@ -259,11 +210,11 @@ export class ApiPublic {
259
210
  KEY \`index3\` (\`type\`),
260
211
  KEY \`index4\` (\`updated_time\`)
261
212
  ) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
262
- },
263
- {
264
- scheme: appName,
265
- table: 't_chat_participants',
266
- sql: `(
213
+ },
214
+ {
215
+ scheme: appName,
216
+ table: 't_chat_participants',
217
+ sql: `(
267
218
  \`id\` int NOT NULL AUTO_INCREMENT,
268
219
  \`chat_id\` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
269
220
  \`user_id\` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -272,11 +223,11 @@ export class ApiPublic {
272
223
  PRIMARY KEY (\`id\`),
273
224
  UNIQUE KEY \`index2\` (\`chat_id\`,\`user_id\`)
274
225
  ) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
275
- },
276
- {
277
- scheme: appName,
278
- table: 't_post',
279
- sql: `(
226
+ },
227
+ {
228
+ scheme: appName,
229
+ table: 't_post',
230
+ sql: `(
280
231
  \`id\` int NOT NULL AUTO_INCREMENT,
281
232
  \`userID\` int NOT NULL,
282
233
  \`content\` json DEFAULT NULL,
@@ -285,11 +236,11 @@ export class ApiPublic {
285
236
  PRIMARY KEY (\`id\`),
286
237
  KEY \`index2\` (\`userID\`)
287
238
  ) ENGINE=InnoDB AUTO_INCREMENT=287 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
288
- },
289
- {
290
- scheme: appName,
291
- table: 't_manager_post',
292
- sql: ` (
239
+ },
240
+ {
241
+ scheme: appName,
242
+ table: 't_manager_post',
243
+ sql: ` (
293
244
  \`id\` int NOT NULL AUTO_INCREMENT,
294
245
  \`userID\` int NOT NULL,
295
246
  \`content\` json DEFAULT NULL,
@@ -299,12 +250,12 @@ export class ApiPublic {
299
250
  PRIMARY KEY (\`id\`),
300
251
  KEY \`index2\` (\`userID\`)
301
252
  ) ENGINE=InnoDB AUTO_INCREMENT=287 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
302
- },
253
+ },
303
254
 
304
- {
305
- scheme: appName,
306
- table: 't_user',
307
- sql: `(
255
+ {
256
+ scheme: appName,
257
+ table: 't_user',
258
+ sql: `(
308
259
  \`id\` int NOT NULL AUTO_INCREMENT,
309
260
  \`userID\` int NOT NULL,
310
261
  \`account\` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -325,12 +276,12 @@ export class ApiPublic {
325
276
  KEY \`index4\` (\`status\`),
326
277
  KEY \`index7\` (\`member_level\`)
327
278
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='V1.2'`,
328
- },
279
+ },
329
280
 
330
- {
331
- scheme: appName,
332
- table: 't_checkout',
333
- sql: `(
281
+ {
282
+ scheme: appName,
283
+ table: 't_checkout',
284
+ sql: `(
334
285
  \`id\` int NOT NULL AUTO_INCREMENT,
335
286
  \`cart_token\` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
336
287
  \`status\` int NOT NULL DEFAULT '0',
@@ -383,11 +334,11 @@ export class ApiPublic {
383
334
  KEY \`index23\` (\`shipment_phone\`),
384
335
  KEY \`index24\` (\`shipment_address\`)
385
336
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='V1.9'`,
386
- },
387
- {
388
- scheme: appName,
389
- table: 't_voucher_history',
390
- sql: `(
337
+ },
338
+ {
339
+ scheme: appName,
340
+ table: 't_voucher_history',
341
+ sql: `(
391
342
  \`id\` int NOT NULL AUTO_INCREMENT,
392
343
  \`user_id\` int NOT NULL COMMENT '會員id',
393
344
  \`order_id\` varchar(200) NOT NULL COMMENT '購物車id',
@@ -398,22 +349,22 @@ export class ApiPublic {
398
349
  PRIMARY KEY (\`id\`),
399
350
  UNIQUE KEY \`id_UNIQUE\` (\`id\`)
400
351
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
401
- },
402
- {
403
- scheme: appName,
404
- table: 't_subscribe',
405
- sql: `(
352
+ },
353
+ {
354
+ scheme: appName,
355
+ table: 't_subscribe',
356
+ sql: `(
406
357
  \`id\` int NOT NULL AUTO_INCREMENT,
407
358
  \`email\` varchar(105) COLLATE utf8mb4_unicode_ci NOT NULL,
408
359
  \`tag\` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
409
360
  PRIMARY KEY (\`id\`),
410
361
  UNIQUE KEY \`index2\` (\`email\`,\`tag\`)
411
362
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci `,
412
- },
413
- {
414
- scheme: appName,
415
- table: 't_fcm',
416
- sql: `(
363
+ },
364
+ {
365
+ scheme: appName,
366
+ table: 't_fcm',
367
+ sql: `(
417
368
  \`id\` INT NOT NULL AUTO_INCREMENT,
418
369
  \`userID\` VARCHAR(100) NULL,
419
370
  \`deviceToken\` VARCHAR(200) NULL,
@@ -422,11 +373,11 @@ export class ApiPublic {
422
373
  PRIMARY KEY (\`id\`)
423
374
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
424
375
  `,
425
- },
426
- {
427
- scheme: appName,
428
- table: 't_wallet',
429
- sql: ` (
376
+ },
377
+ {
378
+ scheme: appName,
379
+ table: 't_wallet',
380
+ sql: ` (
430
381
  \`id\` int NOT NULL AUTO_INCREMENT,
431
382
  \`orderID\` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
432
383
  \`userID\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -439,11 +390,11 @@ export class ApiPublic {
439
390
  KEY \`index2\` (\`userID\`),
440
391
  KEY \`index3\` (\`status\`)
441
392
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
442
- },
443
- {
444
- scheme: appName,
445
- table: 't_ai_points',
446
- sql: `(
393
+ },
394
+ {
395
+ scheme: appName,
396
+ table: 't_ai_points',
397
+ sql: `(
447
398
  \`id\` int NOT NULL AUTO_INCREMENT,
448
399
  \`orderID\` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
449
400
  \`userID\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -456,11 +407,11 @@ export class ApiPublic {
456
407
  KEY \`index2\` (\`userID\`),
457
408
  KEY \`index3\` (\`status\`)
458
409
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
459
- },
460
- {
461
- scheme: appName,
462
- table: 't_sms_points',
463
- sql: `(
410
+ },
411
+ {
412
+ scheme: appName,
413
+ table: 't_sms_points',
414
+ sql: `(
464
415
  \`id\` int NOT NULL AUTO_INCREMENT,
465
416
  \`orderID\` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
466
417
  \`userID\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -473,11 +424,11 @@ export class ApiPublic {
473
424
  KEY \`index2\` (\`userID\`),
474
425
  KEY \`index3\` (\`status\`)
475
426
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
476
- },
477
- {
478
- scheme: appName,
479
- table: 't_rebate_point',
480
- sql: `(
427
+ },
428
+ {
429
+ scheme: appName,
430
+ table: 't_rebate_point',
431
+ sql: `(
481
432
  \`id\` int NOT NULL AUTO_INCREMENT,
482
433
  \`user_id\` int NOT NULL COMMENT '用戶 ID',
483
434
  \`origin\` int NOT NULL COMMENT '原始點數',
@@ -489,11 +440,11 @@ export class ApiPublic {
489
440
  \`deadline\` datetime DEFAULT NULL COMMENT '過期時間',
490
441
  PRIMARY KEY (\`id\`)
491
442
  ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
492
- },
493
- {
494
- scheme: appName,
495
- table: 't_withdraw',
496
- sql: `(
443
+ },
444
+ {
445
+ scheme: appName,
446
+ table: 't_withdraw',
447
+ sql: `(
497
448
  \`id\` INT NOT NULL AUTO_INCREMENT,
498
449
  \`userID\` VARCHAR(45) NOT NULL,
499
450
  \`money\` INT NOT NULL DEFAULT 0,
@@ -502,11 +453,11 @@ export class ApiPublic {
502
453
  \`created_time\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
503
454
  PRIMARY KEY (\`id\`),
504
455
  INDEX \`index2\` (\`userID\` ASC) VISIBLE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`,
505
- },
506
- {
507
- scheme: appName,
508
- table: 't_global_event',
509
- sql: ` (
456
+ },
457
+ {
458
+ scheme: appName,
459
+ table: 't_global_event',
460
+ sql: ` (
510
461
  \`id\` INT NOT NULL AUTO_INCREMENT,
511
462
  \`tag\` VARCHAR(45) NOT NULL,
512
463
  \`name\` VARCHAR(45) NOT NULL,
@@ -515,11 +466,11 @@ export class ApiPublic {
515
466
  PRIMARY KEY (\`id\`),
516
467
  UNIQUE INDEX \`tag_UNIQUE\` (\`tag\` ASC) VISIBLE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
517
468
  `,
518
- },
519
- {
520
- scheme: appName,
521
- table: 't_stock_recover',
522
- sql: `(
469
+ },
470
+ {
471
+ scheme: appName,
472
+ table: 't_stock_recover',
473
+ sql: `(
523
474
  \`id\` int NOT NULL AUTO_INCREMENT,
524
475
  \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
525
476
  \`product_id\` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
@@ -531,11 +482,11 @@ export class ApiPublic {
531
482
  KEY \`index3\` (\`product_id\`)
532
483
  ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
533
484
  `,
534
- },
535
- {
536
- scheme: appName,
537
- table: 't_chat_last_read',
538
- sql: `(
485
+ },
486
+ {
487
+ scheme: appName,
488
+ table: 't_chat_last_read',
489
+ sql: `(
539
490
  \`id\` int NOT NULL AUTO_INCREMENT,
540
491
  \`user_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
541
492
  \`chat_id\` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -544,11 +495,11 @@ export class ApiPublic {
544
495
  UNIQUE KEY \`index2\` (\`user_id\`,\`chat_id\`)
545
496
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
546
497
  `,
547
- },
548
- {
549
- scheme: appName,
550
- table: 't_graph_api',
551
- sql: `(
498
+ },
499
+ {
500
+ scheme: appName,
501
+ table: 't_graph_api',
502
+ sql: `(
552
503
  \`id\` INT NOT NULL AUTO_INCREMENT,
553
504
  \`route\` VARCHAR(200) NOT NULL,
554
505
  \`method\` VARCHAR(45) NOT NULL,
@@ -557,11 +508,11 @@ export class ApiPublic {
557
508
  PRIMARY KEY (\`id\`),
558
509
  UNIQUE INDEX \`index2\` (\`route\` ASC, \`method\` ASC) VISIBLE);
559
510
  `,
560
- },
561
- {
562
- scheme: appName,
563
- table: `t_notice`,
564
- sql: `(
511
+ },
512
+ {
513
+ scheme: appName,
514
+ table: `t_notice`,
515
+ sql: `(
565
516
  \`id\` INT NOT NULL AUTO_INCREMENT,
566
517
  \`user_id\` VARCHAR(45) NOT NULL,
567
518
  \`tag\` VARCHAR(45) NOT NULL,
@@ -571,11 +522,11 @@ export class ApiPublic {
571
522
  \`created_time\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
572
523
  PRIMARY KEY (\`id\`),
573
524
  INDEX \`index2\` (\`user_id\` ASC) VISIBLE);`,
574
- },
575
- {
576
- scheme: appName,
577
- table: 't_return_order',
578
- sql: `(
525
+ },
526
+ {
527
+ scheme: appName,
528
+ table: 't_return_order',
529
+ sql: `(
579
530
  \`id\` int NOT NULL AUTO_INCREMENT,
580
531
  \`return_order_id\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
581
532
  \`order_id\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -588,11 +539,11 @@ export class ApiPublic {
588
539
  KEY \`index3\` (\`email\`),
589
540
  KEY \`index4\` (\`created_time\`)
590
541
  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
591
- },
592
- {
593
- scheme: appName,
594
- table: `t_stock_history`,
595
- sql: `(
542
+ },
543
+ {
544
+ scheme: appName,
545
+ table: `t_stock_history`,
546
+ sql: `(
596
547
  \`id\` int NOT NULL AUTO_INCREMENT,
597
548
  \`type\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
598
549
  \`order_id\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -603,11 +554,11 @@ export class ApiPublic {
603
554
  KEY \`index2\` (\`order_id\`),
604
555
  UNIQUE KEY \`order_id_UNIQUE\` (\`order_id\`)
605
556
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
606
- },
607
- {
608
- scheme: appName,
609
- table: `t_live_purchase_interactions`,
610
- sql: `(
557
+ },
558
+ {
559
+ scheme: appName,
560
+ table: `t_live_purchase_interactions`,
561
+ sql: `(
611
562
  \`id\` int NOT NULL AUTO_INCREMENT,
612
563
  \`type\` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
613
564
  \`name\` varchar(200) NOT NULL,
@@ -618,11 +569,11 @@ export class ApiPublic {
618
569
  KEY \`index2\` (\`name\`)
619
570
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT = 'V1.1';
620
571
  `,
621
- },
622
- {
623
- scheme: appName,
624
- table: `t_line_group_inf`,
625
- sql: `(
572
+ },
573
+ {
574
+ scheme: appName,
575
+ table: `t_line_group_inf`,
576
+ sql: `(
626
577
  \`id\` int NOT NULL AUTO_INCREMENT,
627
578
  \`group_id\` VARCHAR(50) NOT NULL,
628
579
  \`group_name\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -635,11 +586,11 @@ export class ApiPublic {
635
586
  KEY \`index3\` (\`shopnex_user_id\`)
636
587
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
637
588
  `,
638
- },
639
- {
640
- scheme: appName,
641
- table: `t_app_line_group_verification`,
642
- sql: `(
589
+ },
590
+ {
591
+ scheme: appName,
592
+ table: `t_app_line_group_verification`,
593
+ sql: `(
643
594
  \`id\` int NOT NULL AUTO_INCREMENT,
644
595
  \`app_name\` VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL,
645
596
  \`verification_code\` VARCHAR(255) NOT NULL,
@@ -650,11 +601,11 @@ export class ApiPublic {
650
601
  UNIQUE KEY \`unique_verification_code\` (\`verification_code\`)
651
602
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
652
603
  `,
653
- },
654
- {
655
- scheme: appName,
656
- table: `t_temporary_cart`,
657
- sql: `(
604
+ },
605
+ {
606
+ scheme: appName,
607
+ table: `t_temporary_cart`,
608
+ sql: `(
658
609
  \`id\` int NOT NULL AUTO_INCREMENT,
659
610
  \`cart_id\` VARCHAR(255) NOT NULL ,
660
611
  \`content\` json DEFAULT NULL,
@@ -664,11 +615,11 @@ export class ApiPublic {
664
615
  INDEX \`idx_created_time\` (\`created_time\`)
665
616
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
666
617
  `,
667
- },
668
- {
669
- scheme: appName,
670
- table: `t_live_comments`,
671
- sql: `(
618
+ },
619
+ {
620
+ scheme: appName,
621
+ table: `t_live_comments`,
622
+ sql: `(
672
623
  \`id\` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key: Auto-incremented ID',
673
624
  \`interaction_id\` varchar(50) NOT NULL COMMENT 'ID that links to t_live_purchase_interactions',
674
625
  \`user_id\` varchar(50) NOT NULL COMMENT 'ID from FB or IG packet which is used to identify the user',
@@ -679,11 +630,11 @@ export class ApiPublic {
679
630
  KEY \`index2\` (\`interaction_id\`)
680
631
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
681
632
  `,
682
- },
683
- {
684
- scheme: appName,
685
- table: `t_check_in_pos`,
686
- sql: `(
633
+ },
634
+ {
635
+ scheme: appName,
636
+ table: `t_check_in_pos`,
637
+ sql: `(
687
638
  \`id\` INT NOT NULL AUTO_INCREMENT,
688
639
  \`staff\` VARCHAR(45) NOT NULL,
689
640
  \`execute\` VARCHAR(45) NOT NULL,
@@ -695,11 +646,11 @@ export class ApiPublic {
695
646
  INDEX \`index5\` (\`store\` ASC) VISIBLE,
696
647
  INDEX \`index4\` (\`execute\` ASC) VISIBLE) COMMENT = 'V1.1';
697
648
  `,
698
- },
699
- {
700
- scheme: appName,
701
- table: `t_pos_summary`,
702
- sql: `(
649
+ },
650
+ {
651
+ scheme: appName,
652
+ table: `t_pos_summary`,
653
+ sql: `(
703
654
  \`id\` INT NOT NULL AUTO_INCREMENT,
704
655
  \`staff\` VARCHAR(45) NOT NULL,
705
656
  \`summary_type\` VARCHAR(45) NOT NULL,
@@ -710,22 +661,22 @@ export class ApiPublic {
710
661
  INDEX \`index3\` (\`summary_type\` ASC) VISIBLE,
711
662
  INDEX \`index4\` (\`created_time\` ASC) VISIBLE);
712
663
  `,
713
- },
714
- {
715
- scheme: appName,
716
- table: 't_product_comment',
717
- sql: `(
664
+ },
665
+ {
666
+ scheme: appName,
667
+ table: 't_product_comment',
668
+ sql: `(
718
669
  \`id\` int NOT NULL AUTO_INCREMENT,
719
670
  \`product_id\` int DEFAULT NULL,
720
671
  \`content\` json NOT NULL,
721
672
  PRIMARY KEY (\`id\`),
722
673
  KEY \`index2\` (\`product_id\`)
723
674
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
724
- },
725
- {
726
- scheme: appName,
727
- table: 't_products_sold_history',
728
- sql: `(
675
+ },
676
+ {
677
+ scheme: appName,
678
+ table: 't_products_sold_history',
679
+ sql: `(
729
680
  \`id\` int NOT NULL AUTO_INCREMENT,
730
681
  \`product_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
731
682
  \`order_id\` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -737,11 +688,11 @@ export class ApiPublic {
737
688
  KEY \`index4\` (\`spec\`),
738
689
  KEY \`index5\` (\`count\`)
739
690
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='V1.1'`,
740
- },
741
- {
742
- scheme: appName,
743
- table: `visit_logs`,
744
- sql: `(
691
+ },
692
+ {
693
+ scheme: appName,
694
+ table: `visit_logs`,
695
+ sql: `(
745
696
  \`id\` INT NOT NULL AUTO_INCREMENT,
746
697
  \`date\` DATETIME NOT NULL,
747
698
  \`count\` INT NOT NULL,
@@ -751,11 +702,11 @@ export class ApiPublic {
751
702
  INDEX \`index2\` (\`date\` ASC) VISIBLE,
752
703
  UNIQUE INDEX \`tag_name_UNIQUE\` (\`tag_name\` ASC) VISIBLE);
753
704
  `,
754
- },
755
- {
756
- scheme: 't_1725992531001',
757
- table: 't_changed_logs',
758
- sql: `(
705
+ },
706
+ {
707
+ scheme: 't_1725992531001',
708
+ table: 't_changed_logs',
709
+ sql: `(
759
710
  \`id\` INT NOT NULL AUTO_INCREMENT,
760
711
  \`entity_table\` varchar(200) NOT NULL COMMENT '關聯的table',
761
712
  \`entity_id\` INT NOT NULL COMMENT '關聯的id',
@@ -768,21 +719,75 @@ export class ApiPublic {
768
719
  PRIMARY KEY (\`id\`),
769
720
  UNIQUE KEY \`id_UNIQUE\` (\`id\`)
770
721
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
771
- },
772
- ];
773
- for (const b of chunkArray(sqlArray, groupSize)) {
774
- let check = b.length;
775
- await new Promise(resolve => {
776
- for (const d of b) {
777
- compare_sql_table(d.scheme, d.table, d.sql).then(() => {
778
- check--;
779
- if (check === 0) {
780
- resolve(true);
781
- }
782
- });
722
+ },
723
+ ];
724
+ for (const b of chunkArray(sqlArray, groupSize)) {
725
+ let check = b.length;
726
+ await new Promise(resolve => {
727
+ for (const d of b) {
728
+ compare_sql_table(d.scheme, d.table, d.sql).then(() => {
729
+ check--;
730
+ if (check === 0) {
731
+ resolve(true);
732
+ }
733
+ });
734
+ }
735
+ });
736
+ }
737
+ }
738
+ //
739
+ public static async createScheme(appName: string) {
740
+ //已通過則直接回傳執行
741
+ if (
742
+ ApiPublic.checkedApp.find(dd => {
743
+ return dd.app_name === appName;
744
+ })
745
+ ) {
746
+ return;
747
+ }
748
+
749
+ //已經正在檢查中的話,等檢查結束
750
+ if (
751
+ ApiPublic.checkingApp.find(dd => {
752
+ return dd.app_name === appName;
753
+ })
754
+ ) {
755
+ const result = await new Promise(resolve => {
756
+ const interval = setInterval(() => {
757
+ if (
758
+ ApiPublic.checkedApp.find(dd => {
759
+ return dd.app_name === appName;
760
+ })
761
+ ) {
762
+ resolve(true);
763
+ clearInterval(interval);
764
+ } else if (
765
+ !ApiPublic.checkingApp.find(dd => {
766
+ return dd.app_name === appName;
767
+ })
768
+ ) {
769
+ resolve(false);
770
+ clearInterval(interval);
783
771
  }
784
- });
772
+ }, 500);
773
+ });
774
+ if (result) {
775
+ return;
785
776
  }
777
+ }
778
+ ApiPublic.checkingApp.push({
779
+ app_name: appName,
780
+ refer_app: (
781
+ await db.query(
782
+ `select refer_app
783
+ from \`${saasConfig.SAAS_NAME}\`.app_config
784
+ where appName = ?`,
785
+ [appName]
786
+ )
787
+ )[0]['refer_app'],
788
+ });
789
+ try {
790
+ await this.createTable(appName)
786
791
  //AI客服的設定,*注意*異步避免chat-gpt異常
787
792
  AiRobot.syncAiRobot(appName);
788
793
  //舊版未分倉庫的資料格式,改成有分倉庫的資料格式