@payloadcms/drizzle 4.0.0-internal.011fd46 → 4.0.0-internal.0b9bec1
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/LICENSE.md +1 -1
- package/dist/createTableName.d.ts.map +1 -1
- package/dist/exports/postgres.d.ts +1 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +1 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +1 -0
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +1 -0
- package/dist/exports/sqlite.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/postgres/createDatabase.d.ts.map +1 -1
- package/dist/postgres/createExtensions.d.ts.map +1 -1
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts +12 -0
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js +22 -0
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
- package/dist/postgres/schema/buildDrizzleTable.d.ts.map +1 -1
- package/dist/postgres/schema/geometryColumn.d.ts +2 -2
- package/dist/postgres/schema/geometryColumn.d.ts.map +1 -1
- package/dist/queries/addJoinTable.d.ts +1 -1
- package/dist/queries/addJoinTable.d.ts.map +1 -1
- package/dist/queries/buildOrderBy.d.ts +1 -1
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/getTableAlias.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/buildDrizzleRelations.d.ts.map +1 -1
- package/dist/schema/buildRawSchema.d.ts.map +1 -1
- package/dist/schema/idToUUID.d.ts.map +1 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +1 -0
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/withDefault.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts +12 -0
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js +22 -0
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js.map +1 -0
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
- package/dist/transform/read/hasManyText.d.ts.map +1 -1
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/relationship.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/numbers.d.ts.map +1 -1
- package/dist/transform/write/relationships.d.ts.map +1 -1
- package/dist/transform/write/selects.d.ts.map +1 -1
- package/dist/transform/write/texts.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -3
- package/dist/types.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +37 -0
- package/dist/updateJobs.js.map +1 -1
- package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/handleUpsertError.d.ts.map +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/insertArrays.js +2 -1
- package/dist/upsertRow/insertArrays.js.map +1 -1
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts.map +1 -1
- package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/createBlocksMap.d.ts.map +1 -1
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/escapeSQLValue.d.ts.map +1 -1
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -1
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -1
- package/dist/utilities/getArrayRelationName.d.ts.map +1 -1
- package/dist/utilities/getCollectionIdType.d.ts.map +1 -1
- package/dist/utilities/getMigrationTemplate.d.ts.map +1 -1
- package/dist/utilities/getNameFromDrizzleTable.d.ts.map +1 -1
- package/dist/utilities/getPrimaryDb.d.ts +1 -1
- package/dist/utilities/getPrimaryDb.d.ts.map +1 -1
- package/dist/utilities/getTransaction.d.ts +1 -1
- package/dist/utilities/getTransaction.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -1
- package/dist/utilities/isUUIDType.d.ts.map +1 -1
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts +6 -0
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts.map +1 -0
- package/dist/utilities/jobsProcessingLeaseMigration.js +64 -0
- package/dist/utilities/jobsProcessingLeaseMigration.js.map +1 -0
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js +186 -0
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js.map +1 -0
- package/dist/utilities/json.d.ts.map +1 -1
- package/dist/utilities/migrationTableExists.d.ts.map +1 -1
- package/dist/utilities/parseError.d.ts.map +1 -1
- package/dist/utilities/pushDevSchema.d.ts.map +1 -1
- package/dist/utilities/rawConstraint.d.ts.map +1 -1
- package/dist/utilities/sanitizePathSegment.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/find/chainMethods.d.ts +0 -20
- package/dist/find/chainMethods.d.ts.map +0 -1
- package/dist/find/chainMethods.js +0 -16
- package/dist/find/chainMethods.js.map +0 -1
package/dist/updateJobs.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { and, inArray, isNull, lte, or } from 'drizzle-orm';
|
|
1
2
|
import toSnakeCase from 'to-snake-case';
|
|
2
3
|
import { findMany } from './find/findMany.js';
|
|
4
|
+
import { transformForWrite } from './transform/write/index.js';
|
|
3
5
|
import { upsertRow } from './upsertRow/index.js';
|
|
4
6
|
import { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js';
|
|
5
7
|
import { getPrimaryDb } from './utilities/getPrimaryDb.js';
|
|
6
8
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
9
|
+
import { markWrite } from './utilities/readAfterWrite.js';
|
|
10
|
+
const isInitialJobClaim = (data)=>typeof data.processingToken === 'string' && typeof data.processingUntil === 'string' && Object.keys(data).every((field)=>field === 'processingToken' || field === 'processingUntil' || field === 'updatedAt');
|
|
7
11
|
export const updateJobs = async function updateMany({ id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg }) {
|
|
8
12
|
if (!data?.log?.length && !(data.log && typeof data.log === 'object' && '$push' in data.log)) {
|
|
9
13
|
delete data.log;
|
|
@@ -54,6 +58,39 @@ export const updateJobs = async function updateMany({ id, data, limit: limitArg,
|
|
|
54
58
|
return [];
|
|
55
59
|
}
|
|
56
60
|
const db = getPrimaryDb(this, await getTransaction(this, req));
|
|
61
|
+
if (isInitialJobClaim(data)) {
|
|
62
|
+
// Atomically claim jobs so multiple workers cannot pick up the same job.
|
|
63
|
+
// We don't need FOR UPDATE SKIP LOCKED here because of the compare-and-swap-style update using processingUntil and processingToken.
|
|
64
|
+
// The first update makes the where clause fail for other workers, so they cannot claim the same job.
|
|
65
|
+
const _db = db;
|
|
66
|
+
const table = this.tables[tableName];
|
|
67
|
+
const now = new Date().toISOString();
|
|
68
|
+
const { row } = transformForWrite({
|
|
69
|
+
adapter: this,
|
|
70
|
+
data,
|
|
71
|
+
enableAtomicWrites: true,
|
|
72
|
+
fields: collection.flattenedFields,
|
|
73
|
+
tableName
|
|
74
|
+
});
|
|
75
|
+
if (typeof row.updatedAt === 'undefined' || row.updatedAt === null) {
|
|
76
|
+
delete row.updatedAt;
|
|
77
|
+
}
|
|
78
|
+
const jobIDs = jobs.docs.map((job)=>job.id);
|
|
79
|
+
const claimedRows = await _db.update(table).set(row).where(and(inArray(table.id, jobIDs), or(isNull(table.processingUntil), lte(table.processingUntil, now)))).returning({
|
|
80
|
+
id: table.id
|
|
81
|
+
});
|
|
82
|
+
if (claimedRows.length) {
|
|
83
|
+
markWrite(this);
|
|
84
|
+
}
|
|
85
|
+
if (returning === false) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const claimedIDs = new Set(claimedRows.map(({ id })=>id));
|
|
89
|
+
return jobs.docs.filter((job)=>claimedIDs.has(job.id)).map((job)=>({
|
|
90
|
+
...job,
|
|
91
|
+
...data
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
57
94
|
const results = [];
|
|
58
95
|
// TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.
|
|
59
96
|
for (const job of jobs.docs){
|
package/dist/updateJobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { UpdateJobs, Where } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const job of jobs.docs) {\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","findMany","upsertRow","shouldUseOptimizedUpsertRow","getPrimaryDb","getTransaction","updateJobs","updateMany","id","
|
|
1
|
+
{"version":3,"sources":["../src/updateJobs.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateJobs, Where } from 'payload'\n\nimport { and, inArray, isNull, lte, or } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { transformForWrite } from './transform/write/index.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { shouldUseOptimizedUpsertRow } from './upsertRow/shouldUseOptimizedUpsertRow.js'\nimport { getPrimaryDb } from './utilities/getPrimaryDb.js'\nimport { getTransaction } from './utilities/getTransaction.js'\nimport { markWrite } from './utilities/readAfterWrite.js'\n\nconst isInitialJobClaim = (data: Record<string, unknown>): boolean =>\n typeof data.processingToken === 'string' &&\n typeof data.processingUntil === 'string' &&\n Object.keys(data).every(\n (field) => field === 'processingToken' || field === 'processingUntil' || field === 'updatedAt',\n )\n\nexport const updateJobs: UpdateJobs = async function updateMany(\n this: DrizzleAdapter,\n { id, data, limit: limitArg, req, returning, sort: sortArg, where: whereArg },\n) {\n if (\n !(data?.log as object[])?.length &&\n !(data.log && typeof data.log === 'object' && '$push' in data.log)\n ) {\n delete data.log\n }\n\n const whereToUse: Where = id ? { id: { equals: id } } : whereArg\n const limit = id ? 1 : limitArg\n\n const collection = this.payload.collections['payload-jobs'].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const useOptimizedUpsertRow = shouldUseOptimizedUpsertRow({\n data,\n fields: collection.flattenedFields,\n })\n\n if (useOptimizedUpsertRow && id) {\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n const result = await upsertRow({\n id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n return returning === false ? null : [result]\n }\n\n const jobs = await findMany({\n adapter: this,\n collectionSlug: 'payload-jobs',\n fields: collection.flattenedFields,\n limit: id ? 1 : limit,\n pagination: false,\n req,\n sort,\n tableName,\n where: whereToUse,\n })\n if (!jobs.docs.length) {\n return []\n }\n\n const db = getPrimaryDb(this, await getTransaction(this, req))\n\n if (isInitialJobClaim(data)) {\n // Atomically claim jobs so multiple workers cannot pick up the same job.\n // We don't need FOR UPDATE SKIP LOCKED here because of the compare-and-swap-style update using processingUntil and processingToken.\n // The first update makes the where clause fail for other workers, so they cannot claim the same job.\n const _db = db as LibSQLDatabase\n const table = this.tables[tableName]\n const now = new Date().toISOString()\n const { row } = transformForWrite({\n adapter: this,\n data,\n enableAtomicWrites: true,\n fields: collection.flattenedFields,\n tableName,\n })\n\n if (typeof row.updatedAt === 'undefined' || row.updatedAt === null) {\n delete row.updatedAt\n }\n\n const jobIDs = jobs.docs.map((job) => job.id)\n const claimedRows = await _db\n .update(table)\n .set(row)\n .where(\n and(\n inArray(table.id, jobIDs),\n or(isNull(table.processingUntil), lte(table.processingUntil, now)),\n ),\n )\n .returning({ id: table.id })\n\n if (claimedRows.length) {\n markWrite(this)\n }\n\n if (returning === false) {\n return null\n }\n\n const claimedIDs = new Set(claimedRows.map(({ id }) => id))\n return jobs.docs.filter((job) => claimedIDs.has(job.id)).map((job) => ({ ...job, ...data }))\n }\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const job of jobs.docs) {\n const updateData = useOptimizedUpsertRow\n ? data\n : {\n ...job,\n ...data,\n }\n\n const result = await upsertRow({\n id: job.id,\n adapter: this,\n collectionSlug: 'payload-jobs',\n data: updateData,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n operation: 'update',\n req,\n tableName,\n })\n\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["and","inArray","isNull","lte","or","toSnakeCase","findMany","transformForWrite","upsertRow","shouldUseOptimizedUpsertRow","getPrimaryDb","getTransaction","markWrite","isInitialJobClaim","data","processingToken","processingUntil","Object","keys","every","field","updateJobs","updateMany","id","limit","limitArg","req","returning","sort","sortArg","where","whereArg","log","length","whereToUse","equals","collection","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","useOptimizedUpsertRow","fields","flattenedFields","db","result","adapter","collectionSlug","ignoreResult","operation","jobs","pagination","docs","_db","table","tables","now","Date","toISOString","row","enableAtomicWrites","updatedAt","jobIDs","map","job","claimedRows","update","set","claimedIDs","Set","filter","has","results","updateData","push"],"mappings":"AAGA,SAASA,GAAG,EAAEC,OAAO,EAAEC,MAAM,EAAEC,GAAG,EAAEC,EAAE,QAAQ,cAAa;AAC3D,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,2BAA2B,QAAQ,6CAA4C;AAC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E5B,IAAI+C,YAAYrC,MAAM,EAAE;YACtBrB,UAAU,IAAI;QAChB;QAEA,IAAIe,cAAc,OAAO;YACvB,OAAO;QACT;QAEA,MAAM8C,aAAa,IAAIC,IAAIJ,YAAYF,GAAG,CAAC,CAAC,EAAE7C,EAAE,EAAE,GAAKA;QACvD,OAAOgC,KAAKE,IAAI,CAACkB,MAAM,CAAC,CAACN,MAAQI,WAAWG,GAAG,CAACP,IAAI9C,EAAE,GAAG6C,GAAG,CAAC,CAACC,MAAS,CAAA;gBAAE,GAAGA,GAAG;gBAAE,GAAGvD,IAAI;YAAC,CAAA;IAC3F;IAEA,MAAM+D,UAAU,EAAE;IAElB,yHAAyH;IACzH,KAAK,MAAMR,OAAOd,KAAKE,IAAI,CAAE;QAC3B,MAAMqB,aAAahC,wBACfhC,OACA;YACE,GAAGuD,GAAG;YACN,GAAGvD,IAAI;QACT;QAEJ,MAAMoC,SAAS,MAAM1C,UAAU;YAC7Be,IAAI8C,IAAI9C,EAAE;YACV4B,SAAS,IAAI;YACbC,gBAAgB;YAChBtC,MAAMgE;YACN7B;YACAF,QAAQX,WAAWY,eAAe;YAClCK,cAAc1B,cAAc;YAC5B2B,WAAW;YACX5B;YACAc;QACF;QAEAqC,QAAQE,IAAI,CAAC7B;IACf;IAEA,IAAIvB,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOkD;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteExistingArrayRows.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"deleteExistingArrayRows.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingArrayRows.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,uBAAuB,0CAKjC,IAAI,KAAG,OAAO,CAAC,IAAI,CAUrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"deleteExistingRowsByPath.d.ts","sourceRoot":"","sources":["../../src/upsertRow/deleteExistingRowsByPath.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,EAAE,OAAO,CAAA;IACjB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,wBAAwB,oGASlC,IAAI,KAAG,OAAO,CAAC,IAAI,CA4CrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpsertError.d.ts","sourceRoot":"","sources":["../../src/upsertRow/handleUpsertError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"handleUpsertError.d.ts","sourceRoot":"","sources":["../../src/upsertRow/handleUpsertError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,cAAc,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,qFAQ3B,qBAAqB,KAAG,KAkE1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAqBtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/upsertRow/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAqBtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,+KAqB3E,IAAI,KAAG,OAAO,CAAC,CAAC,CAotBlB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAC1C,CAAA;AAYD,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"insertArrays.d.ts","sourceRoot":"","sources":["../../src/upsertRow/insertArrays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,cAAc,CAAA;IACvB,MAAM,EAAE;QACN,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;KACxC,EAAE,CAAA;IACH,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,CAAA;IAClD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAC1C,CAAA;AAYD,eAAO,MAAM,YAAY,kDAMtB,IAAI,KAAG,OAAO,CAAC,IAAI,CAiGrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n if (!arraysByTable || Object.keys(arraysByTable).length === 0) {\n return\n }\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows: { _uuid: string; id: number }[]) => {\n const { id } = rows.find((each) => each._uuid === arrayRow.row._uuid)\n return id\n }\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await adapter.insert({\n db,\n tableName,\n values: row.rows,\n })\n\n insertedRows.forEach((row) => {\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n uuidMap[row._uuid] = row.id\n }\n })\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: row.locales,\n })\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","uuidMap","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","keys","length","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","find","each","_uuid","insertedRows","insert","values","tables","localesSuffix","map","localeRow"],"mappings":"AAuBA,OAAO,MAAMA,eAAe,OAAO,EACjCC,OAAO,EACPC,MAAM,EACNC,EAAE,EACFC,UAAU,EACVC,UAAU,CAAC,CAAC,EACP;IACL,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCJ,OAAOK,OAAO,CAAC,CAACC,eAAeC;QAC7B,IAAI,CAACD,iBAAiBE,OAAOC,IAAI,CAACH,eAAeI,MAAM,KAAK,GAAG;YAC7D;QACF;QACAF,OAAOG,OAAO,CAACL,eAAeD,OAAO,CAAC,CAAC,CAACO,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACT,WAAW,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AAM,CAAC;gBAClC7B;gBACAW;gBACAmB,QAAQX,IAAIL,IAAI;YAClB;YAEAc,aAAaxB,OAAO,CAAC,CAACe;gBACpB,IACE,OAAOA,IAAIQ,KAAK,KAAK,YACpB,CAAA,OAAOR,IAAIH,EAAE,KAAK,YAAY,OAAOG,IAAIH,EAAE,KAAK,QAAO,GACxD;oBACAd,OAAO,CAACiB,IAAIQ,KAAK,CAAC,GAAGR,IAAIH,EAAE;gBAC7B;YACF;QACF;QAEA,qBAAqB;QACrB,IAAIlB,QAAQiC,MAAM,CAAC,GAAGpB,YAAYb,QAAQkC,aAAa,EAAE,CAAC,IAAIb,IAAIN,OAAO,CAACJ,MAAM,GAAG,GAAG;YACpF,IAAI,CAACU,IAAIN,OAAO,CAAC,EAAE,CAACO,SAAS,EAAE;gBAC7BD,IAAIN,OAAO,GAAGM,IAAIN,OAAO,CAACoB,GAAG,CAAC,CAACC;oBAC7B,IAAI,OAAOA,UAAUV,YAAY,KAAK,YAAY;wBAChDU,UAAUd,SAAS,GAAGc,UAAUV,YAAY,CAACI;wBAC7C,OAAOM,UAAUV,YAAY;oBAC/B;oBACA,OAAOU;gBACT;YACF;YACA,MAAMpC,QAAQ+B,MAAM,CAAC;gBACnB7B;gBACAW,WAAW,GAAGA,YAAYb,QAAQkC,aAAa,EAAE;gBACjDF,QAAQX,IAAIN,OAAO;YACrB;QACF;QAEA,0DAA0D;QAC1D,IAAIM,IAAIpB,MAAM,CAACU,MAAM,GAAG,GAAG;YACzB,MAAMZ,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAY2B;
|
|
1
|
+
{"version":3,"sources":["../../src/upsertRow/insertArrays.ts"],"sourcesContent":["import type { ArrayRowToInsert } from '../transform/write/types.js'\nimport type { DrizzleAdapter, DrizzleTransaction } from '../types.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n parentRows: Record<string, unknown>[]\n uuidMap?: Record<string, number | string>\n}\n\ntype RowsByTable = {\n [tableName: string]: {\n arrays: {\n [tableName: string]: ArrayRowToInsert[]\n }[]\n locales: Record<string, unknown>[]\n rows: Record<string, unknown>[]\n }\n}\n\nexport const insertArrays = async ({\n adapter,\n arrays,\n db,\n parentRows,\n uuidMap = {},\n}: Args): Promise<void> => {\n // Maintain a map of flattened rows by table\n const rowsByTable: RowsByTable = {}\n\n arrays.forEach((arraysByTable, parentRowIndex) => {\n if (!arraysByTable || Object.keys(arraysByTable).length === 0) {\n return\n }\n Object.entries(arraysByTable).forEach(([tableName, arrayRows]) => {\n // If the table doesn't exist in map, initialize it\n if (!rowsByTable[tableName]) {\n rowsByTable[tableName] = {\n arrays: [],\n locales: [],\n rows: [],\n }\n }\n\n const parentID = parentRows[parentRowIndex].id\n\n // Add any sub arrays that need to be created\n // We will call this recursively below\n arrayRows.forEach((arrayRow) => {\n if (Object.keys(arrayRow.arrays).length > 0) {\n rowsByTable[tableName].arrays.push(arrayRow.arrays)\n }\n\n // Set up parent IDs for both row and locale row\n arrayRow.row._parentID = parentID\n rowsByTable[tableName].rows.push(arrayRow.row)\n\n Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => {\n arrayRowLocaleData._parentID = arrayRow.row.id\n arrayRowLocaleData._locale = arrayRowLocale\n rowsByTable[tableName].locales.push(arrayRowLocaleData)\n if (!arrayRow.row.id) {\n arrayRowLocaleData._getParentID = (rows: { _uuid: string; id: number }[]) => {\n const { id } = rows.find((each) => each._uuid === arrayRow.row._uuid)\n return id\n }\n }\n })\n })\n })\n })\n\n // Insert all corresponding arrays\n // (one insert per array table)\n for (const [tableName, row] of Object.entries(rowsByTable)) {\n // the nested arrays need the ID for the parentID foreign key\n let insertedRows: Args['parentRows']\n if (row.rows.length > 0) {\n insertedRows = await adapter.insert({\n db,\n tableName,\n values: row.rows,\n })\n\n insertedRows.forEach((row) => {\n if (\n typeof row._uuid === 'string' &&\n (typeof row.id === 'string' || typeof row.id === 'number')\n ) {\n uuidMap[row._uuid] = row.id\n }\n })\n }\n\n // Insert locale rows\n if (adapter.tables[`${tableName}${adapter.localesSuffix}`] && row.locales.length > 0) {\n if (!row.locales[0]._parentID) {\n row.locales = row.locales.map((localeRow) => {\n if (typeof localeRow._getParentID === 'function') {\n localeRow._parentID = localeRow._getParentID(insertedRows)\n delete localeRow._getParentID\n }\n return localeRow\n })\n }\n await adapter.insert({\n db,\n tableName: `${tableName}${adapter.localesSuffix}`,\n values: row.locales,\n })\n }\n\n // If there are sub arrays, call this function recursively\n if (row.arrays.length > 0) {\n await insertArrays({\n adapter,\n arrays: row.arrays,\n db,\n parentRows: insertedRows,\n uuidMap,\n })\n }\n }\n}\n"],"names":["insertArrays","adapter","arrays","db","parentRows","uuidMap","rowsByTable","forEach","arraysByTable","parentRowIndex","Object","keys","length","entries","tableName","arrayRows","locales","rows","parentID","id","arrayRow","push","row","_parentID","arrayRowLocale","arrayRowLocaleData","_locale","_getParentID","find","each","_uuid","insertedRows","insert","values","tables","localesSuffix","map","localeRow"],"mappings":"AAuBA,OAAO,MAAMA,eAAe,OAAO,EACjCC,OAAO,EACPC,MAAM,EACNC,EAAE,EACFC,UAAU,EACVC,UAAU,CAAC,CAAC,EACP;IACL,4CAA4C;IAC5C,MAAMC,cAA2B,CAAC;IAElCJ,OAAOK,OAAO,CAAC,CAACC,eAAeC;QAC7B,IAAI,CAACD,iBAAiBE,OAAOC,IAAI,CAACH,eAAeI,MAAM,KAAK,GAAG;YAC7D;QACF;QACAF,OAAOG,OAAO,CAACL,eAAeD,OAAO,CAAC,CAAC,CAACO,WAAWC,UAAU;YAC3D,mDAAmD;YACnD,IAAI,CAACT,WAAW,CAACQ,UAAU,EAAE;gBAC3BR,WAAW,CAACQ,UAAU,GAAG;oBACvBZ,QAAQ,EAAE;oBACVc,SAAS,EAAE;oBACXC,MAAM,EAAE;gBACV;YACF;YAEA,MAAMC,WA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CAAA,OAAOR,IAAIH,EAAE,KAAK,YAAY,OAAOG,IAAIH,EAAE,KAAK,QAAO,GACxD;oBACAd,OAAO,CAACiB,IAAIQ,KAAK,CAAC,GAAGR,IAAIH,EAAE;gBAC7B;YACF;QACF;QAEA,qBAAqB;QACrB,IAAIlB,QAAQiC,MAAM,CAAC,GAAGpB,YAAYb,QAAQkC,aAAa,EAAE,CAAC,IAAIb,IAAIN,OAAO,CAACJ,MAAM,GAAG,GAAG;YACpF,IAAI,CAACU,IAAIN,OAAO,CAAC,EAAE,CAACO,SAAS,EAAE;gBAC7BD,IAAIN,OAAO,GAAGM,IAAIN,OAAO,CAACoB,GAAG,CAAC,CAACC;oBAC7B,IAAI,OAAOA,UAAUV,YAAY,KAAK,YAAY;wBAChDU,UAAUd,SAAS,GAAGc,UAAUV,YAAY,CAACI;wBAC7C,OAAOM,UAAUV,YAAY;oBAC/B;oBACA,OAAOU;gBACT;YACF;YACA,MAAMpC,QAAQ+B,MAAM,CAAC;gBACnB7B;gBACAW,WAAW,GAAGA,YAAYb,QAAQkC,aAAa,EAAE;gBACjDF,QAAQX,IAAIN,OAAO;YACrB;QACF;QAEA,0DAA0D;QAC1D,IAAIM,IAAIpB,MAAM,CAACU,MAAM,GAAG,GAAG;YACzB,MAAMZ,aAAa;gBACjBC;gBACAC,QAAQoB,IAAIpB,MAAM;gBAClBC;gBACAC,YAAY2B;gBACZ1B;YACF;QACF;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldUseOptimizedUpsertRow.d.ts","sourceRoot":"","sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"shouldUseOptimizedUpsertRow.d.ts","sourceRoot":"","sources":["../../src/upsertRow/shouldUseOptimizedUpsertRow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,2BAA2B,sBAGrC;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB,QA8EA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"appendPrefixToKeys.d.ts","sourceRoot":"","sources":["../../src/utilities/appendPrefixToKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GAAI,CAAC,OAAO,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,MAAM,KAAG,CAI9E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocksToJsonMigrator.d.ts","sourceRoot":"","sources":["../../src/utilities/blocksToJsonMigrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAExB,OAAO,EAGR,MAAM,SAAS,CAAA;AAchB,OAAO,KAAK,EAGV,oBAAoB,EACpB,cAAc,EACf,MAAM,aAAa,CAAA;AA8rBpB,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"blocksToJsonMigrator.d.ts","sourceRoot":"","sources":["../../src/utilities/blocksToJsonMigrator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAExB,OAAO,EAGR,MAAM,SAAS,CAAA;AAchB,OAAO,KAAK,EAGV,oBAAoB,EACpB,cAAc,EACf,MAAM,aAAa,CAAA;AA8rBpB,eAAO,MAAM,0BAA0B,oDAIpC;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,kBAAkB,EAAE,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,CAAA;CACnF,KAAG,oBAEH,CAAA;AAED,eAAO,MAAM,uBAAuB,YAAa,OAAO,KAAG,oBAQ1D,CAAA;AAED,eAAO,MAAM,2CAA2C,qBAErD;IACD,WAAW,EAAE,MAAM,CAAA;CACpB,KAAG,wBAoCH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCreateMigration.d.ts","sourceRoot":"","sources":["../../src/utilities/buildCreateMigration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAW,MAAM,SAAS,CAAA;AAWvD,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"buildCreateMigration.d.ts","sourceRoot":"","sources":["../../src/utilities/buildCreateMigration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAW,MAAM,SAAS,CAAA;AAWvD,eAAO,MAAM,oBAAoB,qDAI9B;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,EAAE,CAAC,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,CAAA;CACnF,KAAG,eA6IH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildForeignKeyName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildForeignKeyName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"buildForeignKeyName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildForeignKeyName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,mBAAmB,+BAI7B;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MAkBH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildIndexName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildIndexName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"buildIndexName.d.ts","sourceRoot":"","sources":["../../src/utilities/buildIndexName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,eAAO,MAAM,cAAc,6CAKxB;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MAmBH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBlocksMap.d.ts","sourceRoot":"","sources":["../../src/utilities/createBlocksMap.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAC1C,CAAA;AAED,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"createBlocksMap.d.ts","sourceRoot":"","sources":["../../src/utilities/createBlocksMap.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAC1C,CAAA;AAED,eAAO,MAAM,eAAe,SAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,SAyC/D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRelationshipMap.d.ts","sourceRoot":"","sources":["../../src/utilities/createRelationshipMap.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"createRelationshipMap.d.ts","sourceRoot":"","sources":["../../src/utilities/createRelationshipMap.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,SAAU,OAAO,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAqBrF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/utilities/createSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,OAAO,KAAK,EAAE,qBAAqB,EAAkB,MAAM,aAAa,CAAA;AAkCxE,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"createSchemaGenerator.d.ts","sourceRoot":"","sources":["../../src/utilities/createSchemaGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,OAAO,KAAK,EAAE,qBAAqB,EAAkB,MAAM,aAAa,CAAA;AAkCxE,eAAO,MAAM,qBAAqB,4GAO/B;IACD,qBAAqB,EAAE,qBAAqB,CAAA;IAC5C,iBAAiB,EAAE,MAAM,CAAA;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACpB,KAAG,cAiTH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escapeSQLValue.d.ts","sourceRoot":"","sources":["../../src/utilities/escapeSQLValue.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,QAAmB,CAAA;AAEjD,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"escapeSQLValue.d.ts","sourceRoot":"","sources":["../../src/utilities/escapeSQLValue.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,QAAmB,CAAA;AAEjD,eAAO,MAAM,cAAc,UAAW,OAAO,KAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAoBzE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeSchemaHooks.d.ts","sourceRoot":"","sources":["../../src/utilities/executeSchemaHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;CACjC,CAAA;AAED,KAAK,OAAO,GAAG;IACb,eAAe,EAAE,kBAAkB,EAAE,CAAA;IACrC,gBAAgB,EAAE,kBAAkB,EAAE,CAAA;CACvC,GAAG,cAAc,CAAA;AAElB,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,WAAW,EAAE,OAAO,kBAAkB,CAAA;IACtC,MAAM,EAAE,cAAc,CAAA;CACvB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAEpG,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,CAAA;CAC7C,CAAA;AAED,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"executeSchemaHooks.d.ts","sourceRoot":"","sources":["../../src/utilities/executeSchemaHooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;CACjC,CAAA;AAED,KAAK,OAAO,GAAG;IACb,eAAe,EAAE,kBAAkB,EAAE,CAAA;IACrC,gBAAgB,EAAE,kBAAkB,EAAE,CAAA;CACvC,GAAG,cAAc,CAAA;AAElB,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,WAAW,EAAE,OAAO,kBAAkB,CAAA;IACtC,MAAM,EAAE,cAAc,CAAA;CACvB,CAAA;AAED,KAAK,kBAAkB,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAEpG,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,CAAA;CAC7C,CAAA;AAED,eAAO,MAAM,kBAAkB,sBAA6B,IAAI,KAAG,OAAO,CAAC,IAAI,CAkB9E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extendDrizzleTable.d.ts","sourceRoot":"","sources":["../../src/utilities/extendDrizzleTable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnC,KAAK,IAAI,GAAG;IACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAChD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAA;IACnD,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"extendDrizzleTable.d.ts","sourceRoot":"","sources":["../../src/utilities/extendDrizzleTable.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnC,KAAK,IAAI,GAAG;IACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAChD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAA;IACnD,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,oCAAqC,IAAI,KAAG,IAkC1E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getArrayRelationName.d.ts","sourceRoot":"","sources":["../../src/utilities/getArrayRelationName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"getArrayRelationName.d.ts","sourceRoot":"","sources":["../../src/utilities/getArrayRelationName.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,eAAO,MAAM,oBAAoB,gCAI9B;IACD,KAAK,EAAE,UAAU,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;CAClB,WAMA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCollectionIdType.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionIdType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAUjD,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"getCollectionIdType.d.ts","sourceRoot":"","sources":["../../src/utilities/getCollectionIdType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAUjD,eAAO,MAAM,mBAAmB,6BAG7B;IACD,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;CACvB,sBAEA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../../src/utilities/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getMigrationTemplate.d.ts","sourceRoot":"","sources":["../../src/utilities/getMigrationTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,eAAO,MAAM,MAAM,SAAU,MAAM,WAIpB,CAAA;AAEf,eAAO,MAAM,oBAAoB,8CAK9B,qBAAqB,KAAG,MAS1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNameFromDrizzleTable.d.ts","sourceRoot":"","sources":["../../src/utilities/getNameFromDrizzleTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAIxC,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"getNameFromDrizzleTable.d.ts","sourceRoot":"","sources":["../../src/utilities/getNameFromDrizzleTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAIxC,eAAO,MAAM,uBAAuB,UAAW,KAAK,KAAG,MAEtD,CAAA"}
|
|
@@ -2,5 +2,5 @@ import type { DrizzleAdapter, DrizzleTransaction } from '../types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the correct database instance for reads that are part of a write operation.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getPrimaryDb: (adapter: DrizzleAdapter, db: DrizzleAdapter[
|
|
5
|
+
export declare const getPrimaryDb: (adapter: DrizzleAdapter, db: DrizzleAdapter['drizzle'] | DrizzleTransaction) => import("drizzle-orm/libsql").LibSQLDatabase<Record<string, never>> | import("../types.js").PostgresDB | DrizzleTransaction;
|
|
6
6
|
//# sourceMappingURL=getPrimaryDb.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrimaryDb.d.ts","sourceRoot":"","sources":["../../src/utilities/getPrimaryDb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE;;GAEG;AACH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"getPrimaryDb.d.ts","sourceRoot":"","sources":["../../src/utilities/getPrimaryDb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErE;;GAEG;AACH,eAAO,MAAM,YAAY,YACd,cAAc,MACnB,cAAc,CAAC,SAAS,CAAC,GAAG,kBAAkB,+HAMnD,CAAA"}
|
|
@@ -9,5 +9,5 @@ import type { DrizzleAdapter } from '../types.js';
|
|
|
9
9
|
* When read replicas are configured and a write happened recently, returns the
|
|
10
10
|
* unwrapped primary to avoid replication-lag stale reads.
|
|
11
11
|
*/
|
|
12
|
-
export declare const getTransaction: <T extends DrizzleAdapter = DrizzleAdapter>(adapter: T, req?: Partial<PayloadRequest>) => Promise<T[
|
|
12
|
+
export declare const getTransaction: <T extends DrizzleAdapter = DrizzleAdapter>(adapter: T, req?: Partial<PayloadRequest>) => Promise<T['drizzle']>;
|
|
13
13
|
//# sourceMappingURL=getTransaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/getTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,cAAc,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"getTransaction.d.ts","sourceRoot":"","sources":["../../src/utilities/getTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAIjD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,cAAc,GAAG,cAAc,WACnE,CAAC,QACJ,OAAO,CAAC,cAAc,CAAC,KAC5B,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAStB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hasLocalesTable.d.ts","sourceRoot":"","sources":["../../src/utilities/hasLocalesTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"hasLocalesTable.d.ts","sourceRoot":"","sources":["../../src/utilities/hasLocalesTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,eAAO,MAAM,eAAe,mCAGzB;IACD,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC5B,KAAG,OAyBH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPolymorphicRelationship.d.ts","sourceRoot":"","sources":["../../src/utilities/isPolymorphicRelationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"isPolymorphicRelationship.d.ts","sourceRoot":"","sources":["../../src/utilities/isPolymorphicRelationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,yBAAyB,UAC7B,OAAO,KACb,KAAK,IAAI;IACV,UAAU,EAAE,cAAc,CAAA;IAC1B,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CASvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUUIDType.d.ts","sourceRoot":"","sources":["../../src/utilities/isUUIDType.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"isUUIDType.d.ts","sourceRoot":"","sources":["../../src/utilities/isUUIDType.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,WAAY,MAAM,KAAG,OAAmD,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DynamicMigrationTemplate } from 'payload';
|
|
2
|
+
export declare const buildDynamicPredefinedJobsProcessingLeaseMigration: ({ dialect, packageName, }: {
|
|
3
|
+
dialect: 'postgres' | 'sqlite';
|
|
4
|
+
packageName: string;
|
|
5
|
+
}) => DynamicMigrationTemplate;
|
|
6
|
+
//# sourceMappingURL=jobsProcessingLeaseMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobsProcessingLeaseMigration.d.ts","sourceRoot":"","sources":["../../src/utilities/jobsProcessingLeaseMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAqEvD,eAAO,MAAM,kDAAkD,8BAG5D;IACD,OAAO,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAA;CACpB,KAAG,wBAwCH,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import toSnakeCase from 'to-snake-case';
|
|
4
|
+
const getDefaultIndexName = (name)=>{
|
|
5
|
+
const suffix = '_idx';
|
|
6
|
+
return `${name.slice(0, 60 - suffix.length)}${suffix}`;
|
|
7
|
+
};
|
|
8
|
+
const getIndexName = ({ fallbackFieldName, indexes, on, tableName })=>{
|
|
9
|
+
const matchingIndex = Object.values(indexes ?? {}).find((index)=>index.on === on);
|
|
10
|
+
return matchingIndex?.name ?? getDefaultIndexName(`${tableName}_${fallbackFieldName}`);
|
|
11
|
+
};
|
|
12
|
+
const getLegacyProcessingIndexName = ({ filePath, tableName })=>{
|
|
13
|
+
const latestSnapshotFile = readdirSync(path.dirname(filePath)).filter((file)=>file.endsWith('.json')).sort().reverse()[0];
|
|
14
|
+
if (latestSnapshotFile) {
|
|
15
|
+
const snapshot = JSON.parse(readFileSync(path.join(path.dirname(filePath), latestSnapshotFile), 'utf8'));
|
|
16
|
+
const table = Object.values(snapshot.tables ?? {}).find(({ name })=>name === tableName);
|
|
17
|
+
const processingIndex = Object.values(table?.indexes ?? {}).find((index)=>index.columns?.some(({ expression })=>expression === 'processing'));
|
|
18
|
+
if (processingIndex?.name) {
|
|
19
|
+
return processingIndex.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return getDefaultIndexName(`${tableName}_processing`);
|
|
23
|
+
};
|
|
24
|
+
export const buildDynamicPredefinedJobsProcessingLeaseMigration = ({ dialect, packageName })=>{
|
|
25
|
+
return async ({ filePath, payload })=>{
|
|
26
|
+
const adapter = payload.db;
|
|
27
|
+
const tableName = adapter.tableNameMap.get(toSnakeCase('payload-jobs'));
|
|
28
|
+
if (!tableName) {
|
|
29
|
+
throw new Error('Could not find the payload-jobs database table');
|
|
30
|
+
}
|
|
31
|
+
const rawTable = adapter.rawTables[tableName];
|
|
32
|
+
const newIndexName = getIndexName({
|
|
33
|
+
fallbackFieldName: 'processing_until',
|
|
34
|
+
indexes: rawTable?.indexes,
|
|
35
|
+
on: 'processingUntil',
|
|
36
|
+
tableName
|
|
37
|
+
});
|
|
38
|
+
const oldIndexName = getLegacyProcessingIndexName({
|
|
39
|
+
filePath,
|
|
40
|
+
tableName
|
|
41
|
+
});
|
|
42
|
+
const schemaName = dialect === 'postgres' ? adapter.schemaName ?? 'public' : undefined;
|
|
43
|
+
const drizzleSnapshot = await adapter.requireDrizzleKit().generateDrizzleJson(adapter.schema);
|
|
44
|
+
writeFileSync(`${filePath}.json`, JSON.stringify(drizzleSnapshot, null, 2));
|
|
45
|
+
const sharedArgs = `
|
|
46
|
+
db,
|
|
47
|
+
newIndexName: ${JSON.stringify(newIndexName)},
|
|
48
|
+
oldIndexName: ${JSON.stringify(oldIndexName)},
|
|
49
|
+
schemaName: ${JSON.stringify(schemaName)},
|
|
50
|
+
sql,
|
|
51
|
+
tableName: ${JSON.stringify(tableName)},`;
|
|
52
|
+
return {
|
|
53
|
+
downSQL: `await migrateJobsProcessingLease({${sharedArgs}
|
|
54
|
+
direction: 'down',
|
|
55
|
+
})`,
|
|
56
|
+
imports: `import { migrateJobsProcessingLease } from '${packageName}/migration-utils'`,
|
|
57
|
+
upSQL: `await migrateJobsProcessingLease({${sharedArgs}
|
|
58
|
+
direction: 'up',
|
|
59
|
+
})`
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=jobsProcessingLeaseMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/jobsProcessingLeaseMigration.ts"],"sourcesContent":["import type { DynamicMigrationTemplate } from 'payload'\n\nimport { readdirSync, readFileSync, writeFileSync } from 'fs'\nimport path from 'path'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter, RawIndex } from '../types.js'\n\ntype SnapshotIndex = {\n columns?: { expression?: string }[]\n name?: string\n}\n\ntype SnapshotTable = {\n indexes?: Record<string, SnapshotIndex>\n name?: string\n}\n\nconst getDefaultIndexName = (name: string): string => {\n const suffix = '_idx'\n\n return `${name.slice(0, 60 - suffix.length)}${suffix}`\n}\n\nconst getIndexName = ({\n fallbackFieldName,\n indexes,\n on,\n tableName,\n}: {\n fallbackFieldName: string\n indexes?: Record<string, RawIndex>\n on: string\n tableName: string\n}): string => {\n const matchingIndex = Object.values(indexes ?? {}).find((index) => index.on === on)\n\n return matchingIndex?.name ?? getDefaultIndexName(`${tableName}_${fallbackFieldName}`)\n}\n\nconst getLegacyProcessingIndexName = ({\n filePath,\n tableName,\n}: {\n filePath: string\n tableName: string\n}): string => {\n const latestSnapshotFile = readdirSync(path.dirname(filePath))\n .filter((file) => file.endsWith('.json'))\n .sort()\n .reverse()[0]\n\n if (latestSnapshotFile) {\n const snapshot = JSON.parse(\n readFileSync(path.join(path.dirname(filePath), latestSnapshotFile), 'utf8'),\n ) as { tables?: Record<string, SnapshotTable> }\n const table = Object.values(snapshot.tables ?? {}).find(({ name }) => name === tableName)\n const processingIndex = Object.values(table?.indexes ?? {}).find((index) =>\n index.columns?.some(({ expression }) => expression === 'processing'),\n )\n\n if (processingIndex?.name) {\n return processingIndex.name\n }\n }\n\n return getDefaultIndexName(`${tableName}_processing`)\n}\n\nexport const buildDynamicPredefinedJobsProcessingLeaseMigration = ({\n dialect,\n packageName,\n}: {\n dialect: 'postgres' | 'sqlite'\n packageName: string\n}): DynamicMigrationTemplate => {\n return async ({ filePath, payload }) => {\n const adapter = payload.db as DrizzleAdapter\n const tableName = adapter.tableNameMap.get(toSnakeCase('payload-jobs'))\n\n if (!tableName) {\n throw new Error('Could not find the payload-jobs database table')\n }\n\n const rawTable = adapter.rawTables[tableName]\n const newIndexName = getIndexName({\n fallbackFieldName: 'processing_until',\n indexes: rawTable?.indexes,\n on: 'processingUntil',\n tableName,\n })\n const oldIndexName = getLegacyProcessingIndexName({ filePath, tableName })\n const schemaName = dialect === 'postgres' ? (adapter.schemaName ?? 'public') : undefined\n const drizzleSnapshot = await adapter.requireDrizzleKit().generateDrizzleJson(adapter.schema)\n\n writeFileSync(`${filePath}.json`, JSON.stringify(drizzleSnapshot, null, 2))\n\n const sharedArgs = `\n db,\n newIndexName: ${JSON.stringify(newIndexName)},\n oldIndexName: ${JSON.stringify(oldIndexName)},\n schemaName: ${JSON.stringify(schemaName)},\n sql,\n tableName: ${JSON.stringify(tableName)},`\n\n return {\n downSQL: `await migrateJobsProcessingLease({${sharedArgs}\n direction: 'down',\n })`,\n imports: `import { migrateJobsProcessingLease } from '${packageName}/migration-utils'`,\n upSQL: `await migrateJobsProcessingLease({${sharedArgs}\n direction: 'up',\n })`,\n }\n }\n}\n"],"names":["readdirSync","readFileSync","writeFileSync","path","toSnakeCase","getDefaultIndexName","name","suffix","slice","length","getIndexName","fallbackFieldName","indexes","on","tableName","matchingIndex","Object","values","find","index","getLegacyProcessingIndexName","filePath","latestSnapshotFile","dirname","filter","file","endsWith","sort","reverse","snapshot","JSON","parse","join","table","tables","processingIndex","columns","some","expression","buildDynamicPredefinedJobsProcessingLeaseMigration","dialect","packageName","payload","adapter","db","tableNameMap","get","Error","rawTable","rawTables","newIndexName","oldIndexName","schemaName","undefined","drizzleSnapshot","requireDrizzleKit","generateDrizzleJson","schema","stringify","sharedArgs","downSQL","imports","upSQL"],"mappings":"AAEA,SAASA,WAAW,EAAEC,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAC7D,OAAOC,UAAU,OAAM;AACvB,OAAOC,iBAAiB,gBAAe;AAcvC,MAAMC,sBAAsB,CAACC;IAC3B,MAAMC,SAAS;IAEf,OAAO,GAAGD,KAAKE,KAAK,CAAC,GAAG,KAAKD,OAAOE,MAAM,IAAIF,QAAQ;AACxD;AAEA,MAAMG,eAAe,CAAC,EACpBC,iBAAiB,EACjBC,OAAO,EACPC,EAAE,EACFC,SAAS,EAMV;IACC,MAAMC,gBAAgBC,OAAOC,MAAM,CAACL,WAAW,CAAC,GAAGM,IAAI,CAAC,CAACC,QAAUA,MAAMN,EAAE,KAAKA;IAEhF,OAAOE,eAAeT,QAAQD,oBAAoB,GAAGS,UAAU,CAAC,EAAEH,mBAAmB;AACvF;AAEA,MAAMS,+BAA+B,CAAC,EACpCC,QAAQ,EACRP,SAAS,EAIV;IACC,MAAMQ,qBAAqBtB,YAAYG,KAAKoB,OAAO,CAACF,WACjDG,MAAM,CAAC,CAACC,OAASA,KAAKC,QAAQ,CAAC,UAC/BC,IAAI,GACJC,OAAO,EAAE,CAAC,EAAE;IAEf,IAAIN,oBAAoB;QACtB,MAAMO,WAAWC,KAAKC,KAAK,CACzB9B,aAAaE,KAAK6B,IAAI,CAAC7B,KAAKoB,OAAO,CAACF,WAAWC,qBAAqB;QAEtE,MAAMW,QAAQjB,OAAOC,MAAM,CAACY,SAASK,MAAM,IAAI,CAAC,GAAGhB,IAAI,CAAC,CAAC,EAAEZ,IAAI,EAAE,GAAKA,SAASQ;QAC/E,MAAMqB,kBAAkBnB,OAAOC,MAAM,CAACgB,OAAOrB,WAAW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EpB,YAAY,iBAAiB,CAAC;YACtFqB,OAAO,CAAC,kCAAkC,EAAEH,WAAW;;IAEzD,CAAC;QACD;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { createClient } from '@libsql/client';
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { migratePostgresJobsProcessingLease } from '../postgres/predefinedMigrations/jobs-processing-lease/index.js';
|
|
7
|
+
import { migrateSqliteJobsProcessingLease } from '../sqlite/predefinedMigrations/jobs-processing-lease/index.js';
|
|
8
|
+
import { buildDynamicPredefinedJobsProcessingLeaseMigration } from './jobsProcessingLeaseMigration.js';
|
|
9
|
+
describe('jobs processing lease predefined migration', ()=>{
|
|
10
|
+
let client;
|
|
11
|
+
const temporaryDirectories = [];
|
|
12
|
+
afterEach(()=>{
|
|
13
|
+
client?.close();
|
|
14
|
+
client = undefined;
|
|
15
|
+
for (const directory of temporaryDirectories){
|
|
16
|
+
rmSync(directory, {
|
|
17
|
+
force: true,
|
|
18
|
+
recursive: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
temporaryDirectories.length = 0;
|
|
22
|
+
});
|
|
23
|
+
it('should migrate SQLite job data up and down', async ()=>{
|
|
24
|
+
client = createClient({
|
|
25
|
+
url: ':memory:'
|
|
26
|
+
});
|
|
27
|
+
await client.execute('CREATE TABLE "custom_jobs" ("id" integer primary key, "processing" integer DEFAULT false)');
|
|
28
|
+
await client.execute('CREATE INDEX "custom_jobs_processing_idx" ON "custom_jobs" ("processing")');
|
|
29
|
+
await client.execute('INSERT INTO "custom_jobs" ("id", "processing") VALUES (1, true), (2, false)');
|
|
30
|
+
const db = {
|
|
31
|
+
run: (statement)=>client.execute(statement)
|
|
32
|
+
};
|
|
33
|
+
const sql = {
|
|
34
|
+
raw: (statement)=>statement
|
|
35
|
+
};
|
|
36
|
+
await migrateSqliteJobsProcessingLease({
|
|
37
|
+
db,
|
|
38
|
+
direction: 'up',
|
|
39
|
+
newIndexName: 'custom_jobs_processing_until_idx',
|
|
40
|
+
oldIndexName: 'custom_jobs_processing_idx',
|
|
41
|
+
sql,
|
|
42
|
+
tableName: 'custom_jobs'
|
|
43
|
+
});
|
|
44
|
+
const migratedJobs = await client.execute('SELECT "id", "processing_until", "processing_token" FROM "custom_jobs" ORDER BY "id"');
|
|
45
|
+
expect(migratedJobs.rows).toEqual([
|
|
46
|
+
{
|
|
47
|
+
id: 1,
|
|
48
|
+
processing_token: null,
|
|
49
|
+
processing_until: '1970-01-01T00:00:00.000Z'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 2,
|
|
53
|
+
processing_token: null,
|
|
54
|
+
processing_until: null
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
await migrateSqliteJobsProcessingLease({
|
|
58
|
+
db,
|
|
59
|
+
direction: 'down',
|
|
60
|
+
newIndexName: 'custom_jobs_processing_until_idx',
|
|
61
|
+
oldIndexName: 'custom_jobs_processing_idx',
|
|
62
|
+
sql,
|
|
63
|
+
tableName: 'custom_jobs'
|
|
64
|
+
});
|
|
65
|
+
const restoredJobs = await client.execute('SELECT "id", "processing" FROM "custom_jobs" ORDER BY "id"');
|
|
66
|
+
expect(restoredJobs.rows).toEqual([
|
|
67
|
+
{
|
|
68
|
+
id: 1,
|
|
69
|
+
processing: 1
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 2,
|
|
73
|
+
processing: 0
|
|
74
|
+
}
|
|
75
|
+
]);
|
|
76
|
+
const restoredColumns = await client.execute('PRAGMA table_info("custom_jobs")');
|
|
77
|
+
expect(restoredColumns.rows.map((column)=>column.name)).not.toContain('processing_token');
|
|
78
|
+
});
|
|
79
|
+
it('should produce PostgreSQL statements with quoted custom names', async ()=>{
|
|
80
|
+
const execute = vi.fn().mockResolvedValue(undefined);
|
|
81
|
+
await migratePostgresJobsProcessingLease({
|
|
82
|
+
db: {
|
|
83
|
+
execute
|
|
84
|
+
},
|
|
85
|
+
direction: 'up',
|
|
86
|
+
newIndexName: 'custom_jobs_processing_until_idx',
|
|
87
|
+
oldIndexName: 'custom_jobs_processing_idx',
|
|
88
|
+
schemaName: 'custom_schema',
|
|
89
|
+
sql: {
|
|
90
|
+
raw: (statement)=>statement
|
|
91
|
+
},
|
|
92
|
+
tableName: 'custom_jobs'
|
|
93
|
+
});
|
|
94
|
+
expect(execute.mock.calls.map(([statement])=>statement)).toEqual([
|
|
95
|
+
'ALTER TABLE "custom_schema"."custom_jobs" ADD COLUMN "processing_until" timestamp(3) with time zone',
|
|
96
|
+
'ALTER TABLE "custom_schema"."custom_jobs" ADD COLUMN "processing_token" varchar',
|
|
97
|
+
'UPDATE "custom_schema"."custom_jobs" SET "processing_until" = \'1970-01-01 00:00:00+00\' WHERE "processing" = true',
|
|
98
|
+
'DROP INDEX IF EXISTS "custom_schema"."custom_jobs_processing_idx"',
|
|
99
|
+
'ALTER TABLE "custom_schema"."custom_jobs" DROP COLUMN "processing"',
|
|
100
|
+
'CREATE INDEX "custom_jobs_processing_until_idx" ON "custom_schema"."custom_jobs" USING btree ("processing_until")'
|
|
101
|
+
]);
|
|
102
|
+
execute.mockClear();
|
|
103
|
+
await migratePostgresJobsProcessingLease({
|
|
104
|
+
db: {
|
|
105
|
+
execute
|
|
106
|
+
},
|
|
107
|
+
direction: 'down',
|
|
108
|
+
newIndexName: 'custom_jobs_processing_until_idx',
|
|
109
|
+
oldIndexName: 'custom_jobs_processing_idx',
|
|
110
|
+
schemaName: 'custom_schema',
|
|
111
|
+
sql: {
|
|
112
|
+
raw: (statement)=>statement
|
|
113
|
+
},
|
|
114
|
+
tableName: 'custom_jobs'
|
|
115
|
+
});
|
|
116
|
+
expect(execute.mock.calls.map(([statement])=>statement)).toContain('ALTER TABLE "custom_schema"."custom_jobs" DROP COLUMN "processing_token"');
|
|
117
|
+
});
|
|
118
|
+
it('should write a Drizzle snapshot and generate adapter-specific migration code', async ()=>{
|
|
119
|
+
const temporaryDirectory = mkdtempSync(path.join(tmpdir(), 'payload-jobs-migration-'));
|
|
120
|
+
temporaryDirectories.push(temporaryDirectory);
|
|
121
|
+
const filePath = path.join(temporaryDirectory, 'migration');
|
|
122
|
+
writeFileSync(path.join(temporaryDirectory, 'previous.json'), JSON.stringify({
|
|
123
|
+
tables: {
|
|
124
|
+
jobs: {
|
|
125
|
+
indexes: {
|
|
126
|
+
legacy: {
|
|
127
|
+
columns: [
|
|
128
|
+
{
|
|
129
|
+
expression: 'processing'
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
name: 'legacy_processing_index'
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
name: 'custom_jobs'
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
const payload = {
|
|
140
|
+
db: {
|
|
141
|
+
rawTables: {
|
|
142
|
+
custom_jobs: {
|
|
143
|
+
indexes: {
|
|
144
|
+
processingUntil: {
|
|
145
|
+
name: 'custom_jobs_processing_until_idx',
|
|
146
|
+
on: 'processingUntil'
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
requireDrizzleKit: ()=>({
|
|
152
|
+
generateDrizzleJson: vi.fn().mockResolvedValue({
|
|
153
|
+
version: 'test-snapshot'
|
|
154
|
+
})
|
|
155
|
+
}),
|
|
156
|
+
schema: {},
|
|
157
|
+
schemaName: 'custom_schema',
|
|
158
|
+
tableNameMap: new Map([
|
|
159
|
+
[
|
|
160
|
+
'payload_jobs',
|
|
161
|
+
'custom_jobs'
|
|
162
|
+
]
|
|
163
|
+
])
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const dynamic = buildDynamicPredefinedJobsProcessingLeaseMigration({
|
|
167
|
+
dialect: 'postgres',
|
|
168
|
+
packageName: '@payloadcms/db-postgres'
|
|
169
|
+
});
|
|
170
|
+
const migration = await dynamic({
|
|
171
|
+
filePath,
|
|
172
|
+
payload
|
|
173
|
+
});
|
|
174
|
+
expect(existsSync(`${filePath}.json`)).toBe(true);
|
|
175
|
+
expect(JSON.parse(readFileSync(`${filePath}.json`, 'utf8'))).toEqual({
|
|
176
|
+
version: 'test-snapshot'
|
|
177
|
+
});
|
|
178
|
+
expect(migration.imports).toContain('@payloadcms/db-postgres/migration-utils');
|
|
179
|
+
expect(migration.upSQL).toContain("direction: 'up'");
|
|
180
|
+
expect(migration.upSQL).toContain('custom_jobs_processing_until_idx');
|
|
181
|
+
expect(migration.upSQL).toContain('legacy_processing_index');
|
|
182
|
+
expect(migration.downSQL).toContain("direction: 'down'");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
//# sourceMappingURL=jobsProcessingLeaseMigration.spec.js.map
|