fix: support utf8mb4 across MySQL and MariaDB
Test / test (push) Canceled after 6m35s
Build and publish image / image (push) Successful in 13m42s

This commit is contained in:
bryanpedini committed 2026-11-20 15:14:28 +01:00
1 parent cce17c5fa4
commit d34894c9cd
28 files changed
+224 -121

No files matched your search

+15 -9
View File
@@ -75,7 +75,7 @@ function connectionOptions(database?: string): mysql.ConnectionOptions {
dateStrings: true,
supportBigNumbers: true,
bigNumberStrings: false,
charset: 'utf8mb4_0900_ai_ci',
charset: 'utf8mb4_general_ci',
connectTimeout: 10_000,
};
}
@@ -263,18 +263,24 @@ export class Db {
return Number(rows[0].id ?? 0);
}
async auditSince(id: number): Promise<AuditRow[]> {
return this.query<AuditRow>(
`SELECT id, DATE_FORMAT(time, '%Y-%m-%dT%H:%i:%s.%fZ') AS time, user_id, actor, origin, operation, status, error, zone, record_id, target_user_id, before_value, after_value FROM ${this.t.audit} WHERE id > ? ORDER BY id`,
[id],
private async auditRows(clause: string, value: number): Promise<AuditRow[]> {
const rows = await this.query<AuditRow>(
`SELECT id, DATE_FORMAT(time, '%Y-%m-%dT%H:%i:%s.%fZ') AS time, user_id, actor, origin, operation, status, error, zone, record_id, target_user_id, CAST(before_value AS CHAR) AS before_value, CAST(after_value AS CHAR) AS after_value FROM ${this.t.audit} ${clause}`,
[value],
);
return rows.map(row => ({
...row,
before_value: row.before_value === null ? null : JSON.parse(String(row.before_value)),
after_value: row.after_value === null ? null : JSON.parse(String(row.after_value)),
}));
}
async auditSince(id: number): Promise<AuditRow[]> {
return this.auditRows('WHERE id > ? ORDER BY id', id);
}
async auditTail(n: number): Promise<AuditRow[]> {
const rows = await this.query<AuditRow>(
`SELECT id, DATE_FORMAT(time, '%Y-%m-%dT%H:%i:%s.%fZ') AS time, user_id, actor, origin, operation, status, error, zone, record_id, target_user_id, before_value, after_value FROM ${this.t.audit} ORDER BY id DESC LIMIT ?`,
[n],
);
const rows = await this.auditRows('ORDER BY id DESC LIMIT ?', n);
return rows.reverse();
}