@payloadcms/db-postgres 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/dist/connect.d.ts +1 -1
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +45 -17
- package/dist/connect.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +2 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +3 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -69
- package/dist/index.js.map +1 -1
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +169 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +196 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/index.d.ts +23 -0
- package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/index.js +211 -0
- package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +20 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +63 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
- package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/types.js +6 -0
- package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
- package/dist/types.d.ts +65 -77
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/license.md +22 -0
- package/package.json +35 -17
- package/dist/count.d.ts +0 -3
- package/dist/count.d.ts.map +0 -1
- package/dist/count.js +0 -50
- package/dist/count.js.map +0 -1
- package/dist/create.d.ts +0 -3
- package/dist/create.d.ts.map +0 -1
- package/dist/create.js +0 -19
- package/dist/create.js.map +0 -1
- package/dist/createGlobal.d.ts +0 -5
- package/dist/createGlobal.d.ts.map +0 -1
- package/dist/createGlobal.js +0 -19
- package/dist/createGlobal.js.map +0 -1
- package/dist/createGlobalVersion.d.ts +0 -6
- package/dist/createGlobalVersion.d.ts.map +0 -1
- package/dist/createGlobalVersion.js +0 -33
- package/dist/createGlobalVersion.js.map +0 -1
- package/dist/createMigration.d.ts +0 -3
- package/dist/createMigration.d.ts.map +0 -1
- package/dist/createMigration.js +0 -81
- package/dist/createMigration.js.map +0 -1
- package/dist/createVersion.d.ts +0 -5
- package/dist/createVersion.d.ts.map +0 -1
- package/dist/createVersion.js +0 -44
- package/dist/createVersion.js.map +0 -1
- package/dist/deleteMany.d.ts +0 -3
- package/dist/deleteMany.d.ts.map +0 -1
- package/dist/deleteMany.js +0 -28
- package/dist/deleteMany.js.map +0 -1
- package/dist/deleteOne.d.ts +0 -3
- package/dist/deleteOne.d.ts.map +0 -1
- package/dist/deleteOne.js +0 -59
- package/dist/deleteOne.js.map +0 -1
- package/dist/deleteVersions.d.ts +0 -3
- package/dist/deleteVersions.d.ts.map +0 -1
- package/dist/deleteVersions.js +0 -31
- package/dist/deleteVersions.js.map +0 -1
- package/dist/destroy.d.ts +0 -3
- package/dist/destroy.d.ts.map +0 -1
- package/dist/destroy.js +0 -11
- package/dist/destroy.js.map +0 -1
- package/dist/find/buildFindManyArgs.d.ts +0 -13
- package/dist/find/buildFindManyArgs.d.ts.map +0 -1
- package/dist/find/buildFindManyArgs.js +0 -64
- package/dist/find/buildFindManyArgs.js.map +0 -1
- package/dist/find/chainMethods.d.ts +0 -16
- package/dist/find/chainMethods.d.ts.map +0 -1
- package/dist/find/chainMethods.js +0 -12
- package/dist/find/chainMethods.js.map +0 -1
- package/dist/find/findMany.d.ts +0 -22
- package/dist/find/findMany.d.ts.map +0 -1
- package/dist/find/findMany.js +0 -163
- package/dist/find/findMany.js.map +0 -1
- package/dist/find/traverseFields.d.ts +0 -16
- package/dist/find/traverseFields.d.ts.map +0 -1
- package/dist/find/traverseFields.js +0 -138
- package/dist/find/traverseFields.js.map +0 -1
- package/dist/find.d.ts +0 -3
- package/dist/find.d.ts.map +0 -1
- package/dist/find.js +0 -21
- package/dist/find.js.map +0 -1
- package/dist/findGlobal.d.ts +0 -3
- package/dist/findGlobal.d.ts.map +0 -1
- package/dist/findGlobal.js +0 -23
- package/dist/findGlobal.js.map +0 -1
- package/dist/findGlobalVersions.d.ts +0 -3
- package/dist/findGlobalVersions.d.ts.map +0 -1
- package/dist/findGlobalVersions.js +0 -24
- package/dist/findGlobalVersions.js.map +0 -1
- package/dist/findOne.d.ts +0 -5
- package/dist/findOne.d.ts.map +0 -1
- package/dist/findOne.js +0 -21
- package/dist/findOne.js.map +0 -1
- package/dist/findVersions.d.ts +0 -3
- package/dist/findVersions.d.ts.map +0 -1
- package/dist/findVersions.js +0 -24
- package/dist/findVersions.js.map +0 -1
- package/dist/init.d.ts +0 -3
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -96
- package/dist/init.js.map +0 -1
- package/dist/migrate.d.ts +0 -3
- package/dist/migrate.d.ts.map +0 -1
- package/dist/migrate.js +0 -99
- package/dist/migrate.js.map +0 -1
- package/dist/migrateDown.d.ts +0 -3
- package/dist/migrateDown.d.ts.map +0 -1
- package/dist/migrateDown.js +0 -63
- package/dist/migrateDown.js.map +0 -1
- package/dist/migrateFresh.d.ts +0 -8
- package/dist/migrateFresh.d.ts.map +0 -1
- package/dist/migrateFresh.js +0 -72
- package/dist/migrateFresh.js.map +0 -1
- package/dist/migrateRefresh.d.ts +0 -6
- package/dist/migrateRefresh.d.ts.map +0 -1
- package/dist/migrateRefresh.js +0 -102
- package/dist/migrateRefresh.js.map +0 -1
- package/dist/migrateReset.d.ts +0 -6
- package/dist/migrateReset.d.ts.map +0 -1
- package/dist/migrateReset.js +0 -82
- package/dist/migrateReset.js.map +0 -1
- package/dist/migrateStatus.d.ts +0 -3
- package/dist/migrateStatus.d.ts.map +0 -1
- package/dist/migrateStatus.js +0 -44
- package/dist/migrateStatus.js.map +0 -1
- package/dist/queries/buildAndOrConditions.d.ts +0 -17
- package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
- package/dist/queries/buildAndOrConditions.js +0 -29
- package/dist/queries/buildAndOrConditions.js.map +0 -1
- package/dist/queries/buildQuery.d.ts +0 -31
- package/dist/queries/buildQuery.d.ts.map +0 -1
- package/dist/queries/buildQuery.js +0 -76
- package/dist/queries/buildQuery.js.map +0 -1
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts +0 -2
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.d.ts.map +0 -1
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js +0 -14
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
- package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts +0 -2
- package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
- package/dist/queries/createJSONQuery/formatJSONPathSegment.js +0 -5
- package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
- package/dist/queries/createJSONQuery/index.d.ts +0 -10
- package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
- package/dist/queries/createJSONQuery/index.js +0 -54
- package/dist/queries/createJSONQuery/index.js.map +0 -1
- package/dist/queries/getTableColumnFromPath.d.ts +0 -51
- package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
- package/dist/queries/getTableColumnFromPath.js +0 -445
- package/dist/queries/getTableColumnFromPath.js.map +0 -1
- package/dist/queries/operatorMap.d.ts +0 -18
- package/dist/queries/operatorMap.d.ts.map +0 -1
- package/dist/queries/operatorMap.js +0 -24
- package/dist/queries/operatorMap.js.map +0 -1
- package/dist/queries/parseParams.d.ts +0 -17
- package/dist/queries/parseParams.d.ts.map +0 -1
- package/dist/queries/parseParams.js +0 -182
- package/dist/queries/parseParams.js.map +0 -1
- package/dist/queries/sanitizeQueryValue.d.ts +0 -15
- package/dist/queries/sanitizeQueryValue.d.ts.map +0 -1
- package/dist/queries/sanitizeQueryValue.js +0 -90
- package/dist/queries/sanitizeQueryValue.js.map +0 -1
- package/dist/queries/selectDistinct.d.ts +0 -23
- package/dist/queries/selectDistinct.d.ts.map +0 -1
- package/dist/queries/selectDistinct.js +0 -41
- package/dist/queries/selectDistinct.js.map +0 -1
- package/dist/queryDrafts.d.ts +0 -3
- package/dist/queryDrafts.d.ts.map +0 -1
- package/dist/queryDrafts.js +0 -41
- package/dist/queryDrafts.js.map +0 -1
- package/dist/schema/build.d.ts +0 -30
- package/dist/schema/build.d.ts.map +0 -1
- package/dist/schema/build.js +0 -320
- package/dist/schema/build.js.map +0 -1
- package/dist/schema/createIndex.d.ts +0 -12
- package/dist/schema/createIndex.d.ts.map +0 -1
- package/dist/schema/createIndex.js +0 -18
- package/dist/schema/createIndex.js.map +0 -1
- package/dist/schema/createTableName.d.ts +0 -30
- package/dist/schema/createTableName.d.ts.map +0 -1
- package/dist/schema/createTableName.js +0 -31
- package/dist/schema/createTableName.js.map +0 -1
- package/dist/schema/idToUUID.d.ts +0 -3
- package/dist/schema/idToUUID.d.ts.map +0 -1
- package/dist/schema/idToUUID.js +0 -11
- package/dist/schema/idToUUID.js.map +0 -1
- package/dist/schema/parentIDColumnMap.d.ts +0 -4
- package/dist/schema/parentIDColumnMap.d.ts.map +0 -1
- package/dist/schema/parentIDColumnMap.js +0 -9
- package/dist/schema/parentIDColumnMap.js.map +0 -1
- package/dist/schema/setColumnID.d.ts +0 -11
- package/dist/schema/setColumnID.d.ts.map +0 -1
- package/dist/schema/setColumnID.js +0 -24
- package/dist/schema/setColumnID.js.map +0 -1
- package/dist/schema/traverseFields.d.ts +0 -38
- package/dist/schema/traverseFields.d.ts.map +0 -1
- package/dist/schema/traverseFields.js +0 -551
- package/dist/schema/traverseFields.js.map +0 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -12
- package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
- package/dist/schema/validateExistingBlockIsIdentical.js +0 -76
- package/dist/schema/validateExistingBlockIsIdentical.js.map +0 -1
- package/dist/transactions/beginTransaction.d.ts +0 -3
- package/dist/transactions/beginTransaction.d.ts.map +0 -1
- package/dist/transactions/beginTransaction.js +0 -47
- package/dist/transactions/beginTransaction.js.map +0 -1
- package/dist/transactions/commitTransaction.d.ts +0 -3
- package/dist/transactions/commitTransaction.d.ts.map +0 -1
- package/dist/transactions/commitTransaction.js +0 -14
- package/dist/transactions/commitTransaction.js.map +0 -1
- package/dist/transactions/rollbackTransaction.d.ts +0 -3
- package/dist/transactions/rollbackTransaction.d.ts.map +0 -1
- package/dist/transactions/rollbackTransaction.js +0 -13
- package/dist/transactions/rollbackTransaction.js.map +0 -1
- package/dist/transform/read/hasManyNumber.d.ts +0 -10
- package/dist/transform/read/hasManyNumber.d.ts.map +0 -1
- package/dist/transform/read/hasManyNumber.js +0 -10
- package/dist/transform/read/hasManyNumber.js.map +0 -1
- package/dist/transform/read/hasManyText.d.ts +0 -10
- package/dist/transform/read/hasManyText.d.ts.map +0 -1
- package/dist/transform/read/hasManyText.js +0 -10
- package/dist/transform/read/hasManyText.js.map +0 -1
- package/dist/transform/read/index.d.ts +0 -12
- package/dist/transform/read/index.d.ts.map +0 -1
- package/dist/transform/read/index.js +0 -43
- package/dist/transform/read/index.js.map +0 -1
- package/dist/transform/read/relationship.d.ts +0 -10
- package/dist/transform/read/relationship.d.ts.map +0 -1
- package/dist/transform/read/relationship.js +0 -64
- package/dist/transform/read/relationship.js.map +0 -1
- package/dist/transform/read/traverseFields.d.ts +0 -52
- package/dist/transform/read/traverseFields.d.ts.map +0 -1
- package/dist/transform/read/traverseFields.js +0 -421
- package/dist/transform/read/traverseFields.js.map +0 -1
- package/dist/transform/write/array.d.ts +0 -26
- package/dist/transform/write/array.d.ts.map +0 -1
- package/dist/transform/write/array.js +0 -58
- package/dist/transform/write/array.js.map +0 -1
- package/dist/transform/write/blocks.d.ts +0 -25
- package/dist/transform/write/blocks.d.ts.map +0 -1
- package/dist/transform/write/blocks.js +0 -54
- package/dist/transform/write/blocks.js.map +0 -1
- package/dist/transform/write/index.d.ts +0 -13
- package/dist/transform/write/index.d.ts.map +0 -1
- package/dist/transform/write/index.js +0 -41
- package/dist/transform/write/index.js.map +0 -1
- package/dist/transform/write/numbers.d.ts +0 -8
- package/dist/transform/write/numbers.d.ts.map +0 -1
- package/dist/transform/write/numbers.js +0 -11
- package/dist/transform/write/numbers.js.map +0 -1
- package/dist/transform/write/relationships.d.ts +0 -10
- package/dist/transform/write/relationships.d.ts.map +0 -1
- package/dist/transform/write/relationships.js +0 -23
- package/dist/transform/write/relationships.js.map +0 -1
- package/dist/transform/write/selects.d.ts +0 -8
- package/dist/transform/write/selects.d.ts.map +0 -1
- package/dist/transform/write/selects.js +0 -20
- package/dist/transform/write/selects.js.map +0 -1
- package/dist/transform/write/texts.d.ts +0 -8
- package/dist/transform/write/texts.d.ts.map +0 -1
- package/dist/transform/write/texts.js +0 -11
- package/dist/transform/write/texts.js.map +0 -1
- package/dist/transform/write/traverseFields.d.ts +0 -50
- package/dist/transform/write/traverseFields.d.ts.map +0 -1
- package/dist/transform/write/traverseFields.js +0 -428
- package/dist/transform/write/traverseFields.js.map +0 -1
- package/dist/transform/write/types.d.ts +0 -43
- package/dist/transform/write/types.d.ts.map +0 -1
- package/dist/transform/write/types.js +0 -3
- package/dist/transform/write/types.js.map +0 -1
- package/dist/update.d.ts +0 -3
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js +0 -55
- package/dist/update.js.map +0 -1
- package/dist/updateGlobal.d.ts +0 -5
- package/dist/updateGlobal.d.ts.map +0 -1
- package/dist/updateGlobal.js +0 -25
- package/dist/updateGlobal.js.map +0 -1
- package/dist/updateGlobalVersion.d.ts +0 -5
- package/dist/updateGlobalVersion.d.ts.map +0 -1
- package/dist/updateGlobalVersion.js +0 -36
- package/dist/updateGlobalVersion.js.map +0 -1
- package/dist/updateVersion.d.ts +0 -5
- package/dist/updateVersion.d.ts.map +0 -1
- package/dist/updateVersion.js +0 -36
- package/dist/updateVersion.js.map +0 -1
- package/dist/upsertRow/deleteExistingArrayRows.d.ts +0 -10
- package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +0 -1
- package/dist/upsertRow/deleteExistingArrayRows.js +0 -10
- package/dist/upsertRow/deleteExistingArrayRows.js.map +0 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts +0 -14
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +0 -1
- package/dist/upsertRow/deleteExistingRowsByPath.js +0 -33
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +0 -1
- package/dist/upsertRow/index.d.ts +0 -4
- package/dist/upsertRow/index.d.ts.map +0 -1
- package/dist/upsertRow/index.js +0 -277
- package/dist/upsertRow/index.js.map +0 -1
- package/dist/upsertRow/insertArrays.d.ts +0 -13
- package/dist/upsertRow/insertArrays.d.ts.map +0 -1
- package/dist/upsertRow/insertArrays.js +0 -68
- package/dist/upsertRow/insertArrays.js.map +0 -1
- package/dist/upsertRow/types.d.ts +0 -27
- package/dist/upsertRow/types.d.ts.map +0 -1
- package/dist/upsertRow/types.js +0 -3
- package/dist/upsertRow/types.js.map +0 -1
- package/dist/utilities/appendPrefixToKeys.d.ts +0 -2
- package/dist/utilities/appendPrefixToKeys.d.ts.map +0 -1
- package/dist/utilities/appendPrefixToKeys.js +0 -6
- package/dist/utilities/appendPrefixToKeys.js.map +0 -1
- package/dist/utilities/createBlocksMap.d.ts +0 -5
- package/dist/utilities/createBlocksMap.d.ts.map +0 -1
- package/dist/utilities/createBlocksMap.js +0 -29
- package/dist/utilities/createBlocksMap.js.map +0 -1
- package/dist/utilities/createMigrationTable.d.ts +0 -3
- package/dist/utilities/createMigrationTable.d.ts.map +0 -1
- package/dist/utilities/createMigrationTable.js +0 -13
- package/dist/utilities/createMigrationTable.js.map +0 -1
- package/dist/utilities/createRelationshipMap.d.ts +0 -2
- package/dist/utilities/createRelationshipMap.d.ts.map +0 -1
- package/dist/utilities/createRelationshipMap.js +0 -19
- package/dist/utilities/createRelationshipMap.js.map +0 -1
- package/dist/utilities/hasLocalesTable.d.ts +0 -3
- package/dist/utilities/hasLocalesTable.d.ts.map +0 -1
- package/dist/utilities/hasLocalesTable.js +0 -11
- package/dist/utilities/hasLocalesTable.js.map +0 -1
- package/dist/utilities/isArrayOfRows.d.ts +0 -2
- package/dist/utilities/isArrayOfRows.d.ts.map +0 -1
- package/dist/utilities/isArrayOfRows.js +0 -5
- package/dist/utilities/isArrayOfRows.js.map +0 -1
- package/dist/utilities/migrationTableExists.d.ts +0 -3
- package/dist/utilities/migrationTableExists.d.ts.map +0 -1
- package/dist/utilities/migrationTableExists.js +0 -9
- package/dist/utilities/migrationTableExists.js.map +0 -1
- package/dist/utilities/parseError.d.ts +0 -5
- package/dist/utilities/parseError.d.ts.map +0 -1
- package/dist/utilities/parseError.js +0 -17
- package/dist/utilities/parseError.js.map +0 -1
- package/dist/utilities/pushDevSchema.d.ts +0 -9
- package/dist/utilities/pushDevSchema.d.ts.map +0 -1
- package/dist/utilities/pushDevSchema.js +0 -58
- package/dist/utilities/pushDevSchema.js.map +0 -1
@@ -0,0 +1,169 @@
|
|
1
|
+
import { upsertRow } from '@payloadcms/drizzle';
|
2
|
+
import { traverseFields } from './traverseFields.js';
|
3
|
+
export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsToResave, fields, globalSlug, isVersions, payload, req, tableName })=>{
|
4
|
+
for (const [id, rows] of Object.entries(docsToResave)){
|
5
|
+
if (collectionSlug) {
|
6
|
+
const collectionConfig = payload.collections[collectionSlug].config;
|
7
|
+
if (collectionConfig) {
|
8
|
+
if (isVersions) {
|
9
|
+
const doc = await payload.findVersionByID({
|
10
|
+
id,
|
11
|
+
collection: collectionSlug,
|
12
|
+
depth: 0,
|
13
|
+
fallbackLocale: null,
|
14
|
+
locale: 'all',
|
15
|
+
req,
|
16
|
+
showHiddenFields: true
|
17
|
+
});
|
18
|
+
if (debug) {
|
19
|
+
payload.logger.info(`The collection "${collectionConfig.slug}" version with ID ${id} will be migrated`);
|
20
|
+
}
|
21
|
+
traverseFields({
|
22
|
+
doc,
|
23
|
+
fields,
|
24
|
+
path: '',
|
25
|
+
rows
|
26
|
+
});
|
27
|
+
try {
|
28
|
+
await upsertRow({
|
29
|
+
id: doc.id,
|
30
|
+
adapter,
|
31
|
+
data: doc,
|
32
|
+
db,
|
33
|
+
fields,
|
34
|
+
ignoreResult: true,
|
35
|
+
operation: 'update',
|
36
|
+
req,
|
37
|
+
tableName
|
38
|
+
});
|
39
|
+
} catch (err) {
|
40
|
+
payload.logger.error(`"${collectionConfig.slug}" version with ID ${doc.id} FAILED TO MIGRATE`);
|
41
|
+
throw err;
|
42
|
+
}
|
43
|
+
if (debug) {
|
44
|
+
payload.logger.info(`"${collectionConfig.slug}" version with ID ${doc.id} migrated successfully!`);
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
const doc = await payload.findByID({
|
48
|
+
id,
|
49
|
+
collection: collectionSlug,
|
50
|
+
depth: 0,
|
51
|
+
fallbackLocale: null,
|
52
|
+
locale: 'all',
|
53
|
+
req,
|
54
|
+
showHiddenFields: true
|
55
|
+
});
|
56
|
+
if (debug) {
|
57
|
+
payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} will be migrated`);
|
58
|
+
}
|
59
|
+
traverseFields({
|
60
|
+
doc,
|
61
|
+
fields,
|
62
|
+
path: '',
|
63
|
+
rows
|
64
|
+
});
|
65
|
+
try {
|
66
|
+
await upsertRow({
|
67
|
+
id: doc.id,
|
68
|
+
adapter,
|
69
|
+
data: doc,
|
70
|
+
db,
|
71
|
+
fields,
|
72
|
+
ignoreResult: true,
|
73
|
+
operation: 'update',
|
74
|
+
req,
|
75
|
+
tableName
|
76
|
+
});
|
77
|
+
} catch (err) {
|
78
|
+
payload.logger.error(`The collection "${collectionConfig.slug}" with ID ${doc.id} has FAILED TO MIGRATE`);
|
79
|
+
throw err;
|
80
|
+
}
|
81
|
+
if (debug) {
|
82
|
+
payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} has migrated successfully!`);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
if (globalSlug) {
|
88
|
+
const globalConfig = payload.config.globals?.find((global)=>global.slug === globalSlug);
|
89
|
+
if (globalConfig) {
|
90
|
+
if (isVersions) {
|
91
|
+
const { docs } = await payload.findGlobalVersions({
|
92
|
+
slug: globalSlug,
|
93
|
+
depth: 0,
|
94
|
+
fallbackLocale: null,
|
95
|
+
limit: 0,
|
96
|
+
locale: 'all',
|
97
|
+
req,
|
98
|
+
showHiddenFields: true
|
99
|
+
});
|
100
|
+
if (debug) {
|
101
|
+
payload.logger.info(`${docs.length} global "${globalSlug}" versions will be migrated`);
|
102
|
+
}
|
103
|
+
for (const doc of docs){
|
104
|
+
traverseFields({
|
105
|
+
doc,
|
106
|
+
fields,
|
107
|
+
path: '',
|
108
|
+
rows
|
109
|
+
});
|
110
|
+
try {
|
111
|
+
await upsertRow({
|
112
|
+
id: doc.id,
|
113
|
+
adapter,
|
114
|
+
data: doc,
|
115
|
+
db,
|
116
|
+
fields,
|
117
|
+
ignoreResult: true,
|
118
|
+
operation: 'update',
|
119
|
+
req,
|
120
|
+
tableName
|
121
|
+
});
|
122
|
+
} catch (err) {
|
123
|
+
payload.logger.error(`"${globalSlug}" version with ID ${doc.id} FAILED TO MIGRATE`);
|
124
|
+
throw err;
|
125
|
+
}
|
126
|
+
if (debug) {
|
127
|
+
payload.logger.info(`"${globalSlug}" version with ID ${doc.id} migrated successfully!`);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
const doc = await payload.findGlobal({
|
132
|
+
slug: globalSlug,
|
133
|
+
depth: 0,
|
134
|
+
fallbackLocale: null,
|
135
|
+
locale: 'all',
|
136
|
+
req,
|
137
|
+
showHiddenFields: true
|
138
|
+
});
|
139
|
+
traverseFields({
|
140
|
+
doc,
|
141
|
+
fields,
|
142
|
+
path: '',
|
143
|
+
rows
|
144
|
+
});
|
145
|
+
try {
|
146
|
+
await upsertRow({
|
147
|
+
adapter,
|
148
|
+
data: doc,
|
149
|
+
db,
|
150
|
+
fields,
|
151
|
+
ignoreResult: true,
|
152
|
+
operation: 'update',
|
153
|
+
req,
|
154
|
+
tableName
|
155
|
+
});
|
156
|
+
} catch (err) {
|
157
|
+
payload.logger.error(`The global "${globalSlug}" has FAILED TO MIGRATE`);
|
158
|
+
throw err;
|
159
|
+
}
|
160
|
+
if (debug) {
|
161
|
+
payload.logger.info(`The global "${globalSlug}" has migrated successfully!`);
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
};
|
168
|
+
|
169
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"sourcesContent":["import type { TransactionPg } from '@payloadcms/drizzle/types'\nimport type { Field, Payload, PayloadRequest } from 'payload'\n\nimport { upsertRow } from '@payloadcms/drizzle'\n\nimport type { PostgresAdapter } from '../../../types.js'\nimport type { DocsToResave } from '../types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\ntype Args = {\n adapter: PostgresAdapter\n collectionSlug?: string\n db: TransactionPg\n debug: boolean\n docsToResave: DocsToResave\n fields: Field[]\n globalSlug?: string\n isVersions: boolean\n payload: Payload\n req: PayloadRequest\n tableName: string\n}\n\nexport const fetchAndResave = async ({\n adapter,\n collectionSlug,\n db,\n debug,\n docsToResave,\n fields,\n globalSlug,\n isVersions,\n payload,\n req,\n tableName,\n}: Args) => {\n for (const [id, rows] of Object.entries(docsToResave)) {\n if (collectionSlug) {\n const collectionConfig = payload.collections[collectionSlug].config\n\n if (collectionConfig) {\n if (isVersions) {\n const doc = await payload.findVersionByID({\n id,\n collection: collectionSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" version with ID ${id} will be migrated`,\n )\n }\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(\n `\"${collectionConfig.slug}\" version with ID ${doc.id} FAILED TO MIGRATE`,\n )\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `\"${collectionConfig.slug}\" version with ID ${doc.id} migrated successfully!`,\n )\n }\n } else {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} will be migrated`,\n )\n }\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} has FAILED TO MIGRATE`,\n )\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `The collection \"${collectionConfig.slug}\" with ID ${doc.id} has migrated successfully!`,\n )\n }\n }\n }\n }\n\n if (globalSlug) {\n const globalConfig = payload.config.globals?.find((global) => global.slug === globalSlug)\n\n if (globalConfig) {\n if (isVersions) {\n const { docs } = await payload.findGlobalVersions({\n slug: globalSlug,\n depth: 0,\n fallbackLocale: null,\n limit: 0,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n if (debug) {\n payload.logger.info(`${docs.length} global \"${globalSlug}\" versions will be migrated`)\n }\n\n for (const doc of docs) {\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n id: doc.id,\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(`\"${globalSlug}\" version with ID ${doc.id} FAILED TO MIGRATE`)\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(\n `\"${globalSlug}\" version with ID ${doc.id} migrated successfully!`,\n )\n }\n }\n } else {\n const doc = await payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n fallbackLocale: null,\n locale: 'all',\n req,\n showHiddenFields: true,\n })\n\n traverseFields({\n doc,\n fields,\n path: '',\n rows,\n })\n\n try {\n await upsertRow({\n adapter,\n data: doc,\n db,\n fields,\n ignoreResult: true,\n operation: 'update',\n req,\n tableName,\n })\n } catch (err) {\n payload.logger.error(`The global \"${globalSlug}\" has FAILED TO MIGRATE`)\n\n throw err\n }\n\n if (debug) {\n payload.logger.info(`The global \"${globalSlug}\" has migrated successfully!`)\n }\n }\n }\n }\n }\n}\n"],"names":["upsertRow","traverseFields","fetchAndResave","adapter","collectionSlug","db","debug","docsToResave","fields","globalSlug","isVersions","payload","req","tableName","id","rows","Object","entries","collectionConfig","collections","config","doc","findVersionByID","collection","depth","fallbackLocale","locale","showHiddenFields","logger","info","slug","path","data","ignoreResult","operation","err","error","findByID","globalConfig","globals","find","global","docs","findGlobalVersions","limit","length","findGlobal"],"mappings":"AAGA,SAASA,SAAS,QAAQ,sBAAqB;AAK/C,SAASC,cAAc,QAAQ,sBAAqB;AAgBpD,OAAO,MAAMC,iBAAiB,OAAO,EACnCC,OAAO,EACPC,cAAc,EACdC,EAAE,EACFC,KAAK,EACLC,YAAY,EACZC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,OAAO,EACPC,GAAG,EACHC,SAAS,EACJ;IACL,KAAK,MAAM,CAACC,IAAIC,KAAK,IAAIC,OAAOC,OAAO,CAACV,cAAe;QACrD,IAAIH,gBAAgB;YAClB,MAAMc,mBAAmBP,QAAQQ,WAAW,CAACf,eAAe,CAACgB,MAAM;YAEnE,IAAIF,kBAAkB;gBACpB,IAAIR,YAAY;oBACd,MAAMW,MAAM,MAAMV,QAAQW,eAAe,CAAC;wBACxCR;wBACAS,YAAYnB;wBACZoB,OAAO;wBACPC,gBAAgB;wBAChBC,QAAQ;wBACRd;wBACAe,kBAAkB;oBACpB;oBAEA,IAAIrB,OAAO;wBACTK,QAAQiB,MAAM,CAACC,IAAI,CACjB,CAAC,gBAAgB,EAAEX,iBAAiBY,IAAI,CAAC,kBAAkB,EAAEhB,GAAG,iBAAiB,CAAC;oBAEtF;oBAEAb,eAAe;wBACboB;wBACAb;wBACAuB,MAAM;wBACNhB;oB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ACnChB,MAAMrB;wBACNe,OAAO;wBACPC,gBAAgB;wBAChBC,QAAQ;wBACRd;wBACAe,kBAAkB;oBACpB;oBAEA1B,eAAe;wBACboB;wBACAb;wBACAuB,MAAM;wBACNhB;oBACF;oBAEA,IAAI;wBACF,MAAMf,UAAU;4BACdG;4BACA6B,MAAMX;4BACNhB;4BACAG;4BACAyB,cAAc;4BACdC,WAAW;4BACXtB;4BACAC;wBACF;oBACF,EAAE,OAAOsB,KAAK;wBACZxB,QAAQiB,MAAM,CAACQ,KAAK,CAAC,CAAC,YAAY,EAAE3B,WAAW,uBAAuB,CAAC;wBAEvE,MAAM0B;oBACR;oBAEA,IAAI7B,OAAO;wBACTK,QAAQiB,MAAM,CAACC,IAAI,CAAC,CAAC,YAAY,EAAEpB,WAAW,4BAA4B,CAAC;oBAC7E;gBACF;YACF;QACF;IACF;AACF,EAAC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { Field } from 'payload';
|
2
|
+
type Args = {
|
3
|
+
doc: Record<string, unknown>;
|
4
|
+
fields: Field[];
|
5
|
+
locale?: string;
|
6
|
+
path: string;
|
7
|
+
rows: Record<string, unknown>[];
|
8
|
+
};
|
9
|
+
export declare const traverseFields: ({ doc, fields, locale, path, rows }: Args) => void;
|
10
|
+
export {};
|
11
|
+
//# sourceMappingURL=traverseFields.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5B,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,cAAc,wCAAyC,IAAI,SA6MvE,CAAA"}
|
@@ -0,0 +1,196 @@
|
|
1
|
+
import { tabHasName } from 'payload/shared';
|
2
|
+
export const traverseFields = ({ doc, fields, locale, path, rows })=>{
|
3
|
+
fields.forEach((field)=>{
|
4
|
+
switch(field.type){
|
5
|
+
case 'array':
|
6
|
+
{
|
7
|
+
const rowData = doc?.[field.name];
|
8
|
+
if (field.localized && typeof rowData === 'object' && rowData !== null) {
|
9
|
+
Object.entries(rowData).forEach(([locale, localeRows])=>{
|
10
|
+
if (Array.isArray(localeRows)) {
|
11
|
+
localeRows.forEach((row, i)=>{
|
12
|
+
return traverseFields({
|
13
|
+
doc: row,
|
14
|
+
fields: field.fields,
|
15
|
+
locale,
|
16
|
+
path: `${path ? `${path}.` : ''}${field.name}.${i}`,
|
17
|
+
rows
|
18
|
+
});
|
19
|
+
});
|
20
|
+
}
|
21
|
+
});
|
22
|
+
}
|
23
|
+
if (Array.isArray(rowData)) {
|
24
|
+
rowData.forEach((row, i)=>{
|
25
|
+
return traverseFields({
|
26
|
+
doc: row,
|
27
|
+
fields: field.fields,
|
28
|
+
path: `${path ? `${path}.` : ''}${field.name}.${i}`,
|
29
|
+
rows
|
30
|
+
});
|
31
|
+
});
|
32
|
+
}
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
case 'blocks':
|
36
|
+
{
|
37
|
+
const rowData = doc?.[field.name];
|
38
|
+
if (field.localized && typeof rowData === 'object' && rowData !== null) {
|
39
|
+
Object.entries(rowData).forEach(([locale, localeRows])=>{
|
40
|
+
if (Array.isArray(localeRows)) {
|
41
|
+
localeRows.forEach((row, i)=>{
|
42
|
+
const matchedBlock = field.blocks.find((block)=>block.slug === row.blockType);
|
43
|
+
if (matchedBlock) {
|
44
|
+
return traverseFields({
|
45
|
+
doc: row,
|
46
|
+
fields: matchedBlock.fields,
|
47
|
+
locale,
|
48
|
+
path: `${path ? `${path}.` : ''}${field.name}.${i}`,
|
49
|
+
rows
|
50
|
+
});
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
});
|
55
|
+
}
|
56
|
+
if (Array.isArray(rowData)) {
|
57
|
+
rowData.forEach((row, i)=>{
|
58
|
+
const matchedBlock = field.blocks.find((block)=>block.slug === row.blockType);
|
59
|
+
if (matchedBlock) {
|
60
|
+
return traverseFields({
|
61
|
+
doc: row,
|
62
|
+
fields: matchedBlock.fields,
|
63
|
+
path: `${path ? `${path}.` : ''}${field.name}.${i}`,
|
64
|
+
rows
|
65
|
+
});
|
66
|
+
}
|
67
|
+
});
|
68
|
+
}
|
69
|
+
break;
|
70
|
+
}
|
71
|
+
case 'collapsible':
|
72
|
+
// falls through
|
73
|
+
case 'row':
|
74
|
+
{
|
75
|
+
return traverseFields({
|
76
|
+
doc,
|
77
|
+
fields: field.fields,
|
78
|
+
path,
|
79
|
+
rows
|
80
|
+
});
|
81
|
+
}
|
82
|
+
case 'group':
|
83
|
+
{
|
84
|
+
const newPath = `${path ? `${path}.` : ''}${field.name}`;
|
85
|
+
const newDoc = doc?.[field.name];
|
86
|
+
if (typeof newDoc === 'object' && newDoc !== null) {
|
87
|
+
if (field.localized) {
|
88
|
+
Object.entries(newDoc).forEach(([locale, localeDoc])=>{
|
89
|
+
return traverseFields({
|
90
|
+
doc: localeDoc,
|
91
|
+
fields: field.fields,
|
92
|
+
locale,
|
93
|
+
path: newPath,
|
94
|
+
rows
|
95
|
+
});
|
96
|
+
});
|
97
|
+
} else {
|
98
|
+
return traverseFields({
|
99
|
+
doc: newDoc,
|
100
|
+
fields: field.fields,
|
101
|
+
path: newPath,
|
102
|
+
rows
|
103
|
+
});
|
104
|
+
}
|
105
|
+
}
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
case 'relationship':
|
109
|
+
// falls through
|
110
|
+
case 'upload':
|
111
|
+
{
|
112
|
+
if (typeof field.relationTo === 'string') {
|
113
|
+
if (field.type === 'upload' || !field.hasMany) {
|
114
|
+
const relationshipPath = `${path ? `${path}.` : ''}${field.name}`;
|
115
|
+
if (field.localized) {
|
116
|
+
const matchedRelationshipsWithLocales = rows.filter((row)=>row.path === relationshipPath);
|
117
|
+
if (matchedRelationshipsWithLocales.length && !doc[field.name]) {
|
118
|
+
doc[field.name] = {};
|
119
|
+
}
|
120
|
+
const newDoc = doc[field.name];
|
121
|
+
matchedRelationshipsWithLocales.forEach((localeRow)=>{
|
122
|
+
if (typeof localeRow.locale === 'string') {
|
123
|
+
const [, id] = Object.entries(localeRow).find(([key, val])=>val !== null && ![
|
124
|
+
'id',
|
125
|
+
'locale',
|
126
|
+
'order',
|
127
|
+
'parent_id',
|
128
|
+
'path'
|
129
|
+
].includes(key));
|
130
|
+
newDoc[localeRow.locale] = id;
|
131
|
+
}
|
132
|
+
});
|
133
|
+
} else {
|
134
|
+
const matchedRelationship = rows.find((row)=>{
|
135
|
+
const matchesPath = row.path === relationshipPath;
|
136
|
+
if (locale) {
|
137
|
+
return matchesPath && locale === row.locale;
|
138
|
+
}
|
139
|
+
return row.path === relationshipPath;
|
140
|
+
});
|
141
|
+
if (matchedRelationship) {
|
142
|
+
const [, id] = Object.entries(matchedRelationship).find(([key, val])=>val !== null && ![
|
143
|
+
'id',
|
144
|
+
'locale',
|
145
|
+
'order',
|
146
|
+
'parent_id',
|
147
|
+
'path'
|
148
|
+
].includes(key));
|
149
|
+
doc[field.name] = id;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
case 'tabs':
|
157
|
+
{
|
158
|
+
return field.tabs.forEach((tab)=>{
|
159
|
+
if (tabHasName(tab)) {
|
160
|
+
const newDoc = doc?.[tab.name];
|
161
|
+
const newPath = `${path ? `${path}.` : ''}${tab.name}`;
|
162
|
+
if (typeof newDoc === 'object' && newDoc !== null) {
|
163
|
+
if (tab.localized) {
|
164
|
+
Object.entries(newDoc).forEach(([locale, localeDoc])=>{
|
165
|
+
return traverseFields({
|
166
|
+
doc: localeDoc,
|
167
|
+
fields: tab.fields,
|
168
|
+
locale,
|
169
|
+
path: newPath,
|
170
|
+
rows
|
171
|
+
});
|
172
|
+
});
|
173
|
+
} else {
|
174
|
+
return traverseFields({
|
175
|
+
doc: newDoc,
|
176
|
+
fields: tab.fields,
|
177
|
+
path: newPath,
|
178
|
+
rows
|
179
|
+
});
|
180
|
+
}
|
181
|
+
}
|
182
|
+
} else {
|
183
|
+
traverseFields({
|
184
|
+
doc,
|
185
|
+
fields: tab.fields,
|
186
|
+
path,
|
187
|
+
rows
|
188
|
+
});
|
189
|
+
}
|
190
|
+
});
|
191
|
+
}
|
192
|
+
}
|
193
|
+
});
|
194
|
+
};
|
195
|
+
|
196
|
+
//# sourceMappingURL=traverseFields.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../../src/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { tabHasName } from 'payload/shared'\n\ntype Args = {\n doc: Record<string, unknown>\n fields: Field[]\n locale?: string\n path: string\n rows: Record<string, unknown>[]\n}\n\nexport const traverseFields = ({ doc, fields, locale, path, rows }: Args) => {\n fields.forEach((field) => {\n switch (field.type) {\n case 'array': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: field.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n })\n }\n\n break\n }\n\n case 'blocks': {\n const rowData = doc?.[field.name]\n\n if (field.localized && typeof rowData === 'object' && rowData !== null) {\n Object.entries(rowData).forEach(([locale, localeRows]) => {\n if (Array.isArray(localeRows)) {\n localeRows.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n locale,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n })\n }\n\n if (Array.isArray(rowData)) {\n rowData.forEach((row, i) => {\n const matchedBlock = field.blocks.find((block) => block.slug === row.blockType)\n\n if (matchedBlock) {\n return traverseFields({\n doc: row as Record<string, unknown>,\n fields: matchedBlock.fields,\n path: `${path ? `${path}.` : ''}${field.name}.${i}`,\n rows,\n })\n }\n })\n }\n\n break\n }\n case 'collapsible':\n // falls through\n case 'row': {\n return traverseFields({\n doc,\n fields: field.fields,\n path,\n rows,\n })\n }\n\n case 'group': {\n const newPath = `${path ? `${path}.` : ''}${field.name}`\n const newDoc = doc?.[field.name]\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (field.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: field.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: field.fields,\n path: newPath,\n rows,\n })\n }\n }\n\n break\n }\n\n case 'relationship':\n // falls through\n case 'upload': {\n if (typeof field.relationTo === 'string') {\n if (field.type === 'upload' || !field.hasMany) {\n const relationshipPath = `${path ? `${path}.` : ''}${field.name}`\n\n if (field.localized) {\n const matchedRelationshipsWithLocales = rows.filter(\n (row) => row.path === relationshipPath,\n )\n\n if (matchedRelationshipsWithLocales.length && !doc[field.name]) {\n doc[field.name] = {}\n }\n\n const newDoc = doc[field.name] as Record<string, unknown>\n\n matchedRelationshipsWithLocales.forEach((localeRow) => {\n if (typeof localeRow.locale === 'string') {\n const [, id] = Object.entries(localeRow).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n newDoc[localeRow.locale] = id\n }\n })\n } else {\n const matchedRelationship = rows.find((row) => {\n const matchesPath = row.path === relationshipPath\n\n if (locale) {\n return matchesPath && locale === row.locale\n }\n\n return row.path === relationshipPath\n })\n\n if (matchedRelationship) {\n const [, id] = Object.entries(matchedRelationship).find(\n ([key, val]) =>\n val !== null && !['id', 'locale', 'order', 'parent_id', 'path'].includes(key),\n )\n\n doc[field.name] = id\n }\n }\n }\n }\n break\n }\n case 'tabs': {\n return field.tabs.forEach((tab) => {\n if (tabHasName(tab)) {\n const newDoc = doc?.[tab.name]\n const newPath = `${path ? `${path}.` : ''}${tab.name}`\n\n if (typeof newDoc === 'object' && newDoc !== null) {\n if (tab.localized) {\n Object.entries(newDoc).forEach(([locale, localeDoc]) => {\n return traverseFields({\n doc: localeDoc,\n fields: tab.fields,\n locale,\n path: newPath,\n rows,\n })\n })\n } else {\n return traverseFields({\n doc: newDoc as Record<string, unknown>,\n fields: tab.fields,\n path: newPath,\n rows,\n })\n }\n }\n } else {\n traverseFields({\n doc,\n fields: tab.fields,\n path,\n rows,\n })\n }\n })\n }\n }\n })\n}\n"],"names":["tabHasName","traverseFields","doc","fields","locale","path","rows","forEach","field","type","rowData","name","localized","Object","entries","localeRows","Array","isArray","row","i","matchedBlock","blocks","find","block","slug","blockType","newPath","newDoc","localeDoc","relationTo","hasMany","relationshipPath","matchedRelationshipsWithLocales","filter","length","localeRow","id","key","val","includes","matchedRelationship","matchesPath","tabs","tab"],"mappings":"AAEA,SAASA,UAAU,QAAQ,iBAAgB;AAU3C,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAQ;IACtEH,OAAOI,OAAO,CAAC,CAACC;QACd,OAAQA,MAAMC,IAAI;YAChB,KAAK;gBAAS;oBACZ,MAAMC,UAA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@@
|
|
1
|
+
{"version":3,"file":"groupUpSQLStatements.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/groupUpSQLStatements.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GACd,WAAW,GACX,eAAe,GACf,YAAY,GACZ,gBAAgB,GAChB,WAAW,GACX,SAAS,CAAA;AAgBb,eAAO,MAAM,oBAAoB,SAAU,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAmD5E,CAAA"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/**
|
2
|
+
* Convert an "ADD COLUMN" statement to an "ALTER COLUMN" statement
|
3
|
+
* example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
|
4
|
+
* to: ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
|
5
|
+
* @param sql
|
6
|
+
*/ function convertAddColumnToAlterColumn(sql) {
|
7
|
+
// Regular expression to match the ADD COLUMN statement with its constraints
|
8
|
+
const regex = /ALTER TABLE ("[^"]+") ADD COLUMN ("[^"]+") [\w\s]+ NOT NULL;/;
|
9
|
+
// Replace the matched part with "ALTER COLUMN ... SET NOT NULL;"
|
10
|
+
return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;');
|
11
|
+
}
|
12
|
+
export const groupUpSQLStatements = (list)=>{
|
13
|
+
const groups = {
|
14
|
+
addColumn: 'ADD COLUMN',
|
15
|
+
// example: ALTER TABLE "posts" ADD COLUMN "category_id" integer
|
16
|
+
addConstraint: 'ADD CONSTRAINT',
|
17
|
+
//example:
|
18
|
+
// DO $$ BEGIN
|
19
|
+
// ALTER TABLE "pages_blocks_my_block" ADD CONSTRAINT "pages_blocks_my_block_person_id_users_id_fk" FOREIGN KEY ("person_id") REFERENCES "users"("id") ON DELETE cascade ON UPDATE no action;
|
20
|
+
// EXCEPTION
|
21
|
+
// WHEN duplicate_object THEN null;
|
22
|
+
// END $$;
|
23
|
+
dropColumn: 'DROP COLUMN',
|
24
|
+
// example: ALTER TABLE "_posts_v_rels" DROP COLUMN IF EXISTS "posts_id";
|
25
|
+
dropConstraint: 'DROP CONSTRAINT',
|
26
|
+
// example: ALTER TABLE "_posts_v_rels" DROP CONSTRAINT "_posts_v_rels_posts_fk";
|
27
|
+
dropTable: 'DROP TABLE',
|
28
|
+
// example: DROP TABLE "pages_rels";
|
29
|
+
notNull: 'NOT NULL'
|
30
|
+
};
|
31
|
+
const result = Object.keys(groups).reduce((result, group)=>{
|
32
|
+
result[group] = [];
|
33
|
+
return result;
|
34
|
+
}, {});
|
35
|
+
for (const line of list){
|
36
|
+
Object.entries(groups).some(([key, value])=>{
|
37
|
+
if (line.endsWith('NOT NULL;')) {
|
38
|
+
// split up the ADD COLUMN and ALTER COLUMN NOT NULL statements
|
39
|
+
// example: ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer NOT NULL;
|
40
|
+
// becomes two separate statements:
|
41
|
+
// 1. ALTER TABLE "pages_blocks_my_block" ADD COLUMN "person_id" integer;
|
42
|
+
// 2. ALTER TABLE "pages_blocks_my_block" ALTER COLUMN "person_id" SET NOT NULL;
|
43
|
+
result.addColumn.push(line.replace(' NOT NULL;', ';'));
|
44
|
+
result.notNull.push(convertAddColumnToAlterColumn(line));
|
45
|
+
return true;
|
46
|
+
}
|
47
|
+
if (line.includes(value)) {
|
48
|
+
result[key].push(line);
|
49
|
+
return true;
|
50
|
+
}
|
51
|
+
});
|
52
|
+
}
|
53
|
+
return result;
|
54
|
+
};
|
55
|
+
|
56
|
+
//# sourceMappingURL=groupUpSQLStatements.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/predefinedMigrations/v2-v3/groupUpSQLStatements.ts"],"sourcesContent":["export type Groups =\n | 'addColumn'\n | 'addConstraint'\n | 'dropColumn'\n | 'dropConstraint'\n | 'dropTable'\n | 'notNull'\n\n/**\n * Convert an \"ADD COLUMN\" statement to an \"ALTER COLUMN\" statement\n * example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n * to: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n * @param sql\n */\nfunction convertAddColumnToAlterColumn(sql) {\n // Regular expression to match the ADD COLUMN statement with its constraints\n const regex = /ALTER TABLE (\"[^\"]+\") ADD COLUMN (\"[^\"]+\") [\\w\\s]+ NOT NULL;/\n\n // Replace the matched part with \"ALTER COLUMN ... SET NOT NULL;\"\n return sql.replace(regex, 'ALTER TABLE $1 ALTER COLUMN $2 SET NOT NULL;')\n}\n\nexport const groupUpSQLStatements = (list: string[]): Record<Groups, string[]> => {\n const groups = {\n addColumn: 'ADD COLUMN',\n // example: ALTER TABLE \"posts\" ADD COLUMN \"category_id\" integer\n\n addConstraint: 'ADD CONSTRAINT',\n //example:\n // DO $$ BEGIN\n // ALTER TABLE \"pages_blocks_my_block\" ADD CONSTRAINT \"pages_blocks_my_block_person_id_users_id_fk\" FOREIGN KEY (\"person_id\") REFERENCES \"users\"(\"id\") ON DELETE cascade ON UPDATE no action;\n // EXCEPTION\n // WHEN duplicate_object THEN null;\n // END $$;\n\n dropColumn: 'DROP COLUMN',\n // example: ALTER TABLE \"_posts_v_rels\" DROP COLUMN IF EXISTS \"posts_id\";\n\n dropConstraint: 'DROP CONSTRAINT',\n // example: ALTER TABLE \"_posts_v_rels\" DROP CONSTRAINT \"_posts_v_rels_posts_fk\";\n\n dropTable: 'DROP TABLE',\n // example: DROP TABLE \"pages_rels\";\n\n notNull: 'NOT NULL',\n // example: ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n }\n\n const result = Object.keys(groups).reduce((result, group: Groups) => {\n result[group] = []\n return result\n }, {}) as Record<Groups, string[]>\n\n for (const line of list) {\n Object.entries(groups).some(([key, value]) => {\n if (line.endsWith('NOT NULL;')) {\n // split up the ADD COLUMN and ALTER COLUMN NOT NULL statements\n // example: ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer NOT NULL;\n // becomes two separate statements:\n // 1. ALTER TABLE \"pages_blocks_my_block\" ADD COLUMN \"person_id\" integer;\n // 2. ALTER TABLE \"pages_blocks_my_block\" ALTER COLUMN \"person_id\" SET NOT NULL;\n result.addColumn.push(line.replace(' NOT NULL;', ';'))\n result.notNull.push(convertAddColumnToAlterColumn(line))\n return true\n }\n if (line.includes(value)) {\n result[key].push(line)\n return true\n }\n })\n }\n\n return result\n}\n"],"names":["convertAddColumnToAlterColumn","sql","regex","replace","groupUpSQLStatements","list","groups","addColumn","addConstraint","dropColumn","dropConstraint","dropTable","notNull","result","Object","keys","reduce","group","line","entries","some","key","value","endsWith","push","includes"],"mappings":"AAQA;;;;;CAKC,GACD,SAASA,8BAA8BC,GAAG;IACxC,4EAA4E;IAC5E,MAAMC,QAAQ;IAEd,iEAAiE;IACjE,OAAOD,IAAIE,OAAO,CAACD,OAAO;AAC5B;AAEA,OAAO,MAAME,uBAAuB,CAACC;IACnC,MAAMC,SAAS;QACbC,WAAW;QACX,gEAAgE;QAEhEC,eAAe;QACf,UAAU;QACV,cAAc;QACd,8LAA8L;QAC9L,YAAY;QACZ,oCAAoC;QACpC,UAAU;QAEVC,YAAY;QACZ,yEAAyE;QAEzEC,gBAAgB;QAChB,iFAAiF;QAEjFC,WAAW;QACX,oCAAoC;QAEpCC,SAAS;IAEX;IAEA,MAAMC,SAASC,OAAOC,IAAI,CAACT,QAAQU,MAAM,CAAC,CAACH,QAAQI;QACjDJ,MAAM,CAACI,MAAM,GAAG,EAAE;QAClB,OAAOJ;IACT,GAAG,CAAC;IAEJ,KAAK,MAAMK,QAAQb,KAAM;QACvBS,OAAOK,OAAO,CAACb,QAAQc,IAAI,CAAC,CAAC,CAACC,KAAKC,MAAM;YACvC,IAAIJ,KAAKK,QAAQ,CAAC,cAAc;gBAC9B,+DAA+D;gBAC/D,wFAAwF;gBACxF,mCAAmC;gBACnC,0EAA0E;gBAC1E,kFAAkF;gBAClFV,OAAON,SAAS,CAACiB,IAAI,CAACN,KAAKf,OAAO,CAAC,cAAc;gBACjDU,OAAOD,OAAO,CAACY,IAAI,CAACxB,8BAA8BkB;gBAClD,OAAO;YACT;YACA,IAAIA,KAAKO,QAAQ,CAACH,QAAQ;gBACxBT,MAAM,CAACQ,IAAI,CAACG,IAAI,CAACN;gBACjB,OAAO;YACT;QACF;IACF;IAEA,OAAOL;AACT,EAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { Payload, PayloadRequest } from 'payload';
|
2
|
+
type Args = {
|
3
|
+
debug?: boolean;
|
4
|
+
payload: Payload;
|
5
|
+
req?: Partial<PayloadRequest>;
|
6
|
+
};
|
7
|
+
/**
|
8
|
+
* Moves upload and relationship columns from the join table and into the tables while moving data
|
9
|
+
* This is done in the following order:
|
10
|
+
* ADD COLUMNs
|
11
|
+
* -- manipulate data to move relationships to new columns
|
12
|
+
* ADD CONSTRAINTs
|
13
|
+
* NOT NULLs
|
14
|
+
* DROP TABLEs
|
15
|
+
* DROP CONSTRAINTs
|
16
|
+
* DROP COLUMNs
|
17
|
+
* @param debug
|
18
|
+
* @param payload
|
19
|
+
* @param req
|
20
|
+
*/
|
21
|
+
export declare const migratePostgresV2toV3: ({ debug, payload, req }: Args) => Promise<void>;
|
22
|
+
export {};
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/predefinedMigrations/v2-v3/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAiBtD,KAAK,IAAI,GAAG;IACV,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;CAC9B,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,4BAAmC,IAAI,kBA8OxE,CAAA"}
|