Files
bun-sqlite/dist/utils/append-default-fields-to-db-schema.js
T
tbenandClaude Opus 5.5 938a1da71d Add queue tables, quote SQL identifiers (v1.3.0)
- isQueue table option adds queue columns and a (status, available_at)
  index; BunSQLite.queue exposes add, claim, complete, fail and
  release_stale with atomic claims
- Set busy_timeout on connections so workers in separate processes wait
  instead of failing with SQLITE_BUSY
- Quote table and column names with backticks in generated SQL, so
  reserved words (to, order, group) work and unknown columns error
  instead of matching as string literals
- Tests for queue ops, multi-process claims and reserved-word names

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-18 16:29:14 +01:00

24 lines
1.0 KiB
JavaScript

import _ from "lodash";
import { DefaultFields, QueueFields, } from "../types";
const QueueFieldNames = QueueFields.map((f) => f.fieldName);
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.isQueue) {
newTable.fields = newTable.fields.filter((f) => !QueueFieldNames.includes(f.fieldName));
newTable.fields.push(...QueueFields);
const indexName = `idx_${newTable.tableName}_queue`;
newTable.indexes = (newTable.indexes || []).filter((idx) => idx.indexName !== indexName);
newTable.indexes.push({
indexName,
indexTableFields: ["status", "available_at"],
});
}
return newTable;
});
return finaldbSchema;
}