bullmq 6.3.11 → 6.3.13

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.
Files changed (204) hide show
  1. package/dist/cjs/classes/queue-getters.js +3 -1
  2. package/dist/cjs/classes/queue.js +2 -1
  3. package/dist/cjs/classes/redis-connection.js +1 -1
  4. package/dist/cjs/classes/redis-queue-backend.js +1 -1
  5. package/dist/cjs/commands/includes/moveChildBackToParentDependencies.lua +20 -0
  6. package/dist/cjs/commands/moveJobsToWait-8.lua +3 -0
  7. package/dist/cjs/commands/reprocessJob-7.lua +2 -14
  8. package/dist/cjs/postgres/sql-loader.js +27 -41
  9. package/dist/cjs/postgres/sql-scripts.js +110 -0
  10. package/dist/cjs/scripts/moveJobsToWait-8.js +21 -0
  11. package/dist/cjs/scripts/reprocessJob-7.js +20 -13
  12. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/esm/classes/queue-getters.d.ts +3 -1
  15. package/dist/esm/classes/queue-getters.js +3 -1
  16. package/dist/esm/classes/queue.d.ts +2 -1
  17. package/dist/esm/classes/queue.js +2 -1
  18. package/dist/esm/classes/redis-connection.d.ts +1 -1
  19. package/dist/esm/classes/redis-connection.js +1 -1
  20. package/dist/esm/classes/redis-queue-backend.d.ts +1 -1
  21. package/dist/esm/classes/redis-queue-backend.js +1 -1
  22. package/dist/esm/commands/includes/moveChildBackToParentDependencies.lua +20 -0
  23. package/dist/esm/commands/moveJobsToWait-8.lua +3 -0
  24. package/dist/esm/commands/reprocessJob-7.lua +2 -14
  25. package/dist/esm/postgres/sql-loader.d.ts +6 -1
  26. package/dist/esm/postgres/sql-loader.js +27 -41
  27. package/dist/esm/postgres/sql-scripts.d.ts +10 -0
  28. package/dist/esm/postgres/sql-scripts.js +107 -0
  29. package/dist/esm/scripts/moveJobsToWait-8.js +21 -0
  30. package/dist/esm/scripts/reprocessJob-7.js +20 -13
  31. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  32. package/dist/esm/version.d.ts +1 -1
  33. package/dist/esm/version.js +1 -1
  34. package/package.json +10 -9
  35. package/dist/cjs/postgres/commands/add_flow.sql +0 -3
  36. package/dist/cjs/postgres/commands/add_job.sql +0 -5
  37. package/dist/cjs/postgres/commands/add_job_scheduler.sql +0 -6
  38. package/dist/cjs/postgres/commands/add_jobs_bulk.sql +0 -3
  39. package/dist/cjs/postgres/commands/add_log.sql +0 -14
  40. package/dist/cjs/postgres/commands/change_delay.sql +0 -3
  41. package/dist/cjs/postgres/commands/change_priority.sql +0 -3
  42. package/dist/cjs/postgres/commands/clean.sql +0 -3
  43. package/dist/cjs/postgres/commands/clear_logs.sql +0 -9
  44. package/dist/cjs/postgres/commands/collect_metrics.sql +0 -4
  45. package/dist/cjs/postgres/commands/delete_deduplication_key.sql +0 -6
  46. package/dist/cjs/postgres/commands/drain.sql +0 -2
  47. package/dist/cjs/postgres/commands/extend_lock.sql +0 -3
  48. package/dist/cjs/postgres/commands/extend_locks.sql +0 -25
  49. package/dist/cjs/postgres/commands/get_client_list.sql +0 -11
  50. package/dist/cjs/postgres/commands/get_counts.sql +0 -13
  51. package/dist/cjs/postgres/commands/get_counts_per_priority.sql +0 -14
  52. package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +0 -7
  53. package/dist/cjs/postgres/commands/get_dependencies.sql +0 -8
  54. package/dist/cjs/postgres/commands/get_dependencies_page.sql +0 -7
  55. package/dist/cjs/postgres/commands/get_dependency_counts.sql +0 -9
  56. package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +0 -7
  57. package/dist/cjs/postgres/commands/get_job_data.sql +0 -2
  58. package/dist/cjs/postgres/commands/get_job_logs_asc.sql +0 -6
  59. package/dist/cjs/postgres/commands/get_job_logs_count.sql +0 -2
  60. package/dist/cjs/postgres/commands/get_job_logs_desc.sql +0 -6
  61. package/dist/cjs/postgres/commands/get_job_scheduler.sql +0 -6
  62. package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +0 -2
  63. package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +0 -10
  64. package/dist/cjs/postgres/commands/get_metrics.sql +0 -14
  65. package/dist/cjs/postgres/commands/get_processed_children_values.sql +0 -8
  66. package/dist/cjs/postgres/commands/get_queue_meta.sql +0 -2
  67. package/dist/cjs/postgres/commands/get_queue_meta_field.sql +0 -2
  68. package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +0 -3
  69. package/dist/cjs/postgres/commands/get_range.sql +0 -3
  70. package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +0 -3
  71. package/dist/cjs/postgres/commands/get_state.sql +0 -2
  72. package/dist/cjs/postgres/commands/has_queue_meta_field.sql +0 -4
  73. package/dist/cjs/postgres/commands/has_waiting_job.sql +0 -11
  74. package/dist/cjs/postgres/commands/is_finished.sql +0 -4
  75. package/dist/cjs/postgres/commands/is_job_in_state.sql +0 -6
  76. package/dist/cjs/postgres/commands/is_job_in_wait.sql +0 -15
  77. package/dist/cjs/postgres/commands/is_job_prioritized.sql +0 -6
  78. package/dist/cjs/postgres/commands/is_job_scheduler.sql +0 -4
  79. package/dist/cjs/postgres/commands/is_maxed.sql +0 -10
  80. package/dist/cjs/postgres/commands/listen_events.sql +0 -3
  81. package/dist/cjs/postgres/commands/listen_jobs.sql +0 -4
  82. package/dist/cjs/postgres/commands/move_active_to_wait.sql +0 -4
  83. package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
  84. package/dist/cjs/postgres/commands/move_to_active.sql +0 -4
  85. package/dist/cjs/postgres/commands/move_to_completed.sql +0 -4
  86. package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +0 -9
  87. package/dist/cjs/postgres/commands/move_to_delayed.sql +0 -4
  88. package/dist/cjs/postgres/commands/move_to_failed.sql +0 -4
  89. package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +0 -9
  90. package/dist/cjs/postgres/commands/move_to_waiting_children.sql +0 -3
  91. package/dist/cjs/postgres/commands/next_delay.sql +0 -2
  92. package/dist/cjs/postgres/commands/next_signal.sql +0 -3
  93. package/dist/cjs/postgres/commands/obliterate.sql +0 -4
  94. package/dist/cjs/postgres/commands/paginate_dependencies.sql +0 -19
  95. package/dist/cjs/postgres/commands/pause.sql +0 -2
  96. package/dist/cjs/postgres/commands/promote.sql +0 -3
  97. package/dist/cjs/postgres/commands/promote_jobs.sql +0 -3
  98. package/dist/cjs/postgres/commands/publish_event.sql +0 -3
  99. package/dist/cjs/postgres/commands/read_events.sql +0 -6
  100. package/dist/cjs/postgres/commands/read_events_max.sql +0 -3
  101. package/dist/cjs/postgres/commands/remove.sql +0 -3
  102. package/dist/cjs/postgres/commands/remove_child_dependency.sql +0 -4
  103. package/dist/cjs/postgres/commands/remove_deduplication_key.sql +0 -9
  104. package/dist/cjs/postgres/commands/remove_job_scheduler.sql +0 -3
  105. package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +0 -2
  106. package/dist/cjs/postgres/commands/remove_rate_limit.sql +0 -6
  107. package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +0 -3
  108. package/dist/cjs/postgres/commands/reprocess_job.sql +0 -4
  109. package/dist/cjs/postgres/commands/retry_job.sql +0 -3
  110. package/dist/cjs/postgres/commands/retry_jobs.sql +0 -3
  111. package/dist/cjs/postgres/commands/set_queue_meta.sql +0 -4
  112. package/dist/cjs/postgres/commands/set_rate_limit.sql +0 -3
  113. package/dist/cjs/postgres/commands/trim_logs.sql +0 -3
  114. package/dist/cjs/postgres/commands/update_data.sql +0 -3
  115. package/dist/cjs/postgres/commands/update_job_scheduler.sql +0 -5
  116. package/dist/cjs/postgres/commands/update_progress.sql +0 -3
  117. package/dist/cjs/postgres/migrations/0001_schema.sql +0 -348
  118. package/dist/cjs/postgres/migrations/0002_functions.sql +0 -3473
  119. package/dist/cjs/postgres/migrations/0003_dedup_stale_key.sql +0 -147
  120. package/dist/esm/postgres/commands/add_flow.sql +0 -3
  121. package/dist/esm/postgres/commands/add_job.sql +0 -5
  122. package/dist/esm/postgres/commands/add_job_scheduler.sql +0 -6
  123. package/dist/esm/postgres/commands/add_jobs_bulk.sql +0 -3
  124. package/dist/esm/postgres/commands/add_log.sql +0 -14
  125. package/dist/esm/postgres/commands/change_delay.sql +0 -3
  126. package/dist/esm/postgres/commands/change_priority.sql +0 -3
  127. package/dist/esm/postgres/commands/clean.sql +0 -3
  128. package/dist/esm/postgres/commands/clear_logs.sql +0 -9
  129. package/dist/esm/postgres/commands/collect_metrics.sql +0 -4
  130. package/dist/esm/postgres/commands/delete_deduplication_key.sql +0 -6
  131. package/dist/esm/postgres/commands/drain.sql +0 -2
  132. package/dist/esm/postgres/commands/extend_lock.sql +0 -3
  133. package/dist/esm/postgres/commands/extend_locks.sql +0 -25
  134. package/dist/esm/postgres/commands/get_client_list.sql +0 -11
  135. package/dist/esm/postgres/commands/get_counts.sql +0 -13
  136. package/dist/esm/postgres/commands/get_counts_per_priority.sql +0 -14
  137. package/dist/esm/postgres/commands/get_deduplication_job_id.sql +0 -7
  138. package/dist/esm/postgres/commands/get_dependencies.sql +0 -8
  139. package/dist/esm/postgres/commands/get_dependencies_page.sql +0 -7
  140. package/dist/esm/postgres/commands/get_dependency_counts.sql +0 -9
  141. package/dist/esm/postgres/commands/get_ignored_children_failures.sql +0 -7
  142. package/dist/esm/postgres/commands/get_job_data.sql +0 -2
  143. package/dist/esm/postgres/commands/get_job_logs_asc.sql +0 -6
  144. package/dist/esm/postgres/commands/get_job_logs_count.sql +0 -2
  145. package/dist/esm/postgres/commands/get_job_logs_desc.sql +0 -6
  146. package/dist/esm/postgres/commands/get_job_scheduler.sql +0 -6
  147. package/dist/esm/postgres/commands/get_job_schedulers_count.sql +0 -2
  148. package/dist/esm/postgres/commands/get_job_schedulers_range.sql +0 -10
  149. package/dist/esm/postgres/commands/get_metrics.sql +0 -14
  150. package/dist/esm/postgres/commands/get_processed_children_values.sql +0 -8
  151. package/dist/esm/postgres/commands/get_queue_meta.sql +0 -2
  152. package/dist/esm/postgres/commands/get_queue_meta_field.sql +0 -2
  153. package/dist/esm/postgres/commands/get_queue_meta_fields.sql +0 -3
  154. package/dist/esm/postgres/commands/get_range.sql +0 -3
  155. package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +0 -3
  156. package/dist/esm/postgres/commands/get_state.sql +0 -2
  157. package/dist/esm/postgres/commands/has_queue_meta_field.sql +0 -4
  158. package/dist/esm/postgres/commands/has_waiting_job.sql +0 -11
  159. package/dist/esm/postgres/commands/is_finished.sql +0 -4
  160. package/dist/esm/postgres/commands/is_job_in_state.sql +0 -6
  161. package/dist/esm/postgres/commands/is_job_in_wait.sql +0 -15
  162. package/dist/esm/postgres/commands/is_job_prioritized.sql +0 -6
  163. package/dist/esm/postgres/commands/is_job_scheduler.sql +0 -4
  164. package/dist/esm/postgres/commands/is_maxed.sql +0 -10
  165. package/dist/esm/postgres/commands/listen_events.sql +0 -3
  166. package/dist/esm/postgres/commands/listen_jobs.sql +0 -4
  167. package/dist/esm/postgres/commands/move_active_to_wait.sql +0 -4
  168. package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
  169. package/dist/esm/postgres/commands/move_to_active.sql +0 -4
  170. package/dist/esm/postgres/commands/move_to_completed.sql +0 -4
  171. package/dist/esm/postgres/commands/move_to_completed_fetch.sql +0 -9
  172. package/dist/esm/postgres/commands/move_to_delayed.sql +0 -4
  173. package/dist/esm/postgres/commands/move_to_failed.sql +0 -4
  174. package/dist/esm/postgres/commands/move_to_failed_fetch.sql +0 -9
  175. package/dist/esm/postgres/commands/move_to_waiting_children.sql +0 -3
  176. package/dist/esm/postgres/commands/next_delay.sql +0 -2
  177. package/dist/esm/postgres/commands/next_signal.sql +0 -3
  178. package/dist/esm/postgres/commands/obliterate.sql +0 -4
  179. package/dist/esm/postgres/commands/paginate_dependencies.sql +0 -19
  180. package/dist/esm/postgres/commands/pause.sql +0 -2
  181. package/dist/esm/postgres/commands/promote.sql +0 -3
  182. package/dist/esm/postgres/commands/promote_jobs.sql +0 -3
  183. package/dist/esm/postgres/commands/publish_event.sql +0 -3
  184. package/dist/esm/postgres/commands/read_events.sql +0 -6
  185. package/dist/esm/postgres/commands/read_events_max.sql +0 -3
  186. package/dist/esm/postgres/commands/remove.sql +0 -3
  187. package/dist/esm/postgres/commands/remove_child_dependency.sql +0 -4
  188. package/dist/esm/postgres/commands/remove_deduplication_key.sql +0 -9
  189. package/dist/esm/postgres/commands/remove_job_scheduler.sql +0 -3
  190. package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +0 -2
  191. package/dist/esm/postgres/commands/remove_rate_limit.sql +0 -6
  192. package/dist/esm/postgres/commands/remove_unprocessed_children.sql +0 -3
  193. package/dist/esm/postgres/commands/reprocess_job.sql +0 -4
  194. package/dist/esm/postgres/commands/retry_job.sql +0 -3
  195. package/dist/esm/postgres/commands/retry_jobs.sql +0 -3
  196. package/dist/esm/postgres/commands/set_queue_meta.sql +0 -4
  197. package/dist/esm/postgres/commands/set_rate_limit.sql +0 -3
  198. package/dist/esm/postgres/commands/trim_logs.sql +0 -3
  199. package/dist/esm/postgres/commands/update_data.sql +0 -3
  200. package/dist/esm/postgres/commands/update_job_scheduler.sql +0 -5
  201. package/dist/esm/postgres/commands/update_progress.sql +0 -3
  202. package/dist/esm/postgres/migrations/0001_schema.sql +0 -348
  203. package/dist/esm/postgres/migrations/0002_functions.sql +0 -3473
  204. package/dist/esm/postgres/migrations/0003_dedup_stale_key.sql +0 -147
@@ -329,7 +329,9 @@ class QueueGetters extends queue_base_1.QueueBase {
329
329
  *
330
330
  * @param parentId - The id of the parent job
331
331
  * @param type - "processed" | "pending"
332
- * @param opts - Options for the query.
332
+ * @param start - Zero-based index from where to start returning children.
333
+ * @param end - Zero-based index where to stop returning children (inclusive),
334
+ * or -1 to return all of them.
333
335
  *
334
336
  * @returns an object with the following shape:
335
337
  * `{ items: { id: string, v?: any, err?: string } [], jobs: JobJson[], total: number}`
@@ -233,7 +233,8 @@ class Queue extends queue_getters_1.QueueGetters {
233
233
  * Upserting a scheduler will create a new job scheduler or update an existing one.
234
234
  * It will also create the first job based on the repeat options and delayed accordingly.
235
235
  *
236
- * @param key - Unique key for the repeatable job meta.
236
+ * @param jobSchedulerId - Unique id of the job scheduler. Upserting with an
237
+ * existing id updates that scheduler.
237
238
  * @param repeatOpts - Repeat options
238
239
  * @param jobTemplate - Job template. If provided it will be used for all the jobs
239
240
  * created by the scheduler.
@@ -175,7 +175,7 @@ class RedisConnection extends events_1.EventEmitter {
175
175
  }
176
176
  /**
177
177
  * Waits for a redis client to be ready.
178
- * @param redis - client
178
+ * @param client - Redis client to wait for.
179
179
  */
180
180
  static async waitUntilReady(client) {
181
181
  if (client.status === 'ready') {
@@ -1438,8 +1438,8 @@ class RedisQueueBackend extends events_1.EventEmitter {
1438
1438
  * This script is used when a job has been manually rate limited and needs
1439
1439
  * to be moved back to wait from active status.
1440
1440
  *
1441
- * @param client - Redis client
1442
1441
  * @param jobId - Job id
1442
+ * @param token - Lock token of the job. Defaults to '0'.
1443
1443
  * @returns
1444
1444
  */
1445
1445
  async moveJobFromActiveToWait(jobId, token = '0') {
@@ -0,0 +1,20 @@
1
+ --[[
2
+ Function to move a retried child back to its parent's dependencies.
3
+ This does not move a parent that has already left waiting-children back to that state.
4
+ ]]
5
+ local function moveChildBackToParentDependencies(jobKey, prevState)
6
+ local parentKey = rcall("HGET", jobKey, "parentKey")
7
+
8
+ if parentKey and rcall("EXISTS", parentKey) == 1 then
9
+ if prevState == "failed" then
10
+ if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
11
+ rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
12
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
13
+ end
14
+ else
15
+ if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
16
+ rcall("SADD", parentKey .. ":dependencies", jobKey)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -31,6 +31,7 @@ local rcall = redis.call;
31
31
  --- @include "includes/batches"
32
32
  --- @include "includes/getOrSetMaxEvents"
33
33
  --- @include "includes/isQueuePausedOrMaxed"
34
+ --- @include "includes/moveChildBackToParentDependencies"
34
35
 
35
36
  local metaKey = KEYS[6]
36
37
  local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, KEYS[7])
@@ -42,11 +43,13 @@ if (#jobs > 0) then
42
43
  for i, key in ipairs(jobs) do
43
44
  local jobKey = KEYS[1] .. key
44
45
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason")
46
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
45
47
  end
46
48
  elseif ARGV[3] == "completed" then
47
49
  for i, key in ipairs(jobs) do
48
50
  local jobKey = KEYS[1] .. key
49
51
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "returnvalue")
52
+ moveChildBackToParentDependencies(jobKey, ARGV[3])
50
53
  end
51
54
  end
52
55
 
@@ -28,6 +28,7 @@ local rcall = redis.call;
28
28
  --- @include "includes/addJobInTargetList"
29
29
  --- @include "includes/getOrSetMaxEvents"
30
30
  --- @include "includes/isQueuePausedOrMaxed"
31
+ --- @include "includes/moveChildBackToParentDependencies"
31
32
 
32
33
  local jobKey = KEYS[1]
33
34
  if rcall("EXISTS", jobKey) == 1 then
@@ -48,20 +49,7 @@ if rcall("EXISTS", jobKey) == 1 then
48
49
  local isPausedOrMaxed = isQueuePausedOrMaxed(KEYS[5], KEYS[6])
49
50
  addJobInTargetList(KEYS[4], KEYS[7], ARGV[2], isPausedOrMaxed, jobId)
50
51
 
51
- local parentKey = rcall("HGET", jobKey, "parentKey")
52
-
53
- if parentKey and rcall("EXISTS", parentKey) == 1 then
54
- if ARGV[4] == "failed" then
55
- if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
56
- rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
57
- rcall("SADD", parentKey .. ":dependencies", jobKey)
58
- end
59
- else
60
- if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
61
- rcall("SADD", parentKey .. ":dependencies", jobKey)
62
- end
63
- end
64
- end
52
+ moveChildBackToParentDependencies(jobKey, ARGV[4])
65
53
 
66
54
  local maxEvents = getOrSetMaxEvents(KEYS[5])
67
55
  -- Emit waiting event
@@ -2,65 +2,51 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadMigrationSql = loadMigrationSql;
4
4
  exports.loadCommandSql = loadCommandSql;
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const url_1 = require("url");
8
- function getDirname() {
9
- if (typeof __dirname !== 'undefined' && __dirname) {
10
- return __dirname;
11
- }
12
- const stack = new Error().stack || '';
13
- for (const line of stack.split('\n')) {
14
- const match = line.match(/(file:\/\/\/[^\s)]+)/);
15
- if (match) {
16
- try {
17
- return (0, path_1.dirname)((0, url_1.fileURLToPath)(match[1]));
18
- }
19
- catch (_a) {
20
- // continue searching
21
- }
22
- }
23
- }
24
- throw new Error('Could not determine sql-loader directory path');
25
- }
26
- const currentDir = getDirname();
5
+ const sql_scripts_1 = require("./sql-scripts");
27
6
  /**
28
- * Loads a migration's SQL from its `.sql` file — the portable source of truth
29
- * shared with the Elixir/Python ports. Results are cached after the first read.
7
+ * Loads a migration's SQL — the portable source of truth shared with the
8
+ * Elixir/Python ports. Results are cached after the first lookup.
30
9
  *
31
- * The `.sql` files live next to this module under `migrations/`. The published
32
- * build copies them alongside the compiled output (a `copy:sql` build step,
33
- * analogous to how the Lua scripts are bundled), so the same relative lookup
34
- * works at runtime.
35
- */
36
- const MIGRATIONS_DIR = (0, path_1.join)(currentDir, 'migrations');
37
- /**
38
- * Runtime queries live under `commands/`. Each `.sql` file is one parameterized
39
- * statement (a `SELECT fn(...)` for the PL/pgSQL operations, or a direct
40
- * query). They contain NO schema/namespace references — the connection's
41
- * `search_path` selects the schema — so they are portable verbatim to the
42
- * Python/Elixir/PHP/Rust ports (mirroring how the Redis backend's `.lua`
43
- * scripts never hardcode the key prefix).
10
+ * The SQL is inlined into the published JavaScript at build time (see
11
+ * scripts/generateSqlScripts.js), exactly like the Redis backend's `.lua`
12
+ * scripts, so no filesystem access is needed at runtime. This keeps the
13
+ * PostgreSQL backend usable from single-file bundles (bun build --compile,
14
+ * esbuild --bundle, pkg, Node SEA, deno compile) where the `.sql` files are
15
+ * not shipped alongside the code:
16
+ *
17
+ * @see https://github.com/taskforcesh/bullmq/issues/4603
18
+ *
19
+ * @param file - Migration filename, e.g. `0001_schema.sql`.
44
20
  */
45
- const COMMANDS_DIR = (0, path_1.join)(currentDir, 'commands');
46
21
  const migrationCache = new Map();
47
22
  const commandCache = new Map();
48
23
  function loadMigrationSql(file) {
49
24
  let sql = migrationCache.get(file);
50
25
  if (sql === undefined) {
51
- sql = (0, fs_1.readFileSync)((0, path_1.join)(MIGRATIONS_DIR, file), 'utf8');
26
+ sql = sql_scripts_1.SQL_MIGRATIONS[file];
27
+ if (sql === undefined) {
28
+ throw new Error(`Could not find migration SQL for '${file}'`);
29
+ }
52
30
  migrationCache.set(file, sql);
53
31
  }
54
32
  return sql;
55
33
  }
56
34
  /**
57
35
  * Loads a runtime command's SQL by name (without the `.sql` extension), cached
58
- * after the first read.
36
+ * after the first lookup. Runtime queries contain NO schema/namespace
37
+ * references — the connection's `search_path` selects the schema — so they are
38
+ * portable verbatim to the Python/Elixir/PHP/Rust ports (mirroring how the
39
+ * Redis backend's `.lua` scripts never hardcode the key prefix).
40
+ *
41
+ * @param name - Command name, e.g. `add_job`.
59
42
  */
60
43
  function loadCommandSql(name) {
61
44
  let sql = commandCache.get(name);
62
45
  if (sql === undefined) {
63
- sql = (0, fs_1.readFileSync)((0, path_1.join)(COMMANDS_DIR, `${name}.sql`), 'utf8');
46
+ sql = sql_scripts_1.SQL_COMMANDS[`${name}.sql`];
47
+ if (sql === undefined) {
48
+ throw new Error(`Could not find command SQL for '${name}'`);
49
+ }
64
50
  commandCache.set(name, sql);
65
51
  }
66
52
  return sql;