@payloadcms/drizzle 4.0.0-internal.9726517 → 4.0.0-internal.a6582c6
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/dist/exports/postgres.d.ts +0 -1
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +0 -1
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +0 -1
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +0 -1
- package/dist/exports/sqlite.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.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/package.json +3 -3
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts +0 -12
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.d.ts.map +0 -1
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js +0 -20
- package/dist/postgres/predefinedMigrations/jobs-processing-lease/index.js.map +0 -1
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts +0 -12
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.d.ts.map +0 -1
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js +0 -20
- package/dist/sqlite/predefinedMigrations/jobs-processing-lease/index.js.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts +0 -6
- package/dist/utilities/jobsProcessingLeaseMigration.d.ts.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.js +0 -64
- package/dist/utilities/jobsProcessingLeaseMigration.js.map +0 -1
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js +0 -166
- package/dist/utilities/jobsProcessingLeaseMigration.spec.js.map +0 -1
|
@@ -9,7 +9,6 @@ export { dropDatabase } from '../postgres/dropDatabase.js';
|
|
|
9
9
|
export { execute } from '../postgres/execute.js';
|
|
10
10
|
export { init } from '../postgres/init.js';
|
|
11
11
|
export { insert } from '../postgres/insert.js';
|
|
12
|
-
export { migratePostgresJobsProcessingLease } from '../postgres/predefinedMigrations/jobs-processing-lease/index.js';
|
|
13
12
|
export { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js';
|
|
14
13
|
export { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js';
|
|
15
14
|
export { requireDrizzleKit } from '../postgres/requireDrizzleKit.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/exports/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/exports/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,2DAA2D,CAAA;AACzG,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAA;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AACrE,cAAc,sBAAsB,CAAA"}
|
package/dist/exports/postgres.js
CHANGED
|
@@ -9,7 +9,6 @@ export { dropDatabase } from '../postgres/dropDatabase.js';
|
|
|
9
9
|
export { execute } from '../postgres/execute.js';
|
|
10
10
|
export { init } from '../postgres/init.js';
|
|
11
11
|
export { insert } from '../postgres/insert.js';
|
|
12
|
-
export { migratePostgresJobsProcessingLease } from '../postgres/predefinedMigrations/jobs-processing-lease/index.js';
|
|
13
12
|
export { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js';
|
|
14
13
|
export { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js';
|
|
15
14
|
export { requireDrizzleKit } from '../postgres/requireDrizzleKit.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/postgres.ts"],"sourcesContent":["export { columnToCodeConverter } from '../postgres/columnToCodeConverter.js'\nexport { countDistinct } from '../postgres/countDistinct.js'\nexport { createDatabase } from '../postgres/createDatabase.js'\nexport { createExtensions } from '../postgres/createExtensions.js'\nexport { createJSONQuery } from '../postgres/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js'\nexport { deleteWhere } from '../postgres/deleteWhere.js'\nexport { dropDatabase } from '../postgres/dropDatabase.js'\nexport { execute } from '../postgres/execute.js'\nexport { init } from '../postgres/init.js'\nexport { insert } from '../postgres/insert.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/postgres.ts"],"sourcesContent":["export { columnToCodeConverter } from '../postgres/columnToCodeConverter.js'\nexport { countDistinct } from '../postgres/countDistinct.js'\nexport { createDatabase } from '../postgres/createDatabase.js'\nexport { createExtensions } from '../postgres/createExtensions.js'\nexport { createJSONQuery } from '../postgres/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js'\nexport { deleteWhere } from '../postgres/deleteWhere.js'\nexport { dropDatabase } from '../postgres/dropDatabase.js'\nexport { execute } from '../postgres/execute.js'\nexport { init } from '../postgres/init.js'\nexport { insert } from '../postgres/insert.js'\nexport { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js'\nexport { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js'\nexport { requireDrizzleKit } from '../postgres/requireDrizzleKit.js'\nexport { geometryColumn } from '../postgres/schema/geometryColumn.js'\nexport * from '../postgres/types.js'\n"],"names":["columnToCodeConverter","countDistinct","createDatabase","createExtensions","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migratePostgresLocalizeStatus","migratePostgresV2toV3","requireDrizzleKit","geometryColumn"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,uCAAsC;AAC5E,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,OAAO,QAAQ,yBAAwB;AAChD,SAASC,IAAI,QAAQ,sBAAqB;AAC1C,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,6BAA6B,QAAQ,4DAA2D;AACzG,SAASC,qBAAqB,QAAQ,kDAAiD;AACvF,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,cAAc,uBAAsB"}
|
package/dist/exports/sqlite.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export { dropDatabase } from '../sqlite/dropDatabase.js';
|
|
|
8
8
|
export { execute } from '../sqlite/execute.js';
|
|
9
9
|
export { init } from '../sqlite/init.js';
|
|
10
10
|
export { insert } from '../sqlite/insert.js';
|
|
11
|
-
export { migrateSqliteJobsProcessingLease } from '../sqlite/predefinedMigrations/jobs-processing-lease/index.js';
|
|
12
11
|
export { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js';
|
|
13
12
|
export { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js';
|
|
14
13
|
export * from '../sqlite/types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yDAAyD,CAAA;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yDAAyD,CAAA;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yDAAyD,CAAA;AACrG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,cAAc,oBAAoB,CAAA"}
|
package/dist/exports/sqlite.js
CHANGED
|
@@ -8,7 +8,6 @@ export { dropDatabase } from '../sqlite/dropDatabase.js';
|
|
|
8
8
|
export { execute } from '../sqlite/execute.js';
|
|
9
9
|
export { init } from '../sqlite/init.js';
|
|
10
10
|
export { insert } from '../sqlite/insert.js';
|
|
11
|
-
export { migrateSqliteJobsProcessingLease } from '../sqlite/predefinedMigrations/jobs-processing-lease/index.js';
|
|
12
11
|
export { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js';
|
|
13
12
|
export { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js';
|
|
14
13
|
export * from '../sqlite/types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/sqlite.ts"],"sourcesContent":["export { columnToCodeConverter } from '../sqlite/columnToCodeConverter.js'\nexport { countDistinct } from '../sqlite/countDistinct.js'\nexport { convertPathToJSONTraversal } from '../sqlite/createJSONQuery/convertPathToJSONTraversal.js'\nexport { createJSONQuery } from '../sqlite/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../sqlite/defaultSnapshot.js'\nexport { deleteWhere } from '../sqlite/deleteWhere.js'\nexport { dropDatabase } from '../sqlite/dropDatabase.js'\nexport { execute } from '../sqlite/execute.js'\nexport { init } from '../sqlite/init.js'\nexport { insert } from '../sqlite/insert.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../../src/exports/sqlite.ts"],"sourcesContent":["export { columnToCodeConverter } from '../sqlite/columnToCodeConverter.js'\nexport { countDistinct } from '../sqlite/countDistinct.js'\nexport { convertPathToJSONTraversal } from '../sqlite/createJSONQuery/convertPathToJSONTraversal.js'\nexport { createJSONQuery } from '../sqlite/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../sqlite/defaultSnapshot.js'\nexport { deleteWhere } from '../sqlite/deleteWhere.js'\nexport { dropDatabase } from '../sqlite/dropDatabase.js'\nexport { execute } from '../sqlite/execute.js'\nexport { init } from '../sqlite/init.js'\nexport { insert } from '../sqlite/insert.js'\nexport { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js'\nexport { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js'\nexport * from '../sqlite/types.js'\n"],"names":["columnToCodeConverter","countDistinct","convertPathToJSONTraversal","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migrateSqliteLocalizeStatus","requireDrizzleKit"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,aAAa,QAAQ,6BAA4B;AAC1D,SAASC,0BAA0B,QAAQ,0DAAyD;AACpG,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,+BAA8B;AACrE,SAASC,WAAW,QAAQ,2BAA0B;AACtD,SAASC,YAAY,QAAQ,4BAA2B;AACxD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SAASC,IAAI,QAAQ,oBAAmB;AACxC,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,2BAA2B,QAAQ,0DAAyD;AACrG,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,cAAc,qBAAoB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,6 @@ export { createSchemaGenerator } from './utilities/createSchemaGenerator.js';
|
|
|
48
48
|
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
49
49
|
export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
50
50
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
51
|
-
export { buildDynamicPredefinedJobsProcessingLeaseMigration } from './utilities/jobsProcessingLeaseMigration.js';
|
|
52
51
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
53
52
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
54
53
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,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ator.js';
|
|
|
46
46
|
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
47
47
|
export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
48
48
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
49
|
-
export { buildDynamicPredefinedJobsProcessingLeaseMigration } from './utilities/jobsProcessingLeaseMigration.js';
|
|
50
49
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
51
50
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
52
51
|
import { findMigrationDir as payloadFindMigrationDir } from 'payload';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { countGlobalVersions } from './countGlobalVersions.js'\nexport { countVersions } from './countVersions.js'\nexport { create } from './create.js'\nexport { createGlobal } from './createGlobal.js'\nexport { createGlobalVersion } from './createGlobalVersion.js'\nexport { createTableName } from './createTableName.js'\nexport { createVersion } from './createVersion.js'\nexport { deleteMany } from './deleteMany.js'\nexport { deleteOne } from './deleteOne.js'\nexport { deleteVersions } from './deleteVersions.js'\nexport { destroy } from './destroy.js'\nexport { find } from './find.js'\nexport { findDistinct } from './findDistinct.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.js'\nexport { findOne } from './findOne.js'\nexport { findVersions } from './findVersions.js'\nexport { migrate } from './migrate.js'\nexport { migrateDown } from './migrateDown.js'\nexport { migrateFresh } from './migrateFresh.js'\nexport { migrateRefresh } from './migrateRefresh.js'\nexport { migrateReset } from './migrateReset.js'\nexport { migrateStatus } from './migrateStatus.js'\nexport { buildQuery } from './queries/buildQuery.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { Operators } from './queries/operatorMap.js'\nexport { parseParams } from './queries/parseParams.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { buildDrizzleRelations } from './schema/buildDrizzleRelations.js'\nexport { buildRawSchema } from './schema/buildRawSchema.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport type {\n BaseRawColumn,\n BlocksToJsonMigrator,\n BuildDrizzleTable,\n BuildQueryJoinAliases,\n ColumnToCodeConverter,\n CountDistinct,\n CreateJSONQueryArgs,\n DeleteWhere,\n DrizzleAdapter,\n DrizzleTransaction,\n DropDatabase,\n EnumRawColumn,\n Execute,\n GenericColumn,\n GenericColumns,\n GenericPgColumn,\n GenericRelation,\n GenericTable,\n IDType,\n Insert,\n IntegerRawColumn,\n Migration,\n PostgresDB,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n RequireDrizzleKit,\n SetColumnID,\n SQLiteDB,\n TimestampRawColumn,\n TransactionPg,\n TransactionSQLite,\n UUIDRawColumn,\n VectorRawColumn,\n} from './types.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateJobs } from './updateJobs.js'\nexport { updateMany } from './updateMany.js'\nexport { updateOne } from './updateOne.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsert } from './upsert.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport {\n buildDynamicPredefinedBlocksToJsonMigration,\n createBlocksToJsonMigrator,\n getBlocksToJsonMigrator,\n} from './utilities/blocksToJsonMigrator.js'\nexport { buildCreateMigration } from './utilities/buildCreateMigration.js'\nexport { buildIndexName } from './utilities/buildIndexName.js'\nexport { createSchemaGenerator } from './utilities/createSchemaGenerator.js'\nexport { executeSchemaHooks } from './utilities/executeSchemaHooks.js'\nexport { extendDrizzleTable } from './utilities/extendDrizzleTable.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { countGlobalVersions } from './countGlobalVersions.js'\nexport { countVersions } from './countVersions.js'\nexport { create } from './create.js'\nexport { createGlobal } from './createGlobal.js'\nexport { createGlobalVersion } from './createGlobalVersion.js'\nexport { createTableName } from './createTableName.js'\nexport { createVersion } from './createVersion.js'\nexport { deleteMany } from './deleteMany.js'\nexport { deleteOne } from './deleteOne.js'\nexport { deleteVersions } from './deleteVersions.js'\nexport { destroy } from './destroy.js'\nexport { find } from './find.js'\nexport { findDistinct } from './findDistinct.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.js'\nexport { findOne } from './findOne.js'\nexport { findVersions } from './findVersions.js'\nexport { migrate } from './migrate.js'\nexport { migrateDown } from './migrateDown.js'\nexport { migrateFresh } from './migrateFresh.js'\nexport { migrateRefresh } from './migrateRefresh.js'\nexport { migrateReset } from './migrateReset.js'\nexport { migrateStatus } from './migrateStatus.js'\nexport { buildQuery } from './queries/buildQuery.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { Operators } from './queries/operatorMap.js'\nexport { parseParams } from './queries/parseParams.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { buildDrizzleRelations } from './schema/buildDrizzleRelations.js'\nexport { buildRawSchema } from './schema/buildRawSchema.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport type {\n BaseRawColumn,\n BlocksToJsonMigrator,\n BuildDrizzleTable,\n BuildQueryJoinAliases,\n ColumnToCodeConverter,\n CountDistinct,\n CreateJSONQueryArgs,\n DeleteWhere,\n DrizzleAdapter,\n DrizzleTransaction,\n DropDatabase,\n EnumRawColumn,\n Execute,\n GenericColumn,\n GenericColumns,\n GenericPgColumn,\n GenericRelation,\n GenericTable,\n IDType,\n Insert,\n IntegerRawColumn,\n Migration,\n PostgresDB,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n RequireDrizzleKit,\n SetColumnID,\n SQLiteDB,\n TimestampRawColumn,\n TransactionPg,\n TransactionSQLite,\n UUIDRawColumn,\n VectorRawColumn,\n} from './types.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateJobs } from './updateJobs.js'\nexport { updateMany } from './updateMany.js'\nexport { updateOne } from './updateOne.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsert } from './upsert.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport {\n buildDynamicPredefinedBlocksToJsonMigration,\n createBlocksToJsonMigrator,\n getBlocksToJsonMigrator,\n} from './utilities/blocksToJsonMigrator.js'\nexport { buildCreateMigration } from './utilities/buildCreateMigration.js'\nexport { buildIndexName } from './utilities/buildIndexName.js'\nexport { createSchemaGenerator } from './utilities/createSchemaGenerator.js'\nexport { executeSchemaHooks } from './utilities/executeSchemaHooks.js'\nexport { extendDrizzleTable } from './utilities/extendDrizzleTable.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\nimport { findMigrationDir as payloadFindMigrationDir } from 'payload'\n\n/**\n * @deprecated remove in 4.0\n * use\n * ```ts\n * import { findMigrationDir } from 'payload'\n * ```\n */\nexport const findMigrationDir = payloadFindMigrationDir\n"],"names":["count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createTableName","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findDistinct","findGlobal","findGlobalVersions","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","buildQuery","operatorMap","parseParams","queryDrafts","buildDrizzleRelations","buildRawSchema","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateJobs","updateMany","updateOne","updateVersion","upsert","upsertRow","buildDynamicPredefinedBlocksToJsonMigration","createBlocksToJsonMigrator","getBlocksToJsonMigrator","buildCreateMigration","buildIndexName","createSchemaGenerator","executeSchemaHooks","extendDrizzleTable","hasLocalesTable","pushDevSchema","validateExistingBlockIsIdentical","findMigrationDir","payloadFindMigrationDir"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,WAAW,QAAQ,2BAA0B;AAEtD,SAASC,WAAW,QAAQ,2BAA0B;AACtD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,oCAAmC;AACzE,SAASC,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAwC3E,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SACEC,2CAA2C,EAC3CC,0BAA0B,EAC1BC,uBAAuB,QAClB,sCAAqC;AAC5C,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,qBAAqB,QAAQ,uCAAsC;AAC5E,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,gCAAgC,QAAQ,kDAAiD;AAClG,SAASC,oBAAoBC,uBAAuB,QAAQ,UAAS;AAErE;;;;;;CAMC,GACD,OAAO,MAAMD,mBAAmBC,wBAAuB"}
|
package/dist/updateJobs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateJobs.d.ts","sourceRoot":"","sources":["../src/updateJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAA;AAsBhD,eAAO,MAAM,UAAU,EAAE,UAsIxB,CAAA"}
|
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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": "4.0.0-internal.a6582c6",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"@types/pg": "8.20.0",
|
|
56
56
|
"@types/to-snake-case": "1.0.0",
|
|
57
57
|
"@payloadcms/eslint-config": "3.28.0",
|
|
58
|
-
"payload": "4.0.0-internal.
|
|
58
|
+
"payload": "4.0.0-internal.a6582c6"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"payload": "4.0.0-internal.
|
|
61
|
+
"payload": "4.0.0-internal.a6582c6"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pnpm build:swc && pnpm build:types",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type Args = {
|
|
2
|
-
db: any;
|
|
3
|
-
direction: 'down' | 'up';
|
|
4
|
-
newIndexName: string;
|
|
5
|
-
oldIndexName: string;
|
|
6
|
-
schemaName?: string;
|
|
7
|
-
sql: any;
|
|
8
|
-
tableName: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function migratePostgresJobsProcessingLease({ db, direction, newIndexName, oldIndexName, schemaName, sql, tableName, }: Args): Promise<void>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/postgres/predefinedMigrations/jobs-processing-lease/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG;IACV,EAAE,EAAE,GAAG,CAAA;IACP,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,GAAG,CAAA;IACR,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAID,wBAAsB,kCAAkC,CAAC,EACvD,EAAE,EACF,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAqB,EACrB,GAAG,EACH,SAAS,GACV,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const quoteIdentifier = (identifier)=>`"${identifier.replaceAll('"', '""')}"`;
|
|
2
|
-
export async function migratePostgresJobsProcessingLease({ db, direction, newIndexName, oldIndexName, schemaName = 'public', sql, tableName }) {
|
|
3
|
-
const qualifiedTableName = `${quoteIdentifier(schemaName)}.${quoteIdentifier(tableName)}`;
|
|
4
|
-
const run = (statement)=>db.execute(sql.raw(statement));
|
|
5
|
-
if (direction === 'up') {
|
|
6
|
-
await run(`ALTER TABLE ${qualifiedTableName} ADD COLUMN "processing_until" timestamp(3) with time zone`);
|
|
7
|
-
await run(`UPDATE ${qualifiedTableName} SET "processing_until" = '1970-01-01 00:00:00+00' WHERE "processing" = true`);
|
|
8
|
-
await run(`DROP INDEX IF EXISTS ${quoteIdentifier(schemaName)}.${quoteIdentifier(oldIndexName)}`);
|
|
9
|
-
await run(`ALTER TABLE ${qualifiedTableName} DROP COLUMN "processing"`);
|
|
10
|
-
await run(`CREATE INDEX ${quoteIdentifier(newIndexName)} ON ${qualifiedTableName} USING btree ("processing_until")`);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
await run(`ALTER TABLE ${qualifiedTableName} ADD COLUMN "processing" boolean DEFAULT false`);
|
|
14
|
-
await run(`UPDATE ${qualifiedTableName} SET "processing" = true WHERE "processing_until" IS NOT NULL`);
|
|
15
|
-
await run(`DROP INDEX IF EXISTS ${quoteIdentifier(schemaName)}.${quoteIdentifier(newIndexName)}`);
|
|
16
|
-
await run(`ALTER TABLE ${qualifiedTableName} DROP COLUMN "processing_until"`);
|
|
17
|
-
await run(`CREATE INDEX ${quoteIdentifier(oldIndexName)} ON ${qualifiedTableName} USING btree ("processing")`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/postgres/predefinedMigrations/jobs-processing-lease/index.ts"],"sourcesContent":["type Args = {\n db: any\n direction: 'down' | 'up'\n newIndexName: string\n oldIndexName: string\n schemaName?: string\n sql: any\n tableName: string\n}\n\nconst quoteIdentifier = (identifier: string): string => `\"${identifier.replaceAll('\"', '\"\"')}\"`\n\nexport async function migratePostgresJobsProcessingLease({\n db,\n direction,\n newIndexName,\n oldIndexName,\n schemaName = 'public',\n sql,\n tableName,\n}: Args): Promise<void> {\n const qualifiedTableName = `${quoteIdentifier(schemaName)}.${quoteIdentifier(tableName)}`\n const run = (statement: string) => db.execute(sql.raw(statement))\n\n if (direction === 'up') {\n await run(\n `ALTER TABLE ${qualifiedTableName} ADD COLUMN \"processing_until\" timestamp(3) with time zone`,\n )\n await run(\n `UPDATE ${qualifiedTableName} SET \"processing_until\" = '1970-01-01 00:00:00+00' WHERE \"processing\" = true`,\n )\n await run(\n `DROP INDEX IF EXISTS ${quoteIdentifier(schemaName)}.${quoteIdentifier(oldIndexName)}`,\n )\n await run(`ALTER TABLE ${qualifiedTableName} DROP COLUMN \"processing\"`)\n await run(\n `CREATE INDEX ${quoteIdentifier(newIndexName)} ON ${qualifiedTableName} USING btree (\"processing_until\")`,\n )\n\n return\n }\n\n await run(`ALTER TABLE ${qualifiedTableName} ADD COLUMN \"processing\" boolean DEFAULT false`)\n await run(\n `UPDATE ${qualifiedTableName} SET \"processing\" = true WHERE \"processing_until\" IS NOT NULL`,\n )\n await run(`DROP INDEX IF EXISTS ${quoteIdentifier(schemaName)}.${quoteIdentifier(newIndexName)}`)\n await run(`ALTER TABLE ${qualifiedTableName} DROP COLUMN \"processing_until\"`)\n await run(\n `CREATE INDEX ${quoteIdentifier(oldIndexName)} ON ${qualifiedTableName} USING btree (\"processing\")`,\n )\n}\n"],"names":["quoteIdentifier","identifier","replaceAll","migratePostgresJobsProcessingLease","db","direction","newIndexName","oldIndexName","schemaName","sql","tableName","qualifiedTableName","run","statement","execute","raw"],"mappings":"AAUA,MAAMA,kBAAkB,CAACC,aAA+B,CAAC,CAAC,EAAEA,WAAWC,UAAU,CAAC,KAAK,MAAM,CAAC,CAAC;AAE/F,OAAO,eAAeC,mCAAmC,EACvDC,EAAE,EACFC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,aAAa,QAAQ,EACrBC,GAAG,EACHC,SAAS,EACJ;IACL,MAAMC,qBAAqB,GAAGX,gBAAgBQ,YAAY,CAAC,EAAER,gBAAgBU,YAAY;IACzF,MAAME,MAAM,CAACC,YAAsBT,GAAGU,OAAO,CAACL,IAAIM,GAAG,CAACF;IAEtD,IAAIR,cAAc,MAAM;QACtB,MAAMO,IACJ,CAAC,YAAY,EAAED,mBAAmB,0DAA0D,CAAC;QAE/F,MAAMC,IACJ,CAAC,OAAO,EAAED,mBAAmB,4EAA4E,CAAC;QAE5G,MAAMC,IACJ,CAAC,qBAAqB,EAAEZ,gBAAgBQ,YAAY,CAAC,EAAER,gBAAgBO,eAAe;QAExF,MAAMK,IAAI,CAAC,YAAY,EAAED,mBAAmB,yBAAyB,CAAC;QACtE,MAAMC,IACJ,CAAC,aAAa,EAAEZ,gBAAgBM,cAAc,IAAI,EAAEK,mBAAmB,iCAAiC,CAAC;QAG3G;IACF;IAEA,MAAMC,IAAI,CAAC,YAAY,EAAED,mBAAmB,8CAA8C,CAAC;IAC3F,MAAMC,IACJ,CAAC,OAAO,EAAED,mBAAmB,6DAA6D,CAAC;IAE7F,MAAMC,IAAI,CAAC,qBAAqB,EAAEZ,gBAAgBQ,YAAY,CAAC,EAAER,gBAAgBM,eAAe;IAChG,MAAMM,IAAI,CAAC,YAAY,EAAED,mBAAmB,+BAA+B,CAAC;IAC5E,MAAMC,IACJ,CAAC,aAAa,EAAEZ,gBAAgBO,cAAc,IAAI,EAAEI,mBAAmB,2BAA2B,CAAC;AAEvG"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type Args = {
|
|
2
|
-
db: any;
|
|
3
|
-
direction: 'down' | 'up';
|
|
4
|
-
newIndexName: string;
|
|
5
|
-
oldIndexName: string;
|
|
6
|
-
schemaName?: string;
|
|
7
|
-
sql: any;
|
|
8
|
-
tableName: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function migrateSqliteJobsProcessingLease({ db, direction, newIndexName, oldIndexName, sql, tableName, }: Args): Promise<void>;
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sqlite/predefinedMigrations/jobs-processing-lease/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG;IACV,EAAE,EAAE,GAAG,CAAA;IACP,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,GAAG,CAAA;IACR,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAID,wBAAsB,gCAAgC,CAAC,EACrD,EAAE,EACF,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,SAAS,GACV,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBtB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const quoteIdentifier = (identifier)=>`"${identifier.replaceAll('"', '""')}"`;
|
|
2
|
-
export async function migrateSqliteJobsProcessingLease({ db, direction, newIndexName, oldIndexName, sql, tableName }) {
|
|
3
|
-
const quotedTableName = quoteIdentifier(tableName);
|
|
4
|
-
const run = (statement)=>db.run(sql.raw(statement));
|
|
5
|
-
if (direction === 'up') {
|
|
6
|
-
await run(`ALTER TABLE ${quotedTableName} ADD COLUMN "processing_until" text`);
|
|
7
|
-
await run(`UPDATE ${quotedTableName} SET "processing_until" = '1970-01-01T00:00:00.000Z' WHERE "processing" = true`);
|
|
8
|
-
await run(`DROP INDEX IF EXISTS ${quoteIdentifier(oldIndexName)}`);
|
|
9
|
-
await run(`ALTER TABLE ${quotedTableName} DROP COLUMN "processing"`);
|
|
10
|
-
await run(`CREATE INDEX ${quoteIdentifier(newIndexName)} ON ${quotedTableName} ("processing_until")`);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
await run(`ALTER TABLE ${quotedTableName} ADD COLUMN "processing" integer DEFAULT false`);
|
|
14
|
-
await run(`UPDATE ${quotedTableName} SET "processing" = true WHERE "processing_until" IS NOT NULL`);
|
|
15
|
-
await run(`DROP INDEX IF EXISTS ${quoteIdentifier(newIndexName)}`);
|
|
16
|
-
await run(`ALTER TABLE ${quotedTableName} DROP COLUMN "processing_until"`);
|
|
17
|
-
await run(`CREATE INDEX ${quoteIdentifier(oldIndexName)} ON ${quotedTableName} ("processing")`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/sqlite/predefinedMigrations/jobs-processing-lease/index.ts"],"sourcesContent":["type Args = {\n db: any\n direction: 'down' | 'up'\n newIndexName: string\n oldIndexName: string\n schemaName?: string\n sql: any\n tableName: string\n}\n\nconst quoteIdentifier = (identifier: string): string => `\"${identifier.replaceAll('\"', '\"\"')}\"`\n\nexport async function migrateSqliteJobsProcessingLease({\n db,\n direction,\n newIndexName,\n oldIndexName,\n sql,\n tableName,\n}: Args): Promise<void> {\n const quotedTableName = quoteIdentifier(tableName)\n const run = (statement: string) => db.run(sql.raw(statement))\n\n if (direction === 'up') {\n await run(`ALTER TABLE ${quotedTableName} ADD COLUMN \"processing_until\" text`)\n await run(\n `UPDATE ${quotedTableName} SET \"processing_until\" = '1970-01-01T00:00:00.000Z' WHERE \"processing\" = true`,\n )\n await run(`DROP INDEX IF EXISTS ${quoteIdentifier(oldIndexName)}`)\n await run(`ALTER TABLE ${quotedTableName} DROP COLUMN \"processing\"`)\n await run(\n `CREATE INDEX ${quoteIdentifier(newIndexName)} ON ${quotedTableName} (\"processing_until\")`,\n )\n\n return\n }\n\n await run(`ALTER TABLE ${quotedTableName} ADD COLUMN \"processing\" integer DEFAULT false`)\n await run(\n `UPDATE ${quotedTableName} SET \"processing\" = true WHERE \"processing_until\" IS NOT NULL`,\n )\n await run(`DROP INDEX IF EXISTS ${quoteIdentifier(newIndexName)}`)\n await run(`ALTER TABLE ${quotedTableName} DROP COLUMN \"processing_until\"`)\n await run(`CREATE INDEX ${quoteIdentifier(oldIndexName)} ON ${quotedTableName} (\"processing\")`)\n}\n"],"names":["quoteIdentifier","identifier","replaceAll","migrateSqliteJobsProcessingLease","db","direction","newIndexName","oldIndexName","sql","tableName","quotedTableName","run","statement","raw"],"mappings":"AAUA,MAAMA,kBAAkB,CAACC,aAA+B,CAAC,CAAC,EAAEA,WAAWC,UAAU,CAAC,KAAK,MAAM,CAAC,CAAC;AAE/F,OAAO,eAAeC,iCAAiC,EACrDC,EAAE,EACFC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,GAAG,EACHC,SAAS,EACJ;IACL,MAAMC,kBAAkBV,gBAAgBS;IACxC,MAAME,MAAM,CAACC,YAAsBR,GAAGO,GAAG,CAACH,IAAIK,GAAG,CAACD;IAElD,IAAIP,cAAc,MAAM;QACtB,MAAMM,IAAI,CAAC,YAAY,EAAED,gBAAgB,mCAAmC,CAAC;QAC7E,MAAMC,IACJ,CAAC,OAAO,EAAED,gBAAgB,8EAA8E,CAAC;QAE3G,MAAMC,IAAI,CAAC,qBAAqB,EAAEX,gBAAgBO,eAAe;QACjE,MAAMI,IAAI,CAAC,YAAY,EAAED,gBAAgB,yBAAyB,CAAC;QACnE,MAAMC,IACJ,CAAC,aAAa,EAAEX,gBAAgBM,cAAc,IAAI,EAAEI,gBAAgB,qBAAqB,CAAC;QAG5F;IACF;IAEA,MAAMC,IAAI,CAAC,YAAY,EAAED,gBAAgB,8CAA8C,CAAC;IACxF,MAAMC,IACJ,CAAC,OAAO,EAAED,gBAAgB,6DAA6D,CAAC;IAE1F,MAAMC,IAAI,CAAC,qBAAqB,EAAEX,gBAAgBM,eAAe;IACjE,MAAMK,IAAI,CAAC,YAAY,EAAED,gBAAgB,+BAA+B,CAAC;IACzE,MAAMC,IAAI,CAAC,aAAa,EAAEX,gBAAgBO,cAAc,IAAI,EAAEG,gBAAgB,eAAe,CAAC;AAChG"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,C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;QAE5FvD,cAAc,GAAGmB,SAAS,KAAK,CAAC,EAAES,KAAK4B,SAAS,CAACJ,iBAAiB,MAAM;QAExE,MAAMK,aAAa,CAAC;;kBAEN,EAAE7B,KAAK4B,SAAS,CAACR,cAAc;kBAC/B,EAAEpB,KAAK4B,SAAS,CAACP,cAAc;gBACjC,EAAErB,KAAK4B,SAAS,CAACN,YAAY;;eAE9B,EAAEtB,KAAK4B,SAAS,CAAC5C,WAAW,CAAC,CAAC;QAEzC,OAAO;YACL8C,SAAS,CAAC,kCAAkC,EAAED,WAAW;;IAE3D,CAAC;YACCE,SAAS,CAAC,4CAA4C,EAAEpB,YAAY,iBAAiB,CAAC;YACtFqB,OAAO,CAAC,kCAAkC,EAAEH,WAAW;;IAEzD,CAAC;QACD;IACF;AACF,EAAC"}
|
|
@@ -1,166 +0,0 @@
|
|
|
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" FROM "custom_jobs" ORDER BY "id"');
|
|
45
|
-
expect(migratedJobs.rows).toEqual([
|
|
46
|
-
{
|
|
47
|
-
id: 1,
|
|
48
|
-
processing_until: '1970-01-01T00:00:00.000Z'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: 2,
|
|
52
|
-
processing_until: null
|
|
53
|
-
}
|
|
54
|
-
]);
|
|
55
|
-
await migrateSqliteJobsProcessingLease({
|
|
56
|
-
db,
|
|
57
|
-
direction: 'down',
|
|
58
|
-
newIndexName: 'custom_jobs_processing_until_idx',
|
|
59
|
-
oldIndexName: 'custom_jobs_processing_idx',
|
|
60
|
-
sql,
|
|
61
|
-
tableName: 'custom_jobs'
|
|
62
|
-
});
|
|
63
|
-
const restoredJobs = await client.execute('SELECT "id", "processing" FROM "custom_jobs" ORDER BY "id"');
|
|
64
|
-
expect(restoredJobs.rows).toEqual([
|
|
65
|
-
{
|
|
66
|
-
id: 1,
|
|
67
|
-
processing: 1
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: 2,
|
|
71
|
-
processing: 0
|
|
72
|
-
}
|
|
73
|
-
]);
|
|
74
|
-
});
|
|
75
|
-
it('should produce PostgreSQL statements with quoted custom names', async ()=>{
|
|
76
|
-
const execute = vi.fn().mockResolvedValue(undefined);
|
|
77
|
-
await migratePostgresJobsProcessingLease({
|
|
78
|
-
db: {
|
|
79
|
-
execute
|
|
80
|
-
},
|
|
81
|
-
direction: 'up',
|
|
82
|
-
newIndexName: 'custom_jobs_processing_until_idx',
|
|
83
|
-
oldIndexName: 'custom_jobs_processing_idx',
|
|
84
|
-
schemaName: 'custom_schema',
|
|
85
|
-
sql: {
|
|
86
|
-
raw: (statement)=>statement
|
|
87
|
-
},
|
|
88
|
-
tableName: 'custom_jobs'
|
|
89
|
-
});
|
|
90
|
-
expect(execute.mock.calls.map(([statement])=>statement)).toEqual([
|
|
91
|
-
'ALTER TABLE "custom_schema"."custom_jobs" ADD COLUMN "processing_until" timestamp(3) with time zone',
|
|
92
|
-
'UPDATE "custom_schema"."custom_jobs" SET "processing_until" = \'1970-01-01 00:00:00+00\' WHERE "processing" = true',
|
|
93
|
-
'DROP INDEX IF EXISTS "custom_schema"."custom_jobs_processing_idx"',
|
|
94
|
-
'ALTER TABLE "custom_schema"."custom_jobs" DROP COLUMN "processing"',
|
|
95
|
-
'CREATE INDEX "custom_jobs_processing_until_idx" ON "custom_schema"."custom_jobs" USING btree ("processing_until")'
|
|
96
|
-
]);
|
|
97
|
-
});
|
|
98
|
-
it('should write a Drizzle snapshot and generate adapter-specific migration code', async ()=>{
|
|
99
|
-
const temporaryDirectory = mkdtempSync(path.join(tmpdir(), 'payload-jobs-migration-'));
|
|
100
|
-
temporaryDirectories.push(temporaryDirectory);
|
|
101
|
-
const filePath = path.join(temporaryDirectory, 'migration');
|
|
102
|
-
writeFileSync(path.join(temporaryDirectory, 'previous.json'), JSON.stringify({
|
|
103
|
-
tables: {
|
|
104
|
-
jobs: {
|
|
105
|
-
indexes: {
|
|
106
|
-
legacy: {
|
|
107
|
-
columns: [
|
|
108
|
-
{
|
|
109
|
-
expression: 'processing'
|
|
110
|
-
}
|
|
111
|
-
],
|
|
112
|
-
name: 'legacy_processing_index'
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
name: 'custom_jobs'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}));
|
|
119
|
-
const payload = {
|
|
120
|
-
db: {
|
|
121
|
-
rawTables: {
|
|
122
|
-
custom_jobs: {
|
|
123
|
-
indexes: {
|
|
124
|
-
processingUntil: {
|
|
125
|
-
name: 'custom_jobs_processing_until_idx',
|
|
126
|
-
on: 'processingUntil'
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
requireDrizzleKit: ()=>({
|
|
132
|
-
generateDrizzleJson: vi.fn().mockResolvedValue({
|
|
133
|
-
version: 'test-snapshot'
|
|
134
|
-
})
|
|
135
|
-
}),
|
|
136
|
-
schema: {},
|
|
137
|
-
schemaName: 'custom_schema',
|
|
138
|
-
tableNameMap: new Map([
|
|
139
|
-
[
|
|
140
|
-
'payload_jobs',
|
|
141
|
-
'custom_jobs'
|
|
142
|
-
]
|
|
143
|
-
])
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
const dynamic = buildDynamicPredefinedJobsProcessingLeaseMigration({
|
|
147
|
-
dialect: 'postgres',
|
|
148
|
-
packageName: '@payloadcms/db-postgres'
|
|
149
|
-
});
|
|
150
|
-
const migration = await dynamic({
|
|
151
|
-
filePath,
|
|
152
|
-
payload
|
|
153
|
-
});
|
|
154
|
-
expect(existsSync(`${filePath}.json`)).toBe(true);
|
|
155
|
-
expect(JSON.parse(readFileSync(`${filePath}.json`, 'utf8'))).toEqual({
|
|
156
|
-
version: 'test-snapshot'
|
|
157
|
-
});
|
|
158
|
-
expect(migration.imports).toContain('@payloadcms/db-postgres/migration-utils');
|
|
159
|
-
expect(migration.upSQL).toContain("direction: 'up'");
|
|
160
|
-
expect(migration.upSQL).toContain('custom_jobs_processing_until_idx');
|
|
161
|
-
expect(migration.upSQL).toContain('legacy_processing_index');
|
|
162
|
-
expect(migration.downSQL).toContain("direction: 'down'");
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
//# sourceMappingURL=jobsProcessingLeaseMigration.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/jobsProcessingLeaseMigration.spec.ts"],"sourcesContent":["import type { Client } from '@libsql/client'\nimport type { Payload } from 'payload'\n\nimport { createClient } from '@libsql/client'\nimport { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'\nimport { tmpdir } from 'os'\nimport path from 'path'\nimport { afterEach, describe, expect, it, vi } from 'vitest'\n\nimport { migratePostgresJobsProcessingLease } from '../postgres/predefinedMigrations/jobs-processing-lease/index.js'\nimport { migrateSqliteJobsProcessingLease } from '../sqlite/predefinedMigrations/jobs-processing-lease/index.js'\nimport { buildDynamicPredefinedJobsProcessingLeaseMigration } from './jobsProcessingLeaseMigration.js'\n\ndescribe('jobs processing lease predefined migration', () => {\n let client: Client | undefined\n const temporaryDirectories: string[] = []\n\n afterEach(() => {\n client?.close()\n client = undefined\n\n for (const directory of temporaryDirectories) {\n rmSync(directory, { force: true, recursive: true })\n }\n temporaryDirectories.length = 0\n })\n\n it('should migrate SQLite job data up and down', async () => {\n client = createClient({ url: ':memory:' })\n await client.execute(\n 'CREATE TABLE \"custom_jobs\" (\"id\" integer primary key, \"processing\" integer DEFAULT false)',\n )\n await client.execute(\n 'CREATE INDEX \"custom_jobs_processing_idx\" ON \"custom_jobs\" (\"processing\")',\n )\n await client.execute(\n 'INSERT INTO \"custom_jobs\" (\"id\", \"processing\") VALUES (1, true), (2, false)',\n )\n\n const db = { run: (statement: unknown) => client!.execute(statement as string) }\n const sql = { raw: (statement: string) => statement }\n\n await migrateSqliteJobsProcessingLease({\n db,\n direction: 'up',\n newIndexName: 'custom_jobs_processing_until_idx',\n oldIndexName: 'custom_jobs_processing_idx',\n sql,\n tableName: 'custom_jobs',\n })\n\n const migratedJobs = await client.execute(\n 'SELECT \"id\", \"processing_until\" FROM \"custom_jobs\" ORDER BY \"id\"',\n )\n expect(migratedJobs.rows).toEqual([\n { id: 1, processing_until: '1970-01-01T00:00:00.000Z' },\n { id: 2, processing_until: null },\n ])\n\n await migrateSqliteJobsProcessingLease({\n db,\n direction: 'down',\n newIndexName: 'custom_jobs_processing_until_idx',\n oldIndexName: 'custom_jobs_processing_idx',\n sql,\n tableName: 'custom_jobs',\n })\n\n const restoredJobs = await client.execute(\n 'SELECT \"id\", \"processing\" FROM \"custom_jobs\" ORDER BY \"id\"',\n )\n expect(restoredJobs.rows).toEqual([\n { id: 1, processing: 1 },\n { id: 2, processing: 0 },\n ])\n })\n\n it('should produce PostgreSQL statements with quoted custom names', async () => {\n const execute = vi.fn().mockResolvedValue(undefined)\n\n await migratePostgresJobsProcessingLease({\n db: { execute },\n direction: 'up',\n newIndexName: 'custom_jobs_processing_until_idx',\n oldIndexName: 'custom_jobs_processing_idx',\n schemaName: 'custom_schema',\n sql: { raw: (statement: string) => statement },\n tableName: 'custom_jobs',\n })\n\n expect(execute.mock.calls.map(([statement]) => statement)).toEqual([\n 'ALTER TABLE \"custom_schema\".\"custom_jobs\" ADD COLUMN \"processing_until\" timestamp(3) with time zone',\n 'UPDATE \"custom_schema\".\"custom_jobs\" SET \"processing_until\" = \\'1970-01-01 00:00:00+00\\' WHERE \"processing\" = true',\n 'DROP INDEX IF EXISTS \"custom_schema\".\"custom_jobs_processing_idx\"',\n 'ALTER TABLE \"custom_schema\".\"custom_jobs\" DROP COLUMN \"processing\"',\n 'CREATE INDEX \"custom_jobs_processing_until_idx\" ON \"custom_schema\".\"custom_jobs\" USING btree (\"processing_until\")',\n ])\n })\n\n it('should write a Drizzle snapshot and generate adapter-specific migration code', async () => {\n const temporaryDirectory = mkdtempSync(path.join(tmpdir(), 'payload-jobs-migration-'))\n temporaryDirectories.push(temporaryDirectory)\n const filePath = path.join(temporaryDirectory, 'migration')\n writeFileSync(\n path.join(temporaryDirectory, 'previous.json'),\n JSON.stringify({\n tables: {\n jobs: {\n indexes: {\n legacy: {\n columns: [{ expression: 'processing' }],\n name: 'legacy_processing_index',\n },\n },\n name: 'custom_jobs',\n },\n },\n }),\n )\n const payload = {\n db: {\n rawTables: {\n custom_jobs: {\n indexes: {\n processingUntil: {\n name: 'custom_jobs_processing_until_idx',\n on: 'processingUntil',\n },\n },\n },\n },\n requireDrizzleKit: () => ({\n generateDrizzleJson: vi.fn().mockResolvedValue({ version: 'test-snapshot' }),\n }),\n schema: {},\n schemaName: 'custom_schema',\n tableNameMap: new Map([['payload_jobs', 'custom_jobs']]),\n },\n } as unknown as Payload\n\n const dynamic = buildDynamicPredefinedJobsProcessingLeaseMigration({\n dialect: 'postgres',\n packageName: '@payloadcms/db-postgres',\n })\n const migration = await dynamic({ filePath, payload })\n\n expect(existsSync(`${filePath}.json`)).toBe(true)\n expect(JSON.parse(readFileSync(`${filePath}.json`, 'utf8'))).toEqual({\n version: 'test-snapshot',\n })\n expect(migration.imports).toContain('@payloadcms/db-postgres/migration-utils')\n expect(migration.upSQL).toContain(\"direction: 'up'\")\n expect(migration.upSQL).toContain('custom_jobs_processing_until_idx')\n expect(migration.upSQL).toContain('legacy_processing_index')\n expect(migration.downSQL).toContain(\"direction: 'down'\")\n })\n})\n"],"names":["createClient","existsSync","mkdtempSync","readFileSync","rmSync","writeFileSync","tmpdir","path","afterEach","describe","expect","it","vi","migratePostgresJobsProcessingLease","migrateSqliteJobsProcessingLease","buildDynamicPredefinedJobsProcessingLeaseMigration","client","temporaryDirectories","close","undefined","directory","force","recursive","length","url","execute","db","run","statement","sql","raw","direction","newIndexName","oldIndexName","tableName","migratedJobs","rows","toEqual","id","processing_until","restoredJobs","processing","fn","mockResolvedValue","schemaName","mock","calls","map","temporaryDirectory","join","push","filePath","JSON","stringify","tables","jobs","indexes","legacy","columns","expression","name","payload","rawTables","custom_jobs","processingUntil","on","requireDrizzleKit","generateDrizzleJson","version","schema","tableNameMap","Map","dynamic","dialect","packageName","migration","toBe","parse","imports","toContain","upSQL","downSQL"],"mappings":"AAGA,SAASA,YAAY,QAAQ,iBAAgB;AAC7C,SAASC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAEC,MAAM,EAAEC,aAAa,QAAQ,KAAI;AACjF,SAASC,MAAM,QAAQ,KAAI;AAC3B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAE5D,SAASC,kCAAkC,QAAQ,kEAAiE;AACpH,SAASC,gCAAgC,QAAQ,gEAA+D;AAChH,SAASC,kDAAkD,QAAQ,oCAAmC;AAEtGN,SAAS,8CAA8C;IACrD,IAAIO;IACJ,MAAMC,uBAAiC,EAAE;IAEzCT,UAAU;QACRQ,QAAQE;QACRF,SAASG;QAET,KAAK,MAAMC,aAAaH,qBAAsB;YAC5Cb,OAAOgB,WAAW;gBAAEC,OAAO;gBAAMC,WAAW;YAAK;QACnD;QACAL,qBAAqBM,MAAM,GAAG;IAChC;IAEAZ,GAAG,8CAA8C;QAC/CK,SAAShB,aAAa;YAAEwB,KAAK;QAAW;QACxC,MAAMR,OAAOS,OAAO,CAClB;QAEF,MAAMT,OAAOS,OAAO,CAClB;QAEF,MAAMT,OAAOS,OAAO,CAClB;QAGF,MAAMC,KAAK;YAAEC,KAAK,CAACC,YAAuBZ,OAAQS,OAAO,CAACG;QAAqB;QAC/E,MAAMC,MAAM;YAAEC,KAAK,CAACF,YAAsBA;QAAU;QAEpD,MAAMd,iCAAiC;YACrCY;YACAK,WAAW;YACXC,cAAc;YACdC,cAAc;YACdJ;YACAK,WAAW;QACb;QAEA,MAAMC,eAA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