velocious 1.0.544 → 1.0.546
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.
- package/README.md +2 -0
- package/build/background-jobs/store.js +39 -0
- package/build/database/pool/single-multi-use.js +20 -1
- package/build/database/record/index.js +1 -1
- package/build/database/tenants/data-copier.js +134 -5
- package/build/environment-handlers/node/cli/commands/generate/base-models.js +3 -1
- package/build/environment-handlers/node.js +16 -4
- package/build/src/background-jobs/store.d.ts +7 -0
- package/build/src/background-jobs/store.d.ts.map +1 -1
- package/build/src/background-jobs/store.js +36 -1
- package/build/src/database/pool/single-multi-use.d.ts +7 -0
- package/build/src/database/pool/single-multi-use.d.ts.map +1 -1
- package/build/src/database/pool/single-multi-use.js +18 -2
- package/build/src/database/record/index.js +2 -2
- package/build/src/database/tenants/data-copier.d.ts +63 -0
- package/build/src/database/tenants/data-copier.d.ts.map +1 -1
- package/build/src/database/tenants/data-copier.js +113 -5
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.js +3 -2
- package/build/src/environment-handlers/node.d.ts.map +1 -1
- package/build/src/environment-handlers/node.js +17 -5
- package/package.json +1 -1
- package/src/background-jobs/store.js +39 -0
- package/src/database/pool/single-multi-use.js +20 -1
- package/src/database/record/index.js +1 -1
- package/src/database/tenants/data-copier.js +134 -5
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +3 -1
- package/src/environment-handlers/node.js +16 -4
package/README.md
CHANGED
|
@@ -2338,4 +2338,6 @@ At runtime, the apartment-style `Tenant` façade (`velocious/build/src/tenants/t
|
|
|
2338
2338
|
|
|
2339
2339
|
`SchemaCloner` adds a missing auto-increment column and its separate source unique index in one schema alteration, including on MySQL/MariaDB where an auto-increment column must be keyed when it is created.
|
|
2340
2340
|
|
|
2341
|
+
`DataCopier.move(...)` safely re-homes selected rows between different physical databases: the target write and verification commit before the source delete, target-only row transformations are supported, and retries after the source is gone preserve the target.
|
|
2342
|
+
|
|
2341
2343
|
See [docs/tenant-databases.md](docs/tenant-databases.md) for the full configuration and migration pattern.
|
|
@@ -55,6 +55,20 @@ const SORTABLE_COLUMNS = {
|
|
|
55
55
|
scheduledAtMs: "scheduled_at_ms"
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Serializes concurrent `_applySchema` runs within THIS process, keyed by database
|
|
60
|
+
* identifier. Two stores that share one connection (SingleMultiUse / SQLite)
|
|
61
|
+
* otherwise interleave the multi-step table rebuild and corrupt it (the jobs table
|
|
62
|
+
* is left as its `*_velocious_rebuild` temp). A DB advisory lock can't fix that: on
|
|
63
|
+
* a session-scoped / re-entrant driver (MySQL `GET_LOCK`) a second acquire on the
|
|
64
|
+
* same session succeeds immediately so both callers proceed, and taking it on a
|
|
65
|
+
* separate connection blocks cross-session forever. An in-process promise-chain
|
|
66
|
+
* mutex serializes same-process callers with neither hazard. Cross-process schema
|
|
67
|
+
* races stay covered by the per-step advisory locks + rechecks inside the steps.
|
|
68
|
+
* @type {Map<string, Promise<void>>}
|
|
69
|
+
*/
|
|
70
|
+
const schemaApplyChains = new Map()
|
|
71
|
+
|
|
58
72
|
export default class BackgroundJobsStore {
|
|
59
73
|
/**
|
|
60
74
|
* Runs constructor.
|
|
@@ -804,6 +818,31 @@ export default class BackgroundJobsStore {
|
|
|
804
818
|
* @returns {Promise<void>} - Resolves when the schema is present.
|
|
805
819
|
*/
|
|
806
820
|
async _applySchema(db) {
|
|
821
|
+
// Serialize concurrent schema applies within this process, keyed by database
|
|
822
|
+
// identifier (see `schemaApplyChains`). The per-step locks inside the steps use
|
|
823
|
+
// DIFFERENT lock names, so two concurrent callers could otherwise each hold a
|
|
824
|
+
// different step lock while both rebuild the jobs table — and on SQLite/MSSQL an
|
|
825
|
+
// add-column is a create-copy-drop-rename rebuild, so overlapping rebuilds
|
|
826
|
+
// corrupt it. This mutex makes the whole apply mutually exclusive per process;
|
|
827
|
+
// the second caller then re-checks and finds every step already done.
|
|
828
|
+
const identifier = this.getDatabaseIdentifier() ?? "default"
|
|
829
|
+
const previous = schemaApplyChains.get(identifier) ?? Promise.resolve()
|
|
830
|
+
const run = previous.then(() => this._applySchemaSteps(db), () => this._applySchemaSteps(db))
|
|
831
|
+
|
|
832
|
+
// Keep the chain alive regardless of this run's outcome so one failed apply does
|
|
833
|
+
// not wedge later callers; this run still propagates its own result/error.
|
|
834
|
+
schemaApplyChains.set(identifier, run.then(() => {}, () => {}))
|
|
835
|
+
|
|
836
|
+
return await run
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Creates or upgrades the background-jobs tables, columns and concurrency rows on
|
|
841
|
+
* the given connection. Serialized per process by {@link BackgroundJobsStore#_applySchema}.
|
|
842
|
+
* @param {import("../database/drivers/base.js").default} db - Database connection.
|
|
843
|
+
* @returns {Promise<void>} - Resolves when the schema is present.
|
|
844
|
+
*/
|
|
845
|
+
async _applySchemaSteps(db) {
|
|
807
846
|
await this._ensureMigrationsTable(db)
|
|
808
847
|
|
|
809
848
|
const alreadyApplied = await this._hasMigration(db)
|
|
@@ -6,6 +6,14 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
|
6
6
|
activeCheckoutCount = 0
|
|
7
7
|
suppressedConnectionContextCount = 0
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Checkout names of the currently-active nested checkouts, innermost last. The
|
|
11
|
+
* shared connection carries a single checkout name, so nesting requires restoring
|
|
12
|
+
* the enclosing scope's name when an inner checkout checks in.
|
|
13
|
+
* @type {Array<string | undefined>}
|
|
14
|
+
*/
|
|
15
|
+
checkoutNameStack = []
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Runs checkin.
|
|
11
19
|
* @param {import("../drivers/base.js").default} connection - Connection.
|
|
@@ -14,8 +22,16 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
|
14
22
|
async checkin(connection) {
|
|
15
23
|
if (this.connection === connection && this.activeCheckoutCount > 0) {
|
|
16
24
|
this.activeCheckoutCount--
|
|
25
|
+
this.checkoutNameStack.pop()
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
// A nested checkout is checking in while an outer one is still active: restore
|
|
28
|
+
// the enclosing scope's checkout name instead of leaving this inner name (or
|
|
29
|
+
// clearing it) on the shared connection.
|
|
30
|
+
if (this.activeCheckoutCount > 0) {
|
|
31
|
+
await connection.setConnectionCheckoutName(this.checkoutNameStack[this.checkoutNameStack.length - 1])
|
|
32
|
+
|
|
33
|
+
return
|
|
34
|
+
}
|
|
19
35
|
}
|
|
20
36
|
|
|
21
37
|
try {
|
|
@@ -24,6 +40,7 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
|
24
40
|
} catch (error) {
|
|
25
41
|
if (this.connection === connection) {
|
|
26
42
|
this.activeCheckoutCount = 0
|
|
43
|
+
this.checkoutNameStack = []
|
|
27
44
|
this.connection = undefined
|
|
28
45
|
}
|
|
29
46
|
|
|
@@ -50,6 +67,7 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
|
50
67
|
const previousConnection = this.connection
|
|
51
68
|
|
|
52
69
|
this.activeCheckoutCount = 0
|
|
70
|
+
this.checkoutNameStack = []
|
|
53
71
|
this.connection = undefined
|
|
54
72
|
|
|
55
73
|
await previousConnection.close()
|
|
@@ -59,6 +77,7 @@ export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
|
59
77
|
this.connection = await this.spawnConnection()
|
|
60
78
|
}
|
|
61
79
|
|
|
80
|
+
this.checkoutNameStack.push(options.name)
|
|
62
81
|
await this.connection.setConnectionCheckoutName(options.name)
|
|
63
82
|
this.activeCheckoutCount++
|
|
64
83
|
|
|
@@ -770,7 +770,7 @@ class VelociousDatabaseRecord {
|
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
prototype[`${relationshipName}OrLoad`] = async function() {
|
|
773
|
-
return await this.relationshipOrLoad(relationshipName
|
|
773
|
+
return await this.relationshipOrLoad(relationshipName)
|
|
774
774
|
}
|
|
775
775
|
|
|
776
776
|
prototype[`set${inflection.camelize(relationshipName)}`] = function(/** @type {VelociousDatabaseRecord | null | undefined} */ model) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
import {POOL_CONFIGURATION_KEY} from "../pool/base.js"
|
|
4
|
+
|
|
3
5
|
const DEFAULT_INSERT_CHUNK_SIZE = 100
|
|
4
6
|
const DEFAULT_QUERY_CHUNK_SIZE = 500
|
|
5
7
|
const DEFAULT_STREAM_BATCH_SIZE = 1000
|
|
@@ -95,6 +97,56 @@ export default class DataCopier {
|
|
|
95
97
|
return sourceRowsByTableName
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Moves every plan table's rows for `keyValue` from the source into the target. The target
|
|
102
|
+
* write commits before the source delete begins, so a target failure leaves the source
|
|
103
|
+
* untouched and a source-delete failure can be retried safely. When the source no longer has
|
|
104
|
+
* matching rows, the method returns the empty traversal without changing the target.
|
|
105
|
+
*
|
|
106
|
+
* `transformRow` can change target-only values such as a tenant ownership column. It receives
|
|
107
|
+
* a shallow clone and must preserve the configured id column so retries address the same rows.
|
|
108
|
+
* @param {string} keyValue - Tenant key selecting the rows to move.
|
|
109
|
+
* @param {{transformRow?: (args: {row: Record<string, unknown>, tableName: string}) => Record<string, unknown>}} [options] - Optional target-row transformation.
|
|
110
|
+
* @returns {Promise<Map<string, Record<string, unknown>[]>>} - Rows written to the target, grouped by table name.
|
|
111
|
+
*/
|
|
112
|
+
async move(keyValue, {transformRow} = {}) {
|
|
113
|
+
const sourceDbWithPoolKey = /** @type {import("../drivers/base.js").default & {[POOL_CONFIGURATION_KEY]?: string}} */ (this.sourceDb)
|
|
114
|
+
const targetDbWithPoolKey = /** @type {import("../drivers/base.js").default & {[POOL_CONFIGURATION_KEY]?: string}} */ (this.targetDb)
|
|
115
|
+
const sourceReuseKey = sourceDbWithPoolKey[POOL_CONFIGURATION_KEY]
|
|
116
|
+
const targetReuseKey = targetDbWithPoolKey[POOL_CONFIGURATION_KEY]
|
|
117
|
+
const sameResolvedDatabase = this.sourceDb.configuration === this.targetDb.configuration
|
|
118
|
+
&& sourceReuseKey !== undefined
|
|
119
|
+
&& sourceReuseKey === targetReuseKey
|
|
120
|
+
|
|
121
|
+
if (this.sourceDb === this.targetDb || sameResolvedDatabase) {
|
|
122
|
+
throw new Error("DataCopier move requires different physical databases.")
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const sourceRowsByTableName = await this.loadRows(this.sourceDb, keyValue)
|
|
126
|
+
|
|
127
|
+
if (!this.rowsByTableNameHasRows(sourceRowsByTableName)) {
|
|
128
|
+
return sourceRowsByTableName
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const targetRowsByTableName = this.transformRows({rowsByTableName: sourceRowsByTableName, transformRow})
|
|
132
|
+
|
|
133
|
+
await this.targetDb.withDisabledForeignKeys(async () => {
|
|
134
|
+
await this.targetDb.transaction(async () => {
|
|
135
|
+
await this.deleteRows({db: this.targetDb, rowsByTableName: sourceRowsByTableName})
|
|
136
|
+
await this.insertRows({db: this.targetDb, rowsByTableName: targetRowsByTableName})
|
|
137
|
+
await this.assertRowsExist({db: this.targetDb, rowsByTableName: targetRowsByTableName})
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
await this.sourceDb.withDisabledForeignKeys(async () => {
|
|
142
|
+
await this.sourceDb.transaction(async () => {
|
|
143
|
+
await this.deleteRows({db: this.sourceDb, rowsByTableName: sourceRowsByTableName})
|
|
144
|
+
})
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
return targetRowsByTableName
|
|
148
|
+
}
|
|
149
|
+
|
|
98
150
|
/**
|
|
99
151
|
* Deletes one tenant's rows from the target database, children before parents, with
|
|
100
152
|
* foreign keys disabled inside a single transaction. This is `copy` without the reinsert:
|
|
@@ -409,6 +461,15 @@ export default class DataCopier {
|
|
|
409
461
|
* @returns {Promise<void>}
|
|
410
462
|
*/
|
|
411
463
|
async deleteTargetRows(rowsByTableName) {
|
|
464
|
+
await this.deleteRows({db: this.targetDb, rowsByTableName})
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Deletes the supplied rows from `db`, children before parents.
|
|
469
|
+
* @param {{db: import("../drivers/base.js").default, rowsByTableName: Map<string, Record<string, unknown>[]>}} args - Database and rows to delete.
|
|
470
|
+
* @returns {Promise<void>}
|
|
471
|
+
*/
|
|
472
|
+
async deleteRows({db, rowsByTableName}) {
|
|
412
473
|
for (const tableConfig of [...this.tablePlan].reverse()) {
|
|
413
474
|
const rowIds = uniqueStrings((rowsByTableName.get(tableConfig.tableName) || []).map((row) => row[this.idColumn]))
|
|
414
475
|
|
|
@@ -416,13 +477,13 @@ export default class DataCopier {
|
|
|
416
477
|
continue
|
|
417
478
|
}
|
|
418
479
|
|
|
419
|
-
const quotedTable =
|
|
420
|
-
const quotedIdColumn =
|
|
480
|
+
const quotedTable = db.quoteTable(tableConfig.tableName)
|
|
481
|
+
const quotedIdColumn = db.quoteColumn(this.idColumn)
|
|
421
482
|
|
|
422
483
|
for (const rowIdsChunk of chunks(rowIds, this.queryChunkSize)) {
|
|
423
484
|
await this.executeQuietQuery(
|
|
424
|
-
|
|
425
|
-
`DELETE FROM ${quotedTable} WHERE ${quotedIdColumn} IN (${this.quotedValuesSql(
|
|
485
|
+
db,
|
|
486
|
+
`DELETE FROM ${quotedTable} WHERE ${quotedIdColumn} IN (${this.quotedValuesSql(db, rowIdsChunk)})`
|
|
426
487
|
)
|
|
427
488
|
}
|
|
428
489
|
}
|
|
@@ -435,6 +496,15 @@ export default class DataCopier {
|
|
|
435
496
|
* @returns {Promise<void>}
|
|
436
497
|
*/
|
|
437
498
|
async insertTargetRows(rowsByTableName) {
|
|
499
|
+
await this.insertRows({db: this.targetDb, rowsByTableName})
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Inserts the supplied rows into `db`, parents before children.
|
|
504
|
+
* @param {{db: import("../drivers/base.js").default, rowsByTableName: Map<string, Record<string, unknown>[]>}} args - Database and rows to insert.
|
|
505
|
+
* @returns {Promise<void>}
|
|
506
|
+
*/
|
|
507
|
+
async insertRows({db, rowsByTableName}) {
|
|
438
508
|
for (const tableConfig of this.tablePlan) {
|
|
439
509
|
const rows = rowsByTableName.get(tableConfig.tableName) || []
|
|
440
510
|
|
|
@@ -450,7 +520,7 @@ export default class DataCopier {
|
|
|
450
520
|
for (const rowsChunk of insertChunks) {
|
|
451
521
|
await this.insertRowsQuietly({
|
|
452
522
|
columns,
|
|
453
|
-
db
|
|
523
|
+
db,
|
|
454
524
|
rows: rowsChunk.map((row) => columns.map((column) => row[column])),
|
|
455
525
|
tableName: tableConfig.tableName
|
|
456
526
|
})
|
|
@@ -458,6 +528,65 @@ export default class DataCopier {
|
|
|
458
528
|
}
|
|
459
529
|
}
|
|
460
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Returns whether any table in the loaded traversal contains rows.
|
|
533
|
+
* @param {Map<string, Record<string, unknown>[]>} rowsByTableName - Rows grouped by table name.
|
|
534
|
+
* @returns {boolean} - Whether any table contains rows.
|
|
535
|
+
*/
|
|
536
|
+
rowsByTableNameHasRows(rowsByTableName) {
|
|
537
|
+
for (const rows of rowsByTableName.values()) {
|
|
538
|
+
if (rows.length > 0) {
|
|
539
|
+
return true
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return false
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Clones source rows and applies the optional target-only transformation.
|
|
548
|
+
* @param {{rowsByTableName: Map<string, Record<string, unknown>[]>, transformRow?: (args: {row: Record<string, unknown>, tableName: string}) => Record<string, unknown>}} args - Source rows and optional transformation.
|
|
549
|
+
* @returns {Map<string, Record<string, unknown>[]>} - Cloned rows prepared for the target.
|
|
550
|
+
*/
|
|
551
|
+
transformRows({rowsByTableName, transformRow}) {
|
|
552
|
+
const transformedRowsByTableName = new Map()
|
|
553
|
+
|
|
554
|
+
for (const tableConfig of this.tablePlan) {
|
|
555
|
+
const sourceRows = rowsByTableName.get(tableConfig.tableName) || []
|
|
556
|
+
const transformedRows = sourceRows.map((sourceRow) => {
|
|
557
|
+
const transformedRow = transformRow
|
|
558
|
+
? transformRow({row: {...sourceRow}, tableName: tableConfig.tableName})
|
|
559
|
+
: {...sourceRow}
|
|
560
|
+
|
|
561
|
+
if (String(transformedRow[this.idColumn]) !== String(sourceRow[this.idColumn])) {
|
|
562
|
+
throw new Error(`DataCopier move transform must preserve ${this.idColumn} for table ${tableConfig.tableName}.`)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return transformedRow
|
|
566
|
+
})
|
|
567
|
+
|
|
568
|
+
transformedRowsByTableName.set(tableConfig.tableName, transformedRows)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return transformedRowsByTableName
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Verifies that every supplied row id exists in `db`.
|
|
576
|
+
* @param {{db: import("../drivers/base.js").default, rowsByTableName: Map<string, Record<string, unknown>[]>}} args - Database and rows to verify.
|
|
577
|
+
* @returns {Promise<void>}
|
|
578
|
+
*/
|
|
579
|
+
async assertRowsExist({db, rowsByTableName}) {
|
|
580
|
+
for (const tableConfig of this.tablePlan) {
|
|
581
|
+
const expectedIds = uniqueStrings((rowsByTableName.get(tableConfig.tableName) || []).map((row) => row[this.idColumn]))
|
|
582
|
+
const existingIds = await this.queryExistingIds({db, ids: expectedIds, tableName: tableConfig.tableName})
|
|
583
|
+
|
|
584
|
+
if (existingIds.size !== expectedIds.length) {
|
|
585
|
+
throw new Error(`DataCopier move target verification failed for table ${tableConfig.tableName}.`)
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
461
590
|
/**
|
|
462
591
|
* Quotes and comma-joins values for an SQL `IN (...)` list against the given database.
|
|
463
592
|
* @param {import("../drivers/base.js").default} db - Database whose quoting rules format the values.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
1
3
|
import BaseCommand from "../../../../../cli/base-command.js"
|
|
2
4
|
import deburrColumnName from "../../../../../utils/deburr-column-name.js"
|
|
3
5
|
import fileExists from "../../../../../utils/file-exists.js"
|
|
@@ -339,7 +341,7 @@ export default class DbGenerateModel extends BaseCommand {
|
|
|
339
341
|
fileContent += " /**\n"
|
|
340
342
|
fileContent += ` * @returns {Promise<import("${modelFilePath}").default | undefined>}\n`
|
|
341
343
|
fileContent += " */\n"
|
|
342
|
-
fileContent += ` ${relationship.getRelationshipName()}OrLoad() { return /** @type {Promise<import("${modelFilePath}").default | undefined>} */ (this.relationshipOrLoad("${relationship.getRelationshipName()}"
|
|
344
|
+
fileContent += ` ${relationship.getRelationshipName()}OrLoad() { return /** @type {Promise<import("${modelFilePath}").default | undefined>} */ (this.relationshipOrLoad("${relationship.getRelationshipName()}")) }\n`
|
|
343
345
|
|
|
344
346
|
fileContent += "\n"
|
|
345
347
|
fileContent += " /**\n"
|
|
@@ -1020,12 +1020,24 @@ export default class VelociousEnvironmentHandlerNode extends Base{
|
|
|
1020
1020
|
const {default: BackgroundJobsStore} = await import("../background-jobs/store.js")
|
|
1021
1021
|
const store = new BackgroundJobsStore({configuration: this.getConfiguration()})
|
|
1022
1022
|
const databaseIdentifier = store.getDatabaseIdentifier() ?? "default"
|
|
1023
|
+
const frameworkDb = dbs[databaseIdentifier]
|
|
1024
|
+
|
|
1025
|
+
// Only ensure the framework schema when the background-jobs database is actually
|
|
1026
|
+
// part of this migrate operation. When it isn't among the migrated set — e.g.
|
|
1027
|
+
// `db:tenants:migrate <tenant>`, which migrates only tenant databases — the
|
|
1028
|
+
// framework store lives elsewhere (typically the default DB) and was already
|
|
1029
|
+
// ensured by the plain `db:migrate` that precedes it. Reaching into it here would
|
|
1030
|
+
// open a fresh connection to that shared database and re-run the concurrency
|
|
1031
|
+
// reconcile UPDATEs; under `db:tenants:migrate --parallel N` that happens once per
|
|
1032
|
+
// tenant worker, and the concurrent auto-committed UPDATEs on the shared
|
|
1033
|
+
// background_jobs / background_job_concurrency rows InnoDB-deadlock
|
|
1034
|
+
// (ER_LOCK_DEADLOCK). So skip when the framework DB isn't in this set; the runtime
|
|
1035
|
+
// store still creates it lazily if a plain migrate never ran.
|
|
1036
|
+
if (!frameworkDb) return
|
|
1023
1037
|
|
|
1024
1038
|
// Reuse the connection db:migrate already holds for this database; opening a
|
|
1025
|
-
// nested checkout would deadlock a database whose pool is capped at one
|
|
1026
|
-
|
|
1027
|
-
// this passes undefined and the store checks out its own (that pool is free).
|
|
1028
|
-
await store.ensureSchema(dbs[databaseIdentifier])
|
|
1039
|
+
// nested checkout would deadlock a database whose pool is capped at one connection.
|
|
1040
|
+
await store.ensureSchema(frameworkDb)
|
|
1029
1041
|
}
|
|
1030
1042
|
|
|
1031
1043
|
/**
|
|
@@ -299,6 +299,13 @@ export default class BackgroundJobsStore {
|
|
|
299
299
|
* @returns {Promise<void>} - Resolves when the schema is present.
|
|
300
300
|
*/
|
|
301
301
|
_applySchema(db: import("../database/drivers/base.js").default): Promise<void>;
|
|
302
|
+
/**
|
|
303
|
+
* Creates or upgrades the background-jobs tables, columns and concurrency rows on
|
|
304
|
+
* the given connection. Serialized per process by {@link BackgroundJobsStore#_applySchema}.
|
|
305
|
+
* @param {import("../database/drivers/base.js").default} db - Database connection.
|
|
306
|
+
* @returns {Promise<void>} - Resolves when the schema is present.
|
|
307
|
+
*/
|
|
308
|
+
_applySchemaSteps(db: import("../database/drivers/base.js").default): Promise<void>;
|
|
302
309
|
/**
|
|
303
310
|
* Runs ensure migrations table.
|
|
304
311
|
* @param {import("../database/drivers/base.js").default} db - Database connection.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/background-jobs/store.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/background-jobs/store.js"],"names":[],"mappings":"AAuEA;IACE;;;;;OAKG;IACH,mDAHG;QAAoD,aAAa,EAAzD,OAAO,qBAAqB,EAAE,OAAO;QACvB,kBAAkB;KAC1C,EAOA;IALC,qDAAkC;IAClC,uCAA4C;IAC5C,eAA8B;IAC9B,oCAAyB;IACzB,qCAAwC;IAG1C;;;OAGG;IACH,yBAFa,MAAM,CAMlB;IAED;;;OAGG;IACH,eAFa,OAAO,CAAC,IAAI,CAAC,CAgBzB;IAED;;;;;;;;;;;OAWG;IACH,kBALW,OAAO,6BAA6B,EAAE,OAAO,GAG3C,OAAO,CAAC,IAAI,CAAC,CASzB;IAED;;;;;;;OAOG;IACH,oCALG;QAAqB,OAAO,EAApB,MAAM;QACS,IAAI,EAAnB,KAAK,CAAC,OAAC,CAAC;QACyC,OAAO;KAChE,GAAU,OAAO,CAAC,MAAM,CAAC,CAmE3B;IAED;;;;;OAKG;IACH,wBAHG;QAAmH,aAAa;KAChI,GAAU,OAAO,CAAC,OAAO,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC,CAYjE;IAED;;;;;;;OAOG;IACH,oBAFa,OAAO,CAAC,OAAO,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC,CAQjE;IAED;;;;;;;OAOG;IACH,2DALG;QAA4D,EAAE,EAAtD,OAAO,6BAA6B,EAAE,OAAO;QAC5B,mBAAmB,EAApC,IAAI,GAAG,GAAG;QACiG,aAAa;KAChI,GAAU,OAAO,CAAC,OAAO,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC,CAwCjE;IAED;;;;;;;;;;;;OAYG;IACH,2BAHW,OAAO,6BAA6B,EAAE,OAAO,GAC3C,MAAM,GAAG,IAAI,CAqBzB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,OAAO,CAAC,OAAO,YAAY,EAAE,gBAAgB,GAAG,IAAI,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