@payloadcms/db-postgres 3.0.0-canary.f83d96a → 3.0.0-canary.fb04843
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/connect.d.ts.map +1 -1
- package/dist/connect.js +35 -12
- package/dist/connect.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -69
- package/dist/index.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +5 -4
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +72 -67
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/index.d.ts +2 -2
- package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/index.js +4 -4
- package/dist/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +5 -4
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +9 -3
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -1
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +3 -2
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
- package/dist/predefinedMigrations/v2-v3/traverseFields.js +32 -32
- package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -1
- package/dist/types.d.ts +65 -78
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/license.md +22 -0
- package/package.json +21 -12
- package/dist/count.d.ts +0 -3
- package/dist/count.d.ts.map +0 -1
- package/dist/count.js +0 -41
- 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 -4
- 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 -5
- 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 -102
- package/dist/createMigration.js.map +0 -1
- package/dist/createVersion.d.ts +0 -4
- package/dist/createVersion.d.ts.map +0 -1
- package/dist/createVersion.js +0 -40
- 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 -15
- package/dist/destroy.js.map +0 -1
- package/dist/find/buildFindManyArgs.d.ts +0 -17
- package/dist/find/buildFindManyArgs.d.ts.map +0 -1
- package/dist/find/buildFindManyArgs.js +0 -65
- 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 -21
- package/dist/find/findMany.d.ts.map +0 -1
- package/dist/find/findMany.js +0 -152
- package/dist/find/findMany.js.map +0 -1
- package/dist/find/traverseFields.d.ts +0 -17
- package/dist/find/traverseFields.d.ts.map +0 -1
- package/dist/find/traverseFields.js +0 -156
- 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 -4
- 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 -91
- 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 -16
- package/dist/queries/buildAndOrConditions.d.ts.map +0 -1
- package/dist/queries/buildAndOrConditions.js +0 -28
- package/dist/queries/buildAndOrConditions.js.map +0 -1
- package/dist/queries/buildQuery.d.ts +0 -30
- package/dist/queries/buildQuery.d.ts.map +0 -1
- package/dist/queries/buildQuery.js +0 -72
- 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 -50
- package/dist/queries/getTableColumnFromPath.d.ts.map +0 -1
- package/dist/queries/getTableColumnFromPath.js +0 -516
- 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 -16
- package/dist/queries/parseParams.d.ts.map +0 -1
- package/dist/queries/parseParams.js +0 -183
- 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 -89
- package/dist/queries/sanitizeQueryValue.js.map +0 -1
- package/dist/queries/selectDistinct.d.ts +0 -22
- package/dist/queries/selectDistinct.d.ts.map +0 -1
- package/dist/queries/selectDistinct.js +0 -30
- 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 -40
- package/dist/queryDrafts.js.map +0 -1
- package/dist/schema/build.d.ts +0 -34
- package/dist/schema/build.d.ts.map +0 -1
- package/dist/schema/build.js +0 -369
- 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 -36
- package/dist/schema/traverseFields.d.ts.map +0 -1
- package/dist/schema/traverseFields.js +0 -614
- 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 -51
- 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 -13
- package/dist/transform/read/index.d.ts.map +0 -1
- package/dist/transform/read/index.js +0 -44
- 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 -60
- package/dist/transform/read/relationship.js.map +0 -1
- package/dist/transform/read/traverseFields.d.ts +0 -57
- package/dist/transform/read/traverseFields.d.ts.map +0 -1
- package/dist/transform/read/traverseFields.js +0 -435
- 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 -445
- 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 -54
- package/dist/update.js.map +0 -1
- package/dist/updateGlobal.d.ts +0 -4
- 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 -4
- 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 -4
- 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 -281
- 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 -32
- 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
@@ -1 +0,0 @@
|
|
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,36 +0,0 @@
|
|
1
|
-
import type { IndexBuilder, PgColumnBuilder } from 'drizzle-orm/pg-core';
|
2
|
-
import type { Field, TabAsField } from 'payload';
|
3
|
-
import type { GenericColumns, PostgresAdapter } from '../types.js';
|
4
|
-
import type { RelationMap } from './build.js';
|
5
|
-
type Args = {
|
6
|
-
adapter: PostgresAdapter;
|
7
|
-
columnPrefix?: string;
|
8
|
-
columns: Record<string, PgColumnBuilder>;
|
9
|
-
disableNotNull: boolean;
|
10
|
-
disableUnique?: boolean;
|
11
|
-
fieldPrefix?: string;
|
12
|
-
fields: (Field | TabAsField)[];
|
13
|
-
forceLocalized?: boolean;
|
14
|
-
indexes: Record<string, (cols: GenericColumns) => IndexBuilder>;
|
15
|
-
localesColumns: Record<string, PgColumnBuilder>;
|
16
|
-
localesIndexes: Record<string, (cols: GenericColumns) => IndexBuilder>;
|
17
|
-
newTableName: string;
|
18
|
-
parentTableName: string;
|
19
|
-
relationsToBuild: RelationMap;
|
20
|
-
relationships: Set<string>;
|
21
|
-
rootRelationsToBuild?: RelationMap;
|
22
|
-
rootTableIDColType: string;
|
23
|
-
rootTableName: string;
|
24
|
-
versions: boolean;
|
25
|
-
};
|
26
|
-
type Result = {
|
27
|
-
hasLocalizedField: boolean;
|
28
|
-
hasLocalizedManyNumberField: boolean;
|
29
|
-
hasLocalizedManyTextField: boolean;
|
30
|
-
hasLocalizedRelationshipField: boolean;
|
31
|
-
hasManyNumberField: 'index' | boolean;
|
32
|
-
hasManyTextField: 'index' | boolean;
|
33
|
-
};
|
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;
|
35
|
-
export {};
|
36
|
-
//# sourceMappingURL=traverseFields.d.ts.map
|
@@ -1 +0,0 @@
|
|
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;AAsBhD,OAAO,KAAK,EAAE,cAAc,EAAU,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1E,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAA;AAU9D,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,614 +0,0 @@
|
|
1
|
-
/* eslint-disable no-param-reassign */ import { relations } from 'drizzle-orm';
|
2
|
-
import { PgNumericBuilder, PgUUIDBuilder, PgVarcharBuilder, boolean, foreignKey, index, integer, jsonb, numeric, pgEnum, text, timestamp, varchar } from 'drizzle-orm/pg-core';
|
3
|
-
import { InvalidConfiguration } from 'payload';
|
4
|
-
import { fieldAffectsData, optionIsObject } from 'payload/shared';
|
5
|
-
import toSnakeCase from 'to-snake-case';
|
6
|
-
import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
|
7
|
-
import { buildTable } from './build.js';
|
8
|
-
import { createIndex } from './createIndex.js';
|
9
|
-
import { createTableName } from './createTableName.js';
|
10
|
-
import { idToUUID } from './idToUUID.js';
|
11
|
-
import { parentIDColumnMap } from './parentIDColumnMap.js';
|
12
|
-
import { validateExistingBlockIsIdentical } from './validateExistingBlockIsIdentical.js';
|
13
|
-
export const traverseFields = ({ adapter, columnPrefix, columns, disableNotNull, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentTableName, relationsToBuild, relationships, rootRelationsToBuild, rootTableIDColType, rootTableName, versions })=>{
|
14
|
-
const throwValidationError = true;
|
15
|
-
let hasLocalizedField = false;
|
16
|
-
let hasLocalizedRelationshipField = false;
|
17
|
-
let hasManyTextField = false;
|
18
|
-
let hasLocalizedManyTextField = false;
|
19
|
-
let hasManyNumberField = false;
|
20
|
-
let hasLocalizedManyNumberField = false;
|
21
|
-
let parentIDColType = 'integer';
|
22
|
-
if (columns.id instanceof PgUUIDBuilder) parentIDColType = 'uuid';
|
23
|
-
if (columns.id instanceof PgNumericBuilder) parentIDColType = 'numeric';
|
24
|
-
if (columns.id instanceof PgVarcharBuilder) parentIDColType = 'varchar';
|
25
|
-
fields.forEach((field)=>{
|
26
|
-
if ('name' in field && field.name === 'id') return;
|
27
|
-
let columnName;
|
28
|
-
let fieldName;
|
29
|
-
let targetTable = columns;
|
30
|
-
let targetIndexes = indexes;
|
31
|
-
if (fieldAffectsData(field)) {
|
32
|
-
columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(field.name)}`;
|
33
|
-
fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
|
34
|
-
// If field is localized,
|
35
|
-
// add the column to the locale table instead of main table
|
36
|
-
if (adapter.payload.config.localization && (field.localized || forceLocalized) && field.type !== 'array' && field.type !== 'blocks' && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
|
37
|
-
hasLocalizedField = true;
|
38
|
-
targetTable = localesColumns;
|
39
|
-
targetIndexes = localesIndexes;
|
40
|
-
}
|
41
|
-
if ((field.unique || field.index) && ![
|
42
|
-
'array',
|
43
|
-
'blocks',
|
44
|
-
'group',
|
45
|
-
'point',
|
46
|
-
'relationship',
|
47
|
-
'upload'
|
48
|
-
].includes(field.type) && !('hasMany' in field && field.hasMany === true)) {
|
49
|
-
const unique = disableUnique !== true && field.unique;
|
50
|
-
if (unique) {
|
51
|
-
const constraintValue = `${fieldPrefix || ''}${field.name}`;
|
52
|
-
if (!adapter.fieldConstraints?.[rootTableName]) {
|
53
|
-
adapter.fieldConstraints[rootTableName] = {};
|
54
|
-
}
|
55
|
-
adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
|
56
|
-
}
|
57
|
-
targetIndexes[`${newTableName}_${field.name}Idx`] = createIndex({
|
58
|
-
name: fieldName,
|
59
|
-
columnName,
|
60
|
-
tableName: newTableName,
|
61
|
-
unique
|
62
|
-
});
|
63
|
-
}
|
64
|
-
}
|
65
|
-
switch(field.type){
|
66
|
-
case 'text':
|
67
|
-
{
|
68
|
-
if (field.hasMany) {
|
69
|
-
if (field.localized) {
|
70
|
-
hasLocalizedManyTextField = true;
|
71
|
-
}
|
72
|
-
if (field.index) {
|
73
|
-
hasManyTextField = 'index';
|
74
|
-
} else if (!hasManyTextField) {
|
75
|
-
hasManyTextField = true;
|
76
|
-
}
|
77
|
-
if (field.unique) {
|
78
|
-
throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany text fields.');
|
79
|
-
}
|
80
|
-
} else {
|
81
|
-
targetTable[fieldName] = varchar(columnName);
|
82
|
-
}
|
83
|
-
break;
|
84
|
-
}
|
85
|
-
case 'email':
|
86
|
-
case 'code':
|
87
|
-
case 'textarea':
|
88
|
-
{
|
89
|
-
targetTable[fieldName] = varchar(columnName);
|
90
|
-
break;
|
91
|
-
}
|
92
|
-
case 'number':
|
93
|
-
{
|
94
|
-
if (field.hasMany) {
|
95
|
-
if (field.localized) {
|
96
|
-
hasLocalizedManyNumberField = true;
|
97
|
-
}
|
98
|
-
if (field.index) {
|
99
|
-
hasManyNumberField = 'index';
|
100
|
-
} else if (!hasManyNumberField) {
|
101
|
-
hasManyNumberField = true;
|
102
|
-
}
|
103
|
-
if (field.unique) {
|
104
|
-
throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
|
105
|
-
}
|
106
|
-
} else {
|
107
|
-
targetTable[fieldName] = numeric(columnName);
|
108
|
-
}
|
109
|
-
break;
|
110
|
-
}
|
111
|
-
case 'richText':
|
112
|
-
case 'json':
|
113
|
-
{
|
114
|
-
targetTable[fieldName] = jsonb(columnName);
|
115
|
-
break;
|
116
|
-
}
|
117
|
-
case 'date':
|
118
|
-
{
|
119
|
-
targetTable[fieldName] = timestamp(columnName, {
|
120
|
-
mode: 'string',
|
121
|
-
precision: 3,
|
122
|
-
withTimezone: true
|
123
|
-
});
|
124
|
-
break;
|
125
|
-
}
|
126
|
-
case 'point':
|
127
|
-
{
|
128
|
-
break;
|
129
|
-
}
|
130
|
-
case 'radio':
|
131
|
-
case 'select':
|
132
|
-
{
|
133
|
-
const enumName = createTableName({
|
134
|
-
adapter,
|
135
|
-
config: field,
|
136
|
-
parentTableName: newTableName,
|
137
|
-
prefix: `enum_${newTableName}_`,
|
138
|
-
target: 'enumName',
|
139
|
-
throwValidationError
|
140
|
-
});
|
141
|
-
adapter.enums[enumName] = pgEnum(enumName, field.options.map((option)=>{
|
142
|
-
if (optionIsObject(option)) {
|
143
|
-
return option.value;
|
144
|
-
}
|
145
|
-
return option;
|
146
|
-
}));
|
147
|
-
if (field.type === 'select' && field.hasMany) {
|
148
|
-
const selectTableName = createTableName({
|
149
|
-
adapter,
|
150
|
-
config: field,
|
151
|
-
parentTableName: newTableName,
|
152
|
-
prefix: `${newTableName}_`,
|
153
|
-
throwValidationError,
|
154
|
-
versionsCustomName: versions
|
155
|
-
});
|
156
|
-
const baseColumns = {
|
157
|
-
order: integer('order').notNull(),
|
158
|
-
parent: parentIDColumnMap[parentIDColType]('parent_id').notNull(),
|
159
|
-
value: adapter.enums[enumName]('value')
|
160
|
-
};
|
161
|
-
const baseExtraConfig = {
|
162
|
-
orderIdx: (cols)=>index(`${selectTableName}_order_idx`).on(cols.order),
|
163
|
-
parentFk: (cols)=>foreignKey({
|
164
|
-
name: `${selectTableName}_parent_fk`,
|
165
|
-
columns: [
|
166
|
-
cols.parent
|
167
|
-
],
|
168
|
-
foreignColumns: [
|
169
|
-
adapter.tables[parentTableName].id
|
170
|
-
]
|
171
|
-
}).onDelete('cascade'),
|
172
|
-
parentIdx: (cols)=>index(`${selectTableName}_parent_idx`).on(cols.parent)
|
173
|
-
};
|
174
|
-
if (field.localized) {
|
175
|
-
baseColumns.locale = adapter.enums.enum__locales('locale').notNull();
|
176
|
-
baseExtraConfig.localeIdx = (cols)=>index(`${selectTableName}_locale_idx`).on(cols.locale);
|
177
|
-
}
|
178
|
-
if (field.index) {
|
179
|
-
baseExtraConfig.value = (cols)=>index(`${selectTableName}_value_idx`).on(cols.value);
|
180
|
-
}
|
181
|
-
buildTable({
|
182
|
-
adapter,
|
183
|
-
baseColumns,
|
184
|
-
baseExtraConfig,
|
185
|
-
disableNotNull,
|
186
|
-
disableUnique,
|
187
|
-
fields: [],
|
188
|
-
rootTableName,
|
189
|
-
tableName: selectTableName,
|
190
|
-
versions
|
191
|
-
});
|
192
|
-
relationsToBuild.set(fieldName, {
|
193
|
-
type: 'many',
|
194
|
-
// selects have their own localized table, independent of the base table.
|
195
|
-
localized: false,
|
196
|
-
target: selectTableName
|
197
|
-
});
|
198
|
-
adapter.relations[`relations_${selectTableName}`] = relations(adapter.tables[selectTableName], ({ one })=>({
|
199
|
-
parent: one(adapter.tables[parentTableName], {
|
200
|
-
fields: [
|
201
|
-
adapter.tables[selectTableName].parent
|
202
|
-
],
|
203
|
-
references: [
|
204
|
-
adapter.tables[parentTableName].id
|
205
|
-
],
|
206
|
-
relationName: fieldName
|
207
|
-
})
|
208
|
-
}));
|
209
|
-
} else {
|
210
|
-
targetTable[fieldName] = adapter.enums[enumName](fieldName);
|
211
|
-
}
|
212
|
-
break;
|
213
|
-
}
|
214
|
-
case 'checkbox':
|
215
|
-
{
|
216
|
-
targetTable[fieldName] = boolean(columnName);
|
217
|
-
break;
|
218
|
-
}
|
219
|
-
case 'array':
|
220
|
-
{
|
221
|
-
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
222
|
-
const arrayTableName = createTableName({
|
223
|
-
adapter,
|
224
|
-
config: field,
|
225
|
-
parentTableName: newTableName,
|
226
|
-
prefix: `${newTableName}_`,
|
227
|
-
throwValidationError,
|
228
|
-
versionsCustomName: versions
|
229
|
-
});
|
230
|
-
const baseColumns = {
|
231
|
-
_order: integer('_order').notNull(),
|
232
|
-
_parentID: parentIDColumnMap[parentIDColType]('_parent_id').notNull()
|
233
|
-
};
|
234
|
-
const baseExtraConfig = {
|
235
|
-
_orderIdx: (cols)=>index(`${arrayTableName}_order_idx`).on(cols._order),
|
236
|
-
_parentIDFk: (cols)=>foreignKey({
|
237
|
-
name: `${arrayTableName}_parent_id_fk`,
|
238
|
-
columns: [
|
239
|
-
cols['_parentID']
|
240
|
-
],
|
241
|
-
foreignColumns: [
|
242
|
-
adapter.tables[parentTableName].id
|
243
|
-
]
|
244
|
-
}).onDelete('cascade'),
|
245
|
-
_parentIDIdx: (cols)=>index(`${arrayTableName}_parent_id_idx`).on(cols._parentID)
|
246
|
-
};
|
247
|
-
if (field.localized && adapter.payload.config.localization) {
|
248
|
-
baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
249
|
-
baseExtraConfig._localeIdx = (cols)=>index(`${arrayTableName}_locale_idx`).on(cols._locale);
|
250
|
-
}
|
251
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
252
|
-
adapter,
|
253
|
-
baseColumns,
|
254
|
-
baseExtraConfig,
|
255
|
-
disableNotNull: disableNotNullFromHere,
|
256
|
-
disableUnique,
|
257
|
-
fields: disableUnique ? idToUUID(field.fields) : field.fields,
|
258
|
-
rootRelationsToBuild,
|
259
|
-
rootRelationships: relationships,
|
260
|
-
rootTableIDColType,
|
261
|
-
rootTableName,
|
262
|
-
tableName: arrayTableName,
|
263
|
-
versions
|
264
|
-
});
|
265
|
-
if (subHasManyTextField) {
|
266
|
-
if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
|
267
|
-
}
|
268
|
-
if (subHasManyNumberField) {
|
269
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
|
270
|
-
}
|
271
|
-
relationsToBuild.set(fieldName, {
|
272
|
-
type: 'many',
|
273
|
-
// arrays have their own localized table, independent of the base table.
|
274
|
-
localized: false,
|
275
|
-
target: arrayTableName
|
276
|
-
});
|
277
|
-
adapter.relations[`relations_${arrayTableName}`] = relations(adapter.tables[arrayTableName], ({ many, one })=>{
|
278
|
-
const result = {
|
279
|
-
_parentID: one(adapter.tables[parentTableName], {
|
280
|
-
fields: [
|
281
|
-
adapter.tables[arrayTableName]._parentID
|
282
|
-
],
|
283
|
-
references: [
|
284
|
-
adapter.tables[parentTableName].id
|
285
|
-
],
|
286
|
-
relationName: fieldName
|
287
|
-
})
|
288
|
-
};
|
289
|
-
if (hasLocalesTable(field.fields)) {
|
290
|
-
result._locales = many(adapter.tables[`${arrayTableName}${adapter.localesSuffix}`], {
|
291
|
-
relationName: '_locales'
|
292
|
-
});
|
293
|
-
}
|
294
|
-
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
295
|
-
if (type === 'one') {
|
296
|
-
const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
|
297
|
-
result[key] = one(adapter.tables[target], {
|
298
|
-
fields: [
|
299
|
-
adapter.tables[arrayWithLocalized][key]
|
300
|
-
],
|
301
|
-
references: [
|
302
|
-
adapter.tables[target].id
|
303
|
-
],
|
304
|
-
relationName: key
|
305
|
-
});
|
306
|
-
}
|
307
|
-
if (type === 'many') {
|
308
|
-
result[key] = many(adapter.tables[target], {
|
309
|
-
relationName: key
|
310
|
-
});
|
311
|
-
}
|
312
|
-
});
|
313
|
-
return result;
|
314
|
-
});
|
315
|
-
break;
|
316
|
-
}
|
317
|
-
case 'blocks':
|
318
|
-
{
|
319
|
-
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
320
|
-
field.blocks.forEach((block)=>{
|
321
|
-
const blockTableName = createTableName({
|
322
|
-
adapter,
|
323
|
-
config: block,
|
324
|
-
parentTableName: rootTableName,
|
325
|
-
prefix: `${rootTableName}_blocks_`,
|
326
|
-
throwValidationError,
|
327
|
-
versionsCustomName: versions
|
328
|
-
});
|
329
|
-
if (!adapter.tables[blockTableName]) {
|
330
|
-
const baseColumns = {
|
331
|
-
_order: integer('_order').notNull(),
|
332
|
-
_parentID: parentIDColumnMap[rootTableIDColType]('_parent_id').notNull(),
|
333
|
-
_path: text('_path').notNull()
|
334
|
-
};
|
335
|
-
const baseExtraConfig = {
|
336
|
-
_orderIdx: (cols)=>index(`${blockTableName}_order_idx`).on(cols._order),
|
337
|
-
_parentIDIdx: (cols)=>index(`${blockTableName}_parent_id_idx`).on(cols._parentID),
|
338
|
-
_parentIdFk: (cols)=>foreignKey({
|
339
|
-
name: `${blockTableName}_parent_id_fk`,
|
340
|
-
columns: [
|
341
|
-
cols._parentID
|
342
|
-
],
|
343
|
-
foreignColumns: [
|
344
|
-
adapter.tables[rootTableName].id
|
345
|
-
]
|
346
|
-
}).onDelete('cascade'),
|
347
|
-
_pathIdx: (cols)=>index(`${blockTableName}_path_idx`).on(cols._path)
|
348
|
-
};
|
349
|
-
if (field.localized && adapter.payload.config.localization) {
|
350
|
-
baseColumns._locale = adapter.enums.enum__locales('_locale').notNull();
|
351
|
-
baseExtraConfig._localeIdx = (cols)=>index(`${blockTableName}_locale_idx`).on(cols._locale);
|
352
|
-
}
|
353
|
-
const { hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
354
|
-
adapter,
|
355
|
-
baseColumns,
|
356
|
-
baseExtraConfig,
|
357
|
-
disableNotNull: disableNotNullFromHere,
|
358
|
-
disableUnique,
|
359
|
-
fields: disableUnique ? idToUUID(block.fields) : block.fields,
|
360
|
-
rootRelationsToBuild,
|
361
|
-
rootRelationships: relationships,
|
362
|
-
rootTableIDColType,
|
363
|
-
rootTableName,
|
364
|
-
tableName: blockTableName,
|
365
|
-
versions
|
366
|
-
});
|
367
|
-
if (subHasManyTextField) {
|
368
|
-
if (!hasManyTextField || subHasManyTextField === 'index') hasManyTextField = subHasManyTextField;
|
369
|
-
}
|
370
|
-
if (subHasManyNumberField) {
|
371
|
-
if (!hasManyNumberField || subHasManyNumberField === 'index') hasManyNumberField = subHasManyNumberField;
|
372
|
-
}
|
373
|
-
adapter.relations[`relations_${blockTableName}`] = relations(adapter.tables[blockTableName], ({ many, one })=>{
|
374
|
-
const result = {
|
375
|
-
_parentID: one(adapter.tables[rootTableName], {
|
376
|
-
fields: [
|
377
|
-
adapter.tables[blockTableName]._parentID
|
378
|
-
],
|
379
|
-
references: [
|
380
|
-
adapter.tables[rootTableName].id
|
381
|
-
],
|
382
|
-
relationName: `_blocks_${block.slug}`
|
383
|
-
})
|
384
|
-
};
|
385
|
-
if (hasLocalesTable(block.fields)) {
|
386
|
-
result._locales = many(adapter.tables[`${blockTableName}${adapter.localesSuffix}`], {
|
387
|
-
relationName: '_locales'
|
388
|
-
});
|
389
|
-
}
|
390
|
-
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
391
|
-
if (type === 'one') {
|
392
|
-
const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
|
393
|
-
result[key] = one(adapter.tables[target], {
|
394
|
-
fields: [
|
395
|
-
adapter.tables[blockWithLocalized][key]
|
396
|
-
],
|
397
|
-
references: [
|
398
|
-
adapter.tables[target].id
|
399
|
-
],
|
400
|
-
relationName: key
|
401
|
-
});
|
402
|
-
}
|
403
|
-
if (type === 'many') {
|
404
|
-
result[key] = many(adapter.tables[target], {
|
405
|
-
relationName: key
|
406
|
-
});
|
407
|
-
}
|
408
|
-
});
|
409
|
-
return result;
|
410
|
-
});
|
411
|
-
} else if (process.env.NODE_ENV !== 'production' && !versions) {
|
412
|
-
validateExistingBlockIsIdentical({
|
413
|
-
block,
|
414
|
-
localized: field.localized,
|
415
|
-
rootTableName,
|
416
|
-
table: adapter.tables[blockTableName],
|
417
|
-
tableLocales: adapter.tables[`${blockTableName}${adapter.localesSuffix}`]
|
418
|
-
});
|
419
|
-
}
|
420
|
-
// blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
|
421
|
-
rootRelationsToBuild.set(`_blocks_${block.slug}`, {
|
422
|
-
type: 'many',
|
423
|
-
// blocks are not localized on the parent table
|
424
|
-
localized: false,
|
425
|
-
target: blockTableName
|
426
|
-
});
|
427
|
-
});
|
428
|
-
break;
|
429
|
-
}
|
430
|
-
case 'tab':
|
431
|
-
case 'group':
|
432
|
-
{
|
433
|
-
if (!('name' in field)) {
|
434
|
-
const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
|
435
|
-
adapter,
|
436
|
-
columnPrefix,
|
437
|
-
columns,
|
438
|
-
disableNotNull,
|
439
|
-
disableUnique,
|
440
|
-
fieldPrefix,
|
441
|
-
fields: field.fields,
|
442
|
-
forceLocalized,
|
443
|
-
indexes,
|
444
|
-
localesColumns,
|
445
|
-
localesIndexes,
|
446
|
-
newTableName,
|
447
|
-
parentTableName,
|
448
|
-
relationsToBuild,
|
449
|
-
relationships,
|
450
|
-
rootRelationsToBuild,
|
451
|
-
rootTableIDColType,
|
452
|
-
rootTableName,
|
453
|
-
versions
|
454
|
-
});
|
455
|
-
if (groupHasLocalizedField) hasLocalizedField = true;
|
456
|
-
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
457
|
-
if (groupHasManyTextField) hasManyTextField = true;
|
458
|
-
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true;
|
459
|
-
if (groupHasManyNumberField) hasManyNumberField = true;
|
460
|
-
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
|
461
|
-
break;
|
462
|
-
}
|
463
|
-
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
464
|
-
const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
|
465
|
-
adapter,
|
466
|
-
columnPrefix: `${columnName}_`,
|
467
|
-
columns,
|
468
|
-
disableNotNull: disableNotNullFromHere,
|
469
|
-
disableUnique,
|
470
|
-
fieldPrefix: `${fieldName}.`,
|
471
|
-
fields: field.fields,
|
472
|
-
forceLocalized: field.localized,
|
473
|
-
indexes,
|
474
|
-
localesColumns,
|
475
|
-
localesIndexes,
|
476
|
-
newTableName: `${parentTableName}_${columnName}`,
|
477
|
-
parentTableName,
|
478
|
-
relationsToBuild,
|
479
|
-
relationships,
|
480
|
-
rootRelationsToBuild,
|
481
|
-
rootTableIDColType,
|
482
|
-
rootTableName,
|
483
|
-
versions
|
484
|
-
});
|
485
|
-
if (groupHasLocalizedField) hasLocalizedField = true;
|
486
|
-
if (groupHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
487
|
-
if (groupHasManyTextField) hasManyTextField = true;
|
488
|
-
if (groupHasLocalizedManyTextField) hasLocalizedManyTextField = true;
|
489
|
-
if (groupHasManyNumberField) hasManyNumberField = true;
|
490
|
-
if (groupHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
|
491
|
-
break;
|
492
|
-
}
|
493
|
-
case 'tabs':
|
494
|
-
{
|
495
|
-
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
496
|
-
const { hasLocalizedField: tabHasLocalizedField, hasLocalizedManyNumberField: tabHasLocalizedManyNumberField, hasLocalizedManyTextField: tabHasLocalizedManyTextField, hasLocalizedRelationshipField: tabHasLocalizedRelationshipField, hasManyNumberField: tabHasManyNumberField, hasManyTextField: tabHasManyTextField } = traverseFields({
|
497
|
-
adapter,
|
498
|
-
columnPrefix,
|
499
|
-
columns,
|
500
|
-
disableNotNull: disableNotNullFromHere,
|
501
|
-
disableUnique,
|
502
|
-
fieldPrefix,
|
503
|
-
fields: field.tabs.map((tab)=>({
|
504
|
-
...tab,
|
505
|
-
type: 'tab'
|
506
|
-
})),
|
507
|
-
forceLocalized,
|
508
|
-
indexes,
|
509
|
-
localesColumns,
|
510
|
-
localesIndexes,
|
511
|
-
newTableName,
|
512
|
-
parentTableName,
|
513
|
-
relationsToBuild,
|
514
|
-
relationships,
|
515
|
-
rootRelationsToBuild,
|
516
|
-
rootTableIDColType,
|
517
|
-
rootTableName,
|
518
|
-
versions
|
519
|
-
});
|
520
|
-
if (tabHasLocalizedField) hasLocalizedField = true;
|
521
|
-
if (tabHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
522
|
-
if (tabHasManyTextField) hasManyTextField = true;
|
523
|
-
if (tabHasLocalizedManyTextField) hasLocalizedManyTextField = true;
|
524
|
-
if (tabHasManyNumberField) hasManyNumberField = true;
|
525
|
-
if (tabHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
|
526
|
-
break;
|
527
|
-
}
|
528
|
-
case 'row':
|
529
|
-
case 'collapsible':
|
530
|
-
{
|
531
|
-
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
532
|
-
const { hasLocalizedField: rowHasLocalizedField, hasLocalizedManyNumberField: rowHasLocalizedManyNumberField, hasLocalizedManyTextField: rowHasLocalizedManyTextField, hasLocalizedRelationshipField: rowHasLocalizedRelationshipField, hasManyNumberField: rowHasManyNumberField, hasManyTextField: rowHasManyTextField } = traverseFields({
|
533
|
-
adapter,
|
534
|
-
columnPrefix,
|
535
|
-
columns,
|
536
|
-
disableNotNull: disableNotNullFromHere,
|
537
|
-
disableUnique,
|
538
|
-
fieldPrefix,
|
539
|
-
fields: field.fields,
|
540
|
-
forceLocalized,
|
541
|
-
indexes,
|
542
|
-
localesColumns,
|
543
|
-
localesIndexes,
|
544
|
-
newTableName,
|
545
|
-
parentTableName,
|
546
|
-
relationsToBuild,
|
547
|
-
relationships,
|
548
|
-
rootRelationsToBuild,
|
549
|
-
rootTableIDColType,
|
550
|
-
rootTableName,
|
551
|
-
versions
|
552
|
-
});
|
553
|
-
if (rowHasLocalizedField) hasLocalizedField = true;
|
554
|
-
if (rowHasLocalizedRelationshipField) hasLocalizedRelationshipField = true;
|
555
|
-
if (rowHasManyTextField) hasManyTextField = true;
|
556
|
-
if (rowHasLocalizedManyTextField) hasLocalizedManyTextField = true;
|
557
|
-
if (rowHasManyNumberField) hasManyNumberField = true;
|
558
|
-
if (rowHasLocalizedManyNumberField) hasLocalizedManyNumberField = true;
|
559
|
-
break;
|
560
|
-
}
|
561
|
-
case 'relationship':
|
562
|
-
case 'upload':
|
563
|
-
if (Array.isArray(field.relationTo)) {
|
564
|
-
field.relationTo.forEach((relation)=>relationships.add(relation));
|
565
|
-
} else if (field.type === 'relationship' && field.hasMany) {
|
566
|
-
relationships.add(field.relationTo);
|
567
|
-
} else {
|
568
|
-
// simple relationships get a column on the targetTable with a foreign key to the relationTo table
|
569
|
-
const relationshipConfig = adapter.payload.collections[field.relationTo].config;
|
570
|
-
const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
|
571
|
-
// get the id type of the related collection
|
572
|
-
let colType = adapter.idType === 'uuid' ? 'uuid' : 'integer';
|
573
|
-
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
574
|
-
if (relatedCollectionCustomID?.type === 'number') colType = 'numeric';
|
575
|
-
if (relatedCollectionCustomID?.type === 'text') colType = 'varchar';
|
576
|
-
// make the foreign key column for relationship using the correct id column type
|
577
|
-
targetTable[fieldName] = parentIDColumnMap[colType](`${columnName}_id`).references(()=>adapter.tables[tableName].id, {
|
578
|
-
onDelete: 'set null'
|
579
|
-
});
|
580
|
-
// add relationship to table
|
581
|
-
relationsToBuild.set(fieldName, {
|
582
|
-
type: 'one',
|
583
|
-
localized: adapter.payload.config.localization && field.localized,
|
584
|
-
target: tableName
|
585
|
-
});
|
586
|
-
// add notNull when not required
|
587
|
-
if (!disableNotNull && field.required && !field.admin?.condition) {
|
588
|
-
targetTable[fieldName].notNull();
|
589
|
-
}
|
590
|
-
break;
|
591
|
-
}
|
592
|
-
if (adapter.payload.config.localization && field.localized) {
|
593
|
-
hasLocalizedRelationshipField = true;
|
594
|
-
}
|
595
|
-
break;
|
596
|
-
default:
|
597
|
-
break;
|
598
|
-
}
|
599
|
-
const condition = field.admin && field.admin.condition;
|
600
|
-
if (!disableNotNull && targetTable[fieldName] && 'required' in field && field.required && !condition) {
|
601
|
-
targetTable[fieldName].notNull();
|
602
|
-
}
|
603
|
-
});
|
604
|
-
return {
|
605
|
-
hasLocalizedField,
|
606
|
-
hasLocalizedManyNumberField,
|
607
|
-
hasLocalizedManyTextField,
|
608
|
-
hasLocalizedRelationshipField,
|
609
|
-
hasManyNumberField,
|
610
|
-
hasManyTextField
|
611
|
-
};
|
612
|
-
};
|
613
|
-
|
614
|
-
//# sourceMappingURL=traverseFields.js.map
|