Add MariaDB queue table. Fix Bugs

This commit is contained in:
2026-10-18 15:58:02 +01:00
parent d872c3661a
commit f9ba5f8657
28 changed files with 785 additions and 49 deletions
+21 -1
View File
@@ -1,11 +1,31 @@
import _ from "lodash";
import { DefaultFields } from "../types";
import { DefaultFields, QueueFields, QueueIndexes, } from "../types";
const queueFieldNames = new Set(QueueFields.map((f) => f.fieldName));
const queueIndexNames = new Set(QueueIndexes.map((i) => i.indexName));
export default function ({ dbSchema }) {
const finaldbSchema = _.cloneDeep(dbSchema);
finaldbSchema.tables = finaldbSchema.tables.map((t) => {
const newTable = _.cloneDeep(t);
newTable.fields = newTable.fields.filter((f) => !f.fieldName?.match(/^(id|created_at|updated_at)$/));
newTable.fields.unshift(...DefaultFields);
if (newTable.queue_table) {
const reserved = [
...newTable.fields
.map((f) => f.fieldName)
.filter((name) => queueFieldNames.has(name)),
...(newTable.indexes || [])
.map((i) => i.indexName)
.filter((name) => queueIndexNames.has(name)),
];
if (reserved.length > 0) {
throw new Error(`\`${newTable.tableName}\` is a queue table: ${reserved.join(", ")} ${reserved.length > 1 ? "are" : "is"} managed by bun-mariadb and can't be declared in the schema`);
}
newTable.fields.push(..._.cloneDeep(QueueFields));
newTable.indexes = [
...(newTable.indexes || []),
..._.cloneDeep(QueueIndexes),
];
}
return newTable;
});
return finaldbSchema;