You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/coa-updater/index.ts
+62-24Lines changed: 62 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,39 @@ import { createPool } from "mariadb";
8
8
constdataPath="/tmp/inducks",
9
9
isvPath=`${dataPath}/isv`;
10
10
11
+
/** Run CLI without a shell so MYSQL_ROOT_PASSWORD is not mangled ($, !, spaces, etc.). */
12
+
asyncfunctionrunMariadbCheck(): Promise<number>{
13
+
consthost=process.env.MYSQL_HOST;
14
+
constpassword=process.env.MYSQL_ROOT_PASSWORD;
15
+
constdatabase=process.env.MYSQL_DATABASE;
16
+
if(!host||password===undefined||!database){
17
+
thrownewError(
18
+
"MYSQL_HOST, MYSQL_ROOT_PASSWORD, and MYSQL_DATABASE are required for mariadb-check",
19
+
);
20
+
}
21
+
constproc=Bun.spawn(
22
+
[
23
+
"mariadb-check",
24
+
"-h",
25
+
host,
26
+
"-uroot",
27
+
`-p${password}`,
28
+
"-v",
29
+
database,
30
+
],
31
+
{stdout: "inherit",stderr: "inherit"},
32
+
);
33
+
returnproc.exited;
34
+
}
35
+
11
36
constpoolParams={
12
37
host: process.env.MYSQL_HOST,
13
38
port: parseInt(process.env.MYSQL_PORT||"3306"),
14
39
user: "root",
15
40
password: process.env.MYSQL_ROOT_PASSWORD,
41
+
connectionLimit: 5,
16
42
multipleStatements: true,
17
43
permitLocalInfile: true,
18
-
// Prevent "socket has unexpectedly been closed" during long LOAD DATA operations
19
-
// (inducks_entry is large; default net_read_timeout/net_write_timeout is 60s)
20
44
sessionVariables: {
21
45
net_read_timeout: 1800,// 30 minutes
22
46
net_write_timeout: 1800,// 30 minutes
@@ -149,61 +173,75 @@ set unique_checks = 1;
149
173
set foreign_key_checks = 1;
150
174
set sql_log_bin=1`;
151
175
152
-
constcleanSqlStatements=cleanSql.split(";");
153
-
154
-
constconnection=awaitpool.getConnection();
155
-
awaitconnection.query(
156
-
`DROP DATABASE IF EXISTS ${process.env.MYSQL_DATABASE_NEW};CREATE DATABASE ${process.env.MYSQL_DATABASE_NEW} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; set global net_buffer_length=1000000;
157
-
set global max_allowed_packet=1000000000; `,
158
-
);
176
+
constcleanSqlStatements=cleanSql
177
+
.split(";")
178
+
.map((s)=>s.trim())
179
+
.filter((s)=>s.length>0);
180
+
181
+
constsetupConnection=awaitpool.getConnection();
182
+
for(conststatementof[
183
+
`DROP DATABASE IF EXISTS ${process.env.MYSQL_DATABASE_NEW}`,
184
+
`CREATE DATABASE ${process.env.MYSQL_DATABASE_NEW} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`,
0 commit comments