@payloadcms/db-postgres 3.0.0-beta.7 → 3.0.0-beta.71
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 +16 -13
- package/dist/connect.js.map +1 -1
- package/dist/countDistinct.d.ts +3 -0
- package/dist/countDistinct.d.ts.map +1 -0
- package/dist/countDistinct.js +24 -0
- package/dist/countDistinct.js.map +1 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
- package/dist/createJSONQuery/formatJSONPathSegment.js.map +1 -0
- package/dist/createJSONQuery/index.d.ts.map +1 -0
- package/dist/createJSONQuery/index.js.map +1 -0
- package/dist/createMigration.d.ts +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +56 -57
- package/dist/createMigration.js.map +1 -1
- package/dist/defaultSnapshot.d.ts +3 -0
- package/dist/defaultSnapshot.d.ts.map +1 -0
- package/dist/defaultSnapshot.js +16 -0
- package/dist/defaultSnapshot.js.map +1 -0
- package/dist/deleteWhere.d.ts +3 -0
- package/dist/deleteWhere.d.ts.map +1 -0
- package/dist/deleteWhere.js +6 -0
- package/dist/deleteWhere.js.map +1 -0
- package/dist/dropDatabase.d.ts +3 -0
- package/dist/dropDatabase.d.ts.map +1 -0
- package/dist/dropDatabase.js +9 -0
- package/dist/dropDatabase.js.map +1 -0
- package/dist/execute.d.ts +3 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +11 -0
- package/dist/execute.js.map +1 -0
- 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/getMigrationTemplate.d.ts +3 -0
- package/dist/getMigrationTemplate.d.ts.map +1 -0
- package/dist/getMigrationTemplate.js +12 -0
- package/dist/getMigrationTemplate.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -71
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +21 -24
- package/dist/init.js.map +1 -1
- package/dist/insert.d.ts +3 -0
- package/dist/insert.d.ts.map +1 -0
- package/dist/insert.js +12 -0
- package/dist/insert.js.map +1 -0
- 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 +191 -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 +57 -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/requireDrizzleKit.d.ts +3 -0
- package/dist/requireDrizzleKit.d.ts.map +1 -0
- package/dist/requireDrizzleKit.js +5 -0
- package/dist/requireDrizzleKit.js.map +1 -0
- package/dist/schema/build.d.ts +12 -7
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +209 -125
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/createIndex.js.map +1 -1
- package/dist/schema/idToUUID.d.ts +1 -1
- package/dist/schema/idToUUID.d.ts.map +1 -1
- package/dist/schema/idToUUID.js.map +1 -1
- package/dist/schema/parentIDColumnMap.js.map +1 -1
- package/dist/schema/setColumnID.d.ts +1 -1
- package/dist/schema/setColumnID.d.ts.map +1 -1
- package/dist/schema/setColumnID.js +2 -2
- package/dist/schema/setColumnID.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +5 -7
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +148 -66
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/types.d.ts +77 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +35 -30
- package/dist/create.d.ts +0 -3
- package/dist/create.d.ts.map +0 -1
- package/dist/create.js +0 -21
- 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 -21
- 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 -37
- package/dist/createGlobalVersion.js.map +0 -1
- package/dist/createVersion.d.ts +0 -5
- package/dist/createVersion.d.ts.map +0 -1
- package/dist/createVersion.js +0 -48
- 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 -31
- 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 -62
- 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 -35
- 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 -154
- 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 -24
- 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 -26
- 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 -28
- 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 -24
- 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 -28
- package/dist/findVersions.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.map +0 -1
- package/dist/queries/createJSONQuery/convertPathToJSONTraversal.js.map +0 -1
- package/dist/queries/createJSONQuery/formatJSONPathSegment.d.ts.map +0 -1
- package/dist/queries/createJSONQuery/formatJSONPathSegment.js.map +0 -1
- package/dist/queries/createJSONQuery/index.d.ts.map +0 -1
- 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 -412
- 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 -45
- package/dist/queryDrafts.js.map +0 -1
- package/dist/schema/getTableName.d.ts +0 -32
- package/dist/schema/getTableName.d.ts.map +0 -1
- package/dist/schema/getTableName.js +0 -31
- package/dist/schema/getTableName.js.map +0 -1
- package/dist/schema/validateExistingBlockIsIdentical.d.ts +0 -11
- package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +0 -1
- package/dist/schema/validateExistingBlockIsIdentical.js +0 -70
- 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 -58
- 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 -28
- 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 -40
- 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 -40
- 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 -276
- 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
- package/src/index.ts +0 -156
- /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.d.ts +0 -0
- /package/dist/{queries/createJSONQuery → createJSONQuery}/convertPathToJSONTraversal.js +0 -0
- /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.d.ts +0 -0
- /package/dist/{queries/createJSONQuery → createJSONQuery}/formatJSONPathSegment.js +0 -0
- /package/dist/{queries/createJSONQuery → createJSONQuery}/index.d.ts +0 -0
- /package/dist/{queries/createJSONQuery → createJSONQuery}/index.js +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
import { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core';
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { flattenTopLevelFields } from 'payload';
|
3
|
+
import { fieldAffectsData } from 'payload/shared';
|
4
4
|
export const setColumnID = ({ adapter, columns, fields })=>{
|
5
5
|
const idField = flattenTopLevelFields(fields).find((field)=>fieldAffectsData(field) && field.name === 'id');
|
6
6
|
if (idField) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/schema/setColumnID.ts"],"sourcesContent":["import type { PgColumnBuilder } from 'drizzle-orm/pg-core'\n\nimport { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core'\nimport { type Field,
|
1
|
+
{"version":3,"sources":["../../src/schema/setColumnID.ts"],"sourcesContent":["import type { PgColumnBuilder } from 'drizzle-orm/pg-core'\n\nimport { numeric, serial, uuid, varchar } from 'drizzle-orm/pg-core'\nimport { type Field, flattenTopLevelFields } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { IDType, PostgresAdapter } from '../types.js'\n\ntype Args = { adapter: PostgresAdapter; columns: Record<string, PgColumnBuilder>; fields: Field[] }\nexport const setColumnID = ({ adapter, columns, fields }: Args): IDType => {\n const idField = flattenTopLevelFields(fields).find(\n (field) => fieldAffectsData(field) && field.name === 'id',\n )\n if (idField) {\n if (idField.type === 'number') {\n columns.id = numeric('id').primaryKey()\n return 'numeric'\n }\n\n if (idField.type === 'text') {\n columns.id = varchar('id').primaryKey()\n return 'varchar'\n }\n }\n\n if (adapter.idType === 'uuid') {\n columns.id = uuid('id').defaultRandom().primaryKey()\n return 'uuid'\n }\n\n columns.id = serial('id').primaryKey()\n return 'integer'\n}\n"],"names":["numeric","serial","uuid","varchar","flattenTopLevelFields","fieldAffectsData","setColumnID","adapter","columns","fields","idField","find","field","name","type","id","primaryKey","idType","defaultRandom"],"mappings":"AAEA,SAASA,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,QAAQ,sBAAqB;AACpE,SAAqBC,qBAAqB,QAAQ,UAAS;AAC3D,SAASC,gBAAgB,QAAQ,iBAAgB;AAKjD,OAAO,MAAMC,cAAc,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,MAAM,EAAQ;IAC5D,MAAMC,UAAUN,sBAAsBK,QAAQE,IAAI,CAChD,CAACC,QAAUP,iBAAiBO,UAAUA,MAAMC,IAAI,KAAK;IAEvD,IAAIH,SAAS;QACX,IAAIA,QAAQI,IAAI,KAAK,UAAU;YAC7BN,QAAQO,EAAE,GAAGf,QAAQ,MAAMgB,UAAU;YACrC,OAAO;QACT;QAEA,IAAIN,QAAQI,IAAI,KAAK,QAAQ;YAC3BN,QAAQO,EAAE,GAAGZ,QAAQ,MAAMa,UAAU;YACrC,OAAO;QACT;IACF;IAEA,IAAIT,QAAQU,MAAM,KAAK,QAAQ;QAC7BT,QAAQO,EAAE,GAAGb,KAAK,MAAMgB,aAAa,GAAGF,UAAU;QAClD,OAAO;IACT;IAEAR,QAAQO,EAAE,GAAGd,OAAO,MAAMe,UAAU;IACpC,OAAO;AACT,EAAC"}
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import type { IndexBuilder, PgColumnBuilder } from 'drizzle-orm/pg-core';
|
2
|
-
import type { Field, TabAsField } from 'payload
|
2
|
+
import type { Field, TabAsField } from 'payload';
|
3
3
|
import type { GenericColumns, PostgresAdapter } from '../types.js';
|
4
|
+
import type { RelationMap } from './build.js';
|
4
5
|
type Args = {
|
5
6
|
adapter: PostgresAdapter;
|
6
|
-
buildNumbers: boolean;
|
7
|
-
buildRelationships: boolean;
|
8
|
-
buildTexts: boolean;
|
9
7
|
columnPrefix?: string;
|
10
8
|
columns: Record<string, PgColumnBuilder>;
|
11
9
|
disableNotNull: boolean;
|
@@ -18,9 +16,9 @@ type Args = {
|
|
18
16
|
localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>;
|
19
17
|
newTableName: string;
|
20
18
|
parentTableName: string;
|
21
|
-
relationsToBuild:
|
19
|
+
relationsToBuild: RelationMap;
|
22
20
|
relationships: Set<string>;
|
23
|
-
rootRelationsToBuild?:
|
21
|
+
rootRelationsToBuild?: RelationMap;
|
24
22
|
rootTableIDColType: string;
|
25
23
|
rootTableName: string;
|
26
24
|
versions: boolean;
|
@@ -33,6 +31,6 @@ type Result = {
|
|
33
31
|
hasManyNumberField: 'index' | boolean;
|
34
32
|
hasManyTextField: 'index' | boolean;
|
35
33
|
};
|
36
|
-
export declare const traverseFields: ({ adapter,
|
34
|
+
export declare const traverseFields: ({ adapter, columnPrefix, columns, disableNotNull, disableUnique, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions, }: Args) => Result;
|
37
35
|
export {};
|
38
36
|
//# sourceMappingURL=traverseFields.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../src/schema/traverseFields.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AA2BhD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAA;AAO9D,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IACxC,cAAc,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IAC/D,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;IAC/C,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,YAAY,CAAC,CAAA;IACtE,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,WAAW,CAAA;IAC7B,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC1B,oBAAoB,CAAC,EAAE,WAAW,CAAA;IAClC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,OAAO,CAAA;IAC1B,2BAA2B,EAAE,OAAO,CAAA;IACpC,yBAAyB,EAAE,OAAO,CAAA;IAClC,6BAA6B,EAAE,OAAO,CAAA;IACtC,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAAA;IACrC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,cAAc,wRAoBxB,IAAI,KAAG,MA4rBT,CAAA"}
|
@@ -1,16 +1,14 @@
|
|
1
|
-
/* eslint-disable no-param-reassign */ import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
1
|
+
/* eslint-disable no-param-reassign */ import { createTableName, hasLocalesTable, validateExistingBlockIsIdentical } from '@payloadcms/drizzle';
|
2
|
+
import { relations } from 'drizzle-orm';
|
3
|
+
import { PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, boolean, foreignKey, index, integer, jsonb, numeric, pgEnum, text, timestamp, varchar } from 'drizzle-orm/pg-core';
|
4
|
+
import { InvalidConfiguration } from 'payload';
|
5
|
+
import { fieldAffectsData, optionIsObject } from 'payload/shared';
|
5
6
|
import toSnakeCase from 'to-snake-case';
|
6
|
-
import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
|
7
7
|
import { buildTable } from './build.js';
|
8
8
|
import { createIndex } from './createIndex.js';
|
9
|
-
import { getTableName } from './getTableName.js';
|
10
9
|
import { idToUUID } from './idToUUID.js';
|
11
10
|
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
12
|
-
|
13
|
-
export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buildTexts, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
|
11
|
+
export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
|
14
12
|
const throwValidationError = true;
|
15
13
|
let hasLocalizedField = false;
|
16
14
|
let hasLocalizedRelationshipField = false;
|
@@ -33,7 +31,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
33
31
|
fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
|
34
32
|
// If field is localized,
|
35
33
|
// add the column to the locale table instead of main table
|
36
|
-
if (adapter.payload.config.localization && (field.localized || forceLocalized)) {
|
34
|
+
if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
|
37
35
|
hasLocalizedField = true;
|
38
36
|
targetTable = localesColumns;
|
39
37
|
targetIndexes = localesIndexes;
|
@@ -130,14 +128,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
130
128
|
case 'radio':
|
131
129
|
case 'select':
|
132
130
|
{
|
133
|
-
const enumName =
|
131
|
+
const enumName = createTableName({
|
134
132
|
adapter,
|
135
133
|
config: field,
|
136
134
|
parentTableName: newTableName,
|
137
135
|
prefix: `enum_${newTableName}_`,
|
138
136
|
target: 'enumName',
|
139
|
-
throwValidationError
|
140
|
-
versions
|
137
|
+
throwValidationError
|
141
138
|
});
|
142
139
|
adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
|
143
140
|
if (optionIsObject(option)) {
|
@@ -146,23 +143,30 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
146
143
|
return option;
|
147
144
|
}));
|
148
145
|
if (field.type === 'select' && field.hasMany) {
|
149
|
-
const selectTableName =
|
146
|
+
const selectTableName = createTableName({
|
150
147
|
adapter,
|
151
148
|
config: field,
|
152
149
|
parentTableName: newTableName,
|
153
150
|
prefix: `${newTableName}_`,
|
154
151
|
throwValidationError,
|
155
|
-
versions
|
152
|
+
versionsCustomName: versions
|
156
153
|
});
|
157
154
|
const baseColumns = {
|
158
155
|
order: integer('order').notNull(),
|
159
|
-
parent: parentIDColumnMap[parentIDColType]('parent_id').
|
160
|
-
onDelete: 'cascade'
|
161
|
-
}).notNull(),
|
156
|
+
parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),
|
162
157
|
value: adapter.enums[enumName]('value')
|
163
158
|
};
|
164
159
|
const baseExtraConfig = {
|
165
160
|
orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
|
161
|
+
parentFk: (cols)=>foreignKey({
|
162
|
+
name: `${selectTableName}_parent_fk`,
|
163
|
+
columns: [
|
164
|
+
cols.parent
|
165
|
+
],
|
166
|
+
foreignColumns: [
|
167
|
+
adapter.tables[parentTableName].id
|
168
|
+
]
|
169
|
+
}).onDelete('cascade'),
|
166
170
|
parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
|
167
171
|
};
|
168
172
|
if (field.localized) {
|
@@ -179,24 +183,27 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
179
183
|
disableNotNull,
|
180
184
|
disableUnique,
|
181
185
|
fields: [],
|
186
|
+
rootTableName,
|
182
187
|
tableName: selectTableName,
|
183
188
|
versions
|
184
189
|
});
|
185
|
-
relationsToBuild.set(fieldName,
|
186
|
-
|
187
|
-
|
190
|
+
relationsToBuild.set(fieldName, {
|
191
|
+
type: 'many',
|
192
|
+
// selects have their own localized table, independent of the base table.
|
193
|
+
localized: false,
|
194
|
+
target: selectTableName
|
195
|
+
});
|
196
|
+
adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
|
188
197
|
parent: one(adapter.tables[parentTableName], {
|
189
198
|
fields: [
|
190
199
|
adapter.tables[selectTableName].parent
|
191
200
|
],
|
192
201
|
references: [
|
193
202
|
adapter.tables[parentTableName].id
|
194
|
-
]
|
203
|
+
],
|
204
|
+
relationName: fieldName
|
195
205
|
})
|
196
|
-
};
|
197
|
-
return result;
|
198
|
-
});
|
199
|
-
adapter.relations[`relation_${selectTableName}`] = selectTableRelations;
|
206
|
+
}));
|
200
207
|
} else {
|
201
208
|
targetTable[fieldName] = adapter.enums[enumName](fieldName);
|
202
209
|
}
|
@@ -210,21 +217,29 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
210
217
|
case 'array':
|
211
218
|
{
|
212
219
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
213
|
-
const arrayTableName =
|
220
|
+
const arrayTableName = createTableName({
|
214
221
|
adapter,
|
215
222
|
config: field,
|
216
223
|
parentTableName: newTableName,
|
217
224
|
prefix: `${newTableName}_`,
|
218
|
-
throwValidationError
|
225
|
+
throwValidationError,
|
226
|
+
versionsCustomName: versions
|
219
227
|
});
|
220
228
|
const baseColumns = {
|
221
229
|
_order: integer('_order').notNull(),
|
222
|
-
_parentID: parentIDColumnMap[parentIDColType]('_parent_id').
|
223
|
-
onDelete: 'cascade'
|
224
|
-
}).notNull()
|
230
|
+
_parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull()
|
225
231
|
};
|
226
232
|
const baseExtraConfig = {
|
227
233
|
_orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
|
234
|
+
_parentIDFk: (cols)=>foreignKey({
|
235
|
+
name: `${arrayTableName}_parent_id_fk`,
|
236
|
+
columns: [
|
237
|
+
cols['_parentID']
|
238
|
+
],
|
239
|
+
foreignColumns: [
|
240
|
+
adapter.tables[parentTableName].id
|
241
|
+
]
|
242
|
+
}).onDelete('cascade'),
|
228
243
|
_parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
|
229
244
|
};
|
230
245
|
if (field.localized && adapter.payload.config.localization) {
|
@@ -251,8 +266,13 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
251
266
|
if (subHasManyNumberField) {
|
252
267
|
if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
|
253
268
|
}
|
254
|
-
relationsToBuild.set(fieldName,
|
255
|
-
|
269
|
+
relationsToBuild.set(fieldName, {
|
270
|
+
type: 'many',
|
271
|
+
// arrays have their own localized table, independent of the base table.
|
272
|
+
localized: false,
|
273
|
+
target: arrayTableName
|
274
|
+
});
|
275
|
+
adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
|
256
276
|
const result = {
|
257
277
|
_parentID: one(adapter.tables[parentTableName], {
|
258
278
|
fields: [
|
@@ -260,42 +280,68 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
260
280
|
],
|
261
281
|
references: [
|
262
282
|
adapter.tables[parentTableName].id
|
263
|
-
]
|
283
|
+
],
|
284
|
+
relationName: fieldName
|
264
285
|
})
|
265
286
|
};
|
266
287
|
if (hasLocalesTable(field.fields)) {
|
267
|
-
result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`]
|
288
|
+
result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
|
289
|
+
relationName: '_locales'
|
290
|
+
});
|
268
291
|
}
|
269
|
-
subRelationsToBuild.forEach((
|
270
|
-
|
292
|
+
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
293
|
+
if (type === 'one') {
|
294
|
+
const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
|
295
|
+
result[key] = one(adapter.tables[target], {
|
296
|
+
fields: [
|
297
|
+
adapter.tables[arrayWithLocalized][key]
|
298
|
+
],
|
299
|
+
references: [
|
300
|
+
adapter.tables[target].id
|
301
|
+
],
|
302
|
+
relationName: key
|
303
|
+
});
|
304
|
+
}
|
305
|
+
if (type === 'many') {
|
306
|
+
result[key] = many(adapter.tables[target], {
|
307
|
+
relationName: key
|
308
|
+
});
|
309
|
+
}
|
271
310
|
});
|
272
311
|
return result;
|
273
312
|
});
|
274
|
-
adapter.relations[`relations_${arrayTableName}`] = arrayTableRelations;
|
275
313
|
break;
|
276
314
|
}
|
277
315
|
case 'blocks':
|
278
316
|
{
|
279
317
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
280
318
|
field.blocks.forEach((block)=>{
|
281
|
-
const blockTableName =
|
319
|
+
const blockTableName = createTableName({
|
282
320
|
adapter,
|
283
321
|
config: block,
|
284
322
|
parentTableName: rootTableName,
|
285
323
|
prefix: `${rootTableName}_blocks_`,
|
286
|
-
throwValidationError
|
324
|
+
throwValidationError,
|
325
|
+
versionsCustomName: versions
|
287
326
|
});
|
288
327
|
if (!adapter.tables[blockTableName]) {
|
289
328
|
const baseColumns = {
|
290
329
|
_order: integer('_order').notNull(),
|
291
|
-
_parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').
|
292
|
-
onDelete: 'cascade'
|
293
|
-
}).notNull(),
|
330
|
+
_parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),
|
294
331
|
_path: text('_path').notNull()
|
295
332
|
};
|
296
333
|
const baseExtraConfig = {
|
297
334
|
_orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
|
298
335
|
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
336
|
+
_parentIdFk: (cols)=>foreignKey({
|
337
|
+
name: `${blockTableName}_parent_id_fk`,
|
338
|
+
columns: [
|
339
|
+
cols._parentID
|
340
|
+
],
|
341
|
+
foreignColumns: [
|
342
|
+
adapter.tables[rootTableName].id
|
343
|
+
]
|
344
|
+
}).onDelete('cascade'),
|
299
345
|
_pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
|
300
346
|
};
|
301
347
|
if (field.localized && adapter.payload.config.localization) {
|
@@ -322,7 +368,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
322
368
|
if (subHasManyNumberField) {
|
323
369
|
if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
|
324
370
|
}
|
325
|
-
|
371
|
+
adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
|
326
372
|
const result = {
|
327
373
|
_parentID: one(adapter.tables[rootTableName], {
|
328
374
|
fields: [
|
@@ -330,28 +376,52 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
330
376
|
],
|
331
377
|
references: [
|
332
378
|
adapter.tables[rootTableName].id
|
333
|
-
]
|
379
|
+
],
|
380
|
+
relationName: `_blocks_${block.slug}`
|
334
381
|
})
|
335
382
|
};
|
336
383
|
if (hasLocalesTable(block.fields)) {
|
337
|
-
result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
|
384
|
+
result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
|
385
|
+
relationName: '_locales'
|
386
|
+
});
|
338
387
|
}
|
339
|
-
subRelationsToBuild.forEach((
|
340
|
-
|
388
|
+
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
389
|
+
if (type === 'one') {
|
390
|
+
const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
|
391
|
+
result[key] = one(adapter.tables[target], {
|
392
|
+
fields: [
|
393
|
+
adapter.tables[blockWithLocalized][key]
|
394
|
+
],
|
395
|
+
references: [
|
396
|
+
adapter.tables[target].id
|
397
|
+
],
|
398
|
+
relationName: key
|
399
|
+
});
|
400
|
+
}
|
401
|
+
if (type === 'many') {
|
402
|
+
result[key] = many(adapter.tables[target], {
|
403
|
+
relationName: key
|
404
|
+
});
|
405
|
+
}
|
341
406
|
});
|
342
407
|
return result;
|
343
408
|
});
|
344
|
-
adapter.relations[`relations_${blockTableName}`] = blockTableRelations;
|
345
409
|
} else if (process.env.NODE_ENV !== 'production' && !versions) {
|
346
410
|
validateExistingBlockIsIdentical({
|
347
411
|
block,
|
348
412
|
localized: field.localized,
|
349
413
|
rootTableName,
|
350
|
-
table: adapter.tables[blockTableName]
|
414
|
+
table: adapter.tables[blockTableName],
|
415
|
+
tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
|
351
416
|
});
|
352
417
|
}
|
353
|
-
|
354
|
-
rootRelationsToBuild.set(`_blocks_${block.slug}`,
|
418
|
+
// blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
|
419
|
+
rootRelationsToBuild.set(`_blocks_${block.slug}`, {
|
420
|
+
type: 'many',
|
421
|
+
// blocks are not localized on the parent table
|
422
|
+
localized: false,
|
423
|
+
target: blockTableName
|
424
|
+
});
|
355
425
|
});
|
356
426
|
break;
|
357
427
|
}
|
@@ -361,9 +431,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
361
431
|
if (!('name' in field)) {
|
362
432
|
const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
|
363
433
|
adapter,
|
364
|
-
buildNumbers,
|
365
|
-
buildRelationships,
|
366
|
-
buildTexts,
|
367
434
|
columnPrefix,
|
368
435
|
columns,
|
369
436
|
disableNotNull,
|
@@ -394,9 +461,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
394
461
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
395
462
|
const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
|
396
463
|
adapter,
|
397
|
-
buildNumbers,
|
398
|
-
buildRelationships,
|
399
|
-
buildTexts,
|
400
464
|
columnPrefix: `${columnName}_`,
|
401
465
|
columns,
|
402
466
|
disableNotNull: disableNotNullFromHere,
|
@@ -429,9 +493,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
429
493
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
430
494
|
const { hasLocalizedField: tabHasLocalizedField, hasLocalizedManyNumberField: tabHasLocalizedManyNumberField, hasLocalizedManyTextField: tabHasLocalizedManyTextField, hasLocalizedRelationshipField: tabHasLocalizedRelationshipField, hasManyNumberField: tabHasManyNumberField, hasManyTextField: tabHasManyTextField } = traverseFields({
|
431
495
|
adapter,
|
432
|
-
buildNumbers,
|
433
|
-
buildRelationships,
|
434
|
-
buildTexts,
|
435
496
|
columnPrefix,
|
436
497
|
columns,
|
437
498
|
disableNotNull: disableNotNullFromHere,
|
@@ -468,9 +529,6 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
468
529
|
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
469
530
|
const { hasLocalizedField: rowHasLocalizedField, hasLocalizedManyNumberField: rowHasLocalizedManyNumberField, hasLocalizedManyTextField: rowHasLocalizedManyTextField, hasLocalizedRelationshipField: rowHasLocalizedRelationshipField, hasManyNumberField: rowHasManyNumberField, hasManyTextField: rowHasManyTextField } = traverseFields({
|
470
531
|
adapter,
|
471
|
-
buildNumbers,
|
472
|
-
buildRelationships,
|
473
|
-
buildTexts,
|
474
532
|
columnPrefix,
|
475
533
|
columns,
|
476
534
|
disableNotNull: disableNotNullFromHere,
|
@@ -481,7 +539,7 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
481
539
|
indexes,
|
482
540
|
localesColumns,
|
483
541
|
localesIndexes,
|
484
|
-
newTableName
|
542
|
+
newTableName,
|
485
543
|
parentTableName,
|
486
544
|
relationsToBuild,
|
487
545
|
relationships,
|
@@ -502,10 +560,34 @@ export const traverseFields = ({ adapter, buildNumbers, buildRelationships, buil
|
|
502
560
|
case 'upload':
|
503
561
|
if (Array.isArray(field.relationTo)) {
|
504
562
|
field.relationTo.forEach((relation)=>relationships.add(relation));
|
505
|
-
} else {
|
563
|
+
} else if (field.type === 'relationship' && field.hasMany) {
|
506
564
|
relationships.add(field.relationTo);
|
565
|
+
} else {
|
566
|
+
// simple relationships get a column on the targetTable with a foreign key to the relationTo table
|
567
|
+
const relationshipConfig = adapter.payload.collections[field.relationTo].config;
|
568
|
+
const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
|
569
|
+
// get the id type of the related collection
|
570
|
+
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
571
|
+
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
572
|
+
if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
|
573
|
+
if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
|
574
|
+
// make the foreign key column for relationship using the correct id column type
|
575
|
+
targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
|
576
|
+
onDelete: 'set null'
|
577
|
+
});
|
578
|
+
// add relationship to table
|
579
|
+
relationsToBuild.set(fieldName, {
|
580
|
+
type: 'one',
|
581
|
+
localized: adapter.payload.config.localization && field.localized,
|
582
|
+
target: tableName
|
583
|
+
});
|
584
|
+
// add notNull when not required
|
585
|
+
if (!disableNotNull && field.required && !field.admin?.condition) {
|
586
|
+
targetTable[fieldName].notNull();
|
587
|
+
}
|
588
|
+
break;
|
507
589
|
}
|
508
|
-
if (
|
590
|
+
if (adapter.payload.config.localization && field.localized) {
|
509
591
|
hasLocalizedRelationshipField = true;
|
510
592
|
}
|
511
593
|
break;
|