@hanzo/cms-drizzle 3.85.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +22 -0
- package/README.md +3 -0
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +26 -0
- package/dist/count.js.map +1 -0
- package/dist/countGlobalVersions.d.ts +3 -0
- package/dist/countGlobalVersions.d.ts.map +1 -0
- package/dist/countGlobalVersions.js +28 -0
- package/dist/countGlobalVersions.js.map +1 -0
- package/dist/countVersions.d.ts +3 -0
- package/dist/countVersions.d.ts.map +1 -0
- package/dist/countVersions.js +28 -0
- package/dist/countVersions.js.map +1 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +28 -0
- package/dist/create.js.map +1 -0
- package/dist/createGlobal.d.ts +4 -0
- package/dist/createGlobal.d.ts.map +1 -0
- package/dist/createGlobal.js +28 -0
- package/dist/createGlobal.js.map +1 -0
- package/dist/createGlobalVersion.d.ts +4 -0
- package/dist/createGlobalVersion.d.ts.map +1 -0
- package/dist/createGlobalVersion.js +49 -0
- package/dist/createGlobalVersion.js.map +1 -0
- package/dist/createTableName.d.ts +31 -0
- package/dist/createTableName.d.ts.map +1 -0
- package/dist/createTableName.js +37 -0
- package/dist/createTableName.js.map +1 -0
- package/dist/createVersion.d.ts +4 -0
- package/dist/createVersion.d.ts.map +1 -0
- package/dist/createVersion.js +65 -0
- package/dist/createVersion.js.map +1 -0
- package/dist/deleteMany.d.ts +3 -0
- package/dist/deleteMany.d.ts.map +1 -0
- package/dist/deleteMany.js +51 -0
- package/dist/deleteMany.js.map +1 -0
- package/dist/deleteOne.d.ts +3 -0
- package/dist/deleteOne.d.ts.map +1 -0
- package/dist/deleteOne.js +67 -0
- package/dist/deleteOne.js.map +1 -0
- package/dist/deleteVersions.d.ts +3 -0
- package/dist/deleteVersions.d.ts.map +1 -0
- package/dist/deleteVersions.js +52 -0
- package/dist/deleteVersions.js.map +1 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.d.ts.map +1 -0
- package/dist/destroy.js +17 -0
- package/dist/destroy.js.map +1 -0
- package/dist/exports/postgres.d.ts +16 -0
- package/dist/exports/postgres.d.ts.map +1 -0
- package/dist/exports/postgres.js +17 -0
- package/dist/exports/postgres.js.map +1 -0
- package/dist/exports/sqlite.d.ts +13 -0
- package/dist/exports/sqlite.d.ts.map +1 -0
- package/dist/exports/sqlite.js +14 -0
- package/dist/exports/sqlite.js.map +1 -0
- package/dist/exports/types-deprecated.d.ts +150 -0
- package/dist/exports/types-deprecated.d.ts.map +1 -0
- package/dist/exports/types-deprecated.js +5 -0
- package/dist/exports/types-deprecated.js.map +1 -0
- package/dist/find/buildFindManyArgs.d.ts +27 -0
- package/dist/find/buildFindManyArgs.d.ts.map +1 -0
- package/dist/find/buildFindManyArgs.js +96 -0
- package/dist/find/buildFindManyArgs.js.map +1 -0
- package/dist/find/chainMethods.d.ts +20 -0
- package/dist/find/chainMethods.d.ts.map +1 -0
- package/dist/find/chainMethods.js +16 -0
- package/dist/find/chainMethods.js.map +1 -0
- package/dist/find/findMany.d.ts +23 -0
- package/dist/find/findMany.d.ts.map +1 -0
- package/dist/find/findMany.js +173 -0
- package/dist/find/findMany.js.map +1 -0
- package/dist/find/traverseFields.d.ts +34 -0
- package/dist/find/traverseFields.d.ts.map +1 -0
- package/dist/find/traverseFields.js +653 -0
- package/dist/find/traverseFields.js.map +1 -0
- package/dist/find.d.ts +3 -0
- package/dist/find.d.ts.map +1 -0
- package/dist/find.js +25 -0
- package/dist/find.js.map +1 -0
- package/dist/findDistinct.d.ts +3 -0
- package/dist/findDistinct.d.ts.map +1 -0
- package/dist/findDistinct.js +135 -0
- package/dist/findDistinct.js.map +1 -0
- package/dist/findGlobal.d.ts +3 -0
- package/dist/findGlobal.d.ts.map +1 -0
- package/dist/findGlobal.js +24 -0
- package/dist/findGlobal.js.map +1 -0
- package/dist/findGlobalVersions.d.ts +3 -0
- package/dist/findGlobalVersions.d.ts.map +1 -0
- package/dist/findGlobalVersions.js +24 -0
- package/dist/findGlobalVersions.js.map +1 -0
- package/dist/findOne.d.ts +4 -0
- package/dist/findOne.d.ts.map +1 -0
- package/dist/findOne.js +25 -0
- package/dist/findOne.js.map +1 -0
- package/dist/findVersions.d.ts +3 -0
- package/dist/findVersions.d.ts.map +1 -0
- package/dist/findVersions.js +25 -0
- package/dist/findVersions.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate.d.ts +3 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +98 -0
- package/dist/migrate.js.map +1 -0
- package/dist/migrateDown.d.ts +3 -0
- package/dist/migrateDown.d.ts.map +1 -0
- package/dist/migrateDown.js +64 -0
- package/dist/migrateDown.js.map +1 -0
- package/dist/migrateFresh.d.ts +8 -0
- package/dist/migrateFresh.d.ts.map +1 -0
- package/dist/migrateFresh.js +77 -0
- package/dist/migrateFresh.js.map +1 -0
- package/dist/migrateRefresh.d.ts +6 -0
- package/dist/migrateRefresh.d.ts.map +1 -0
- package/dist/migrateRefresh.js +104 -0
- package/dist/migrateRefresh.js.map +1 -0
- package/dist/migrateReset.d.ts +6 -0
- package/dist/migrateReset.d.ts.map +1 -0
- package/dist/migrateReset.js +86 -0
- package/dist/migrateReset.js.map +1 -0
- package/dist/migrateStatus.d.ts +3 -0
- package/dist/migrateStatus.d.ts.map +1 -0
- package/dist/migrateStatus.js +44 -0
- package/dist/migrateStatus.js.map +1 -0
- package/dist/postgres/columnToCodeConverter.d.ts +3 -0
- package/dist/postgres/columnToCodeConverter.d.ts.map +1 -0
- package/dist/postgres/columnToCodeConverter.js +93 -0
- package/dist/postgres/columnToCodeConverter.js.map +1 -0
- package/dist/postgres/countDistinct.d.ts +3 -0
- package/dist/postgres/countDistinct.d.ts.map +1 -0
- package/dist/postgres/countDistinct.js +24 -0
- package/dist/postgres/countDistinct.js.map +1 -0
- package/dist/postgres/createDatabase.d.ts +14 -0
- package/dist/postgres/createDatabase.d.ts.map +1 -0
- package/dist/postgres/createDatabase.js +76 -0
- package/dist/postgres/createDatabase.js.map +1 -0
- package/dist/postgres/createExtensions.d.ts +3 -0
- package/dist/postgres/createExtensions.d.ts.map +1 -0
- package/dist/postgres/createExtensions.js +16 -0
- package/dist/postgres/createExtensions.js.map +1 -0
- package/dist/postgres/createJSONQuery/index.d.ts +3 -0
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/index.js +67 -0
- package/dist/postgres/createJSONQuery/index.js.map +1 -0
- package/dist/postgres/defaultSnapshot.d.ts +3 -0
- package/dist/postgres/defaultSnapshot.d.ts.map +1 -0
- package/dist/postgres/defaultSnapshot.js +20 -0
- package/dist/postgres/defaultSnapshot.js.map +1 -0
- package/dist/postgres/deleteWhere.d.ts +3 -0
- package/dist/postgres/deleteWhere.d.ts.map +1 -0
- package/dist/postgres/deleteWhere.js +6 -0
- package/dist/postgres/deleteWhere.js.map +1 -0
- package/dist/postgres/dropDatabase.d.ts +3 -0
- package/dist/postgres/dropDatabase.d.ts.map +1 -0
- package/dist/postgres/dropDatabase.js +9 -0
- package/dist/postgres/dropDatabase.js.map +1 -0
- package/dist/postgres/execute.d.ts +3 -0
- package/dist/postgres/execute.d.ts.map +1 -0
- package/dist/postgres/execute.js +11 -0
- package/dist/postgres/execute.js.map +1 -0
- package/dist/postgres/init.d.ts +3 -0
- package/dist/postgres/init.d.ts.map +1 -0
- package/dist/postgres/init.js +41 -0
- package/dist/postgres/init.js.map +1 -0
- package/dist/postgres/insert.d.ts +3 -0
- package/dist/postgres/insert.d.ts.map +1 -0
- package/dist/postgres/insert.js +12 -0
- package/dist/postgres/insert.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +19 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +173 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +151 -0
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js +114 -0
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts +23 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +275 -0
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js +64 -0
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts +22 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js +64 -0
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts +9 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.js +6 -0
- package/dist/postgres/predefinedMigrations/v2-v3/types.js.map +1 -0
- package/dist/postgres/requireDrizzleKit.d.ts +3 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
- package/dist/postgres/requireDrizzleKit.js +13 -0
- package/dist/postgres/requireDrizzleKit.js.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts +7 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.js +157 -0
- package/dist/postgres/schema/buildDrizzleTable.js.map +1 -0
- package/dist/postgres/schema/geometryColumn.d.ts +11 -0
- package/dist/postgres/schema/geometryColumn.d.ts.map +1 -0
- package/dist/postgres/schema/geometryColumn.js +18 -0
- package/dist/postgres/schema/geometryColumn.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +3 -0
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
- package/dist/postgres/schema/setColumnID.js +47 -0
- package/dist/postgres/schema/setColumnID.js.map +1 -0
- package/dist/postgres/types.d.ts +199 -0
- package/dist/postgres/types.d.ts.map +1 -0
- package/dist/postgres/types.js +3 -0
- package/dist/postgres/types.js.map +1 -0
- package/dist/queries/addJoinTable.d.ts +13 -0
- package/dist/queries/addJoinTable.d.ts.map +1 -0
- package/dist/queries/addJoinTable.js +15 -0
- package/dist/queries/addJoinTable.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +21 -0
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -0
- package/dist/queries/buildAndOrConditions.js +30 -0
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildOrderBy.d.ts +22 -0
- package/dist/queries/buildOrderBy.d.ts.map +1 -0
- package/dist/queries/buildOrderBy.js +71 -0
- package/dist/queries/buildOrderBy.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +35 -0
- package/dist/queries/buildQuery.d.ts.map +1 -0
- package/dist/queries/buildQuery.js +46 -0
- package/dist/queries/buildQuery.js.map +1 -0
- package/dist/queries/getTableAlias.d.ts +13 -0
- package/dist/queries/getTableAlias.d.ts.map +1 -0
- package/dist/queries/getTableAlias.js +20 -0
- package/dist/queries/getTableAlias.js.map +1 -0
- package/dist/queries/getTableColumnFromPath.d.ts +58 -0
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -0
- package/dist/queries/getTableColumnFromPath.js +793 -0
- package/dist/queries/getTableColumnFromPath.js.map +1 -0
- package/dist/queries/operatorMap.d.ts +6 -0
- package/dist/queries/operatorMap.d.ts.map +1 -0
- package/dist/queries/operatorMap.js +22 -0
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.d.ts +24 -0
- package/dist/queries/parseParams.d.ts.map +1 -0
- package/dist/queries/parseParams.js +356 -0
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts +26 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -0
- package/dist/queries/sanitizeQueryValue.js +246 -0
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queries/selectDistinct.d.ts +25 -0
- package/dist/queries/selectDistinct.d.ts.map +1 -0
- package/dist/queries/selectDistinct.js +29 -0
- package/dist/queries/selectDistinct.js.map +1 -0
- package/dist/queryDrafts.d.ts +3 -0
- package/dist/queryDrafts.d.ts.map +1 -0
- package/dist/queryDrafts.js +41 -0
- package/dist/queryDrafts.js.map +1 -0
- package/dist/schema/build.d.ts +50 -0
- package/dist/schema/build.d.ts.map +1 -0
- package/dist/schema/build.js +705 -0
- package/dist/schema/build.js.map +1 -0
- package/dist/schema/buildDrizzleRelations.d.ts +5 -0
- package/dist/schema/buildDrizzleRelations.d.ts.map +1 -0
- package/dist/schema/buildDrizzleRelations.js +28 -0
- package/dist/schema/buildDrizzleRelations.js.map +1 -0
- package/dist/schema/buildRawSchema.d.ts +9 -0
- package/dist/schema/buildRawSchema.d.ts.map +1 -0
- package/dist/schema/buildRawSchema.js +117 -0
- package/dist/schema/buildRawSchema.js.map +1 -0
- package/dist/schema/idToUUID.d.ts +3 -0
- package/dist/schema/idToUUID.d.ts.map +1 -0
- package/dist/schema/idToUUID.js +11 -0
- package/dist/schema/idToUUID.js.map +1 -0
- package/dist/schema/traverseFields.d.ts +44 -0
- package/dist/schema/traverseFields.d.ts.map +1 -0
- package/dist/schema/traverseFields.js +810 -0
- package/dist/schema/traverseFields.js.map +1 -0
- package/dist/schema/withDefault.d.ts +4 -0
- package/dist/schema/withDefault.d.ts.map +1 -0
- package/dist/schema/withDefault.js +11 -0
- package/dist/schema/withDefault.js.map +1 -0
- package/dist/sqlite/columnToCodeConverter.d.ts +3 -0
- package/dist/sqlite/columnToCodeConverter.d.ts.map +1 -0
- package/dist/sqlite/columnToCodeConverter.js +116 -0
- package/dist/sqlite/columnToCodeConverter.js.map +1 -0
- package/dist/sqlite/countDistinct.d.ts +3 -0
- package/dist/sqlite/countDistinct.d.ts.map +1 -0
- package/dist/sqlite/countDistinct.js +24 -0
- package/dist/sqlite/countDistinct.js.map +1 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +14 -0
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/sqlite/createJSONQuery/index.d.ts +3 -0
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -0
- package/dist/sqlite/createJSONQuery/index.js +109 -0
- package/dist/sqlite/createJSONQuery/index.js.map +1 -0
- package/dist/sqlite/defaultSnapshot.d.ts +3 -0
- package/dist/sqlite/defaultSnapshot.d.ts.map +1 -0
- package/dist/sqlite/defaultSnapshot.js +15 -0
- package/dist/sqlite/defaultSnapshot.js.map +1 -0
- package/dist/sqlite/deleteWhere.d.ts +3 -0
- package/dist/sqlite/deleteWhere.d.ts.map +1 -0
- package/dist/sqlite/deleteWhere.js +6 -0
- package/dist/sqlite/deleteWhere.js.map +1 -0
- package/dist/sqlite/dropDatabase.d.ts +3 -0
- package/dist/sqlite/dropDatabase.d.ts.map +1 -0
- package/dist/sqlite/dropDatabase.js +19 -0
- package/dist/sqlite/dropDatabase.js.map +1 -0
- package/dist/sqlite/execute.d.ts +3 -0
- package/dist/sqlite/execute.d.ts.map +1 -0
- package/dist/sqlite/execute.js +13 -0
- package/dist/sqlite/execute.js.map +1 -0
- package/dist/sqlite/init.d.ts +3 -0
- package/dist/sqlite/init.d.ts.map +1 -0
- package/dist/sqlite/init.js +42 -0
- package/dist/sqlite/init.js.map +1 -0
- package/dist/sqlite/insert.d.ts +3 -0
- package/dist/sqlite/insert.d.ts.map +1 -0
- package/dist/sqlite/insert.js +21 -0
- package/dist/sqlite/insert.js.map +1 -0
- package/dist/sqlite/requireDrizzleKit.d.ts +3 -0
- package/dist/sqlite/requireDrizzleKit.d.ts.map +1 -0
- package/dist/sqlite/requireDrizzleKit.js +12 -0
- package/dist/sqlite/requireDrizzleKit.js.map +1 -0
- package/dist/sqlite/schema/buildDrizzleTable.d.ts +3 -0
- package/dist/sqlite/schema/buildDrizzleTable.d.ts.map +1 -0
- package/dist/sqlite/schema/buildDrizzleTable.js +153 -0
- package/dist/sqlite/schema/buildDrizzleTable.js.map +1 -0
- package/dist/sqlite/schema/setColumnID.d.ts +3 -0
- package/dist/sqlite/schema/setColumnID.d.ts.map +1 -0
- package/dist/sqlite/schema/setColumnID.js +48 -0
- package/dist/sqlite/schema/setColumnID.js.map +1 -0
- package/dist/sqlite/types.d.ts +214 -0
- package/dist/sqlite/types.d.ts.map +1 -0
- package/dist/sqlite/types.js +3 -0
- package/dist/sqlite/types.js.map +1 -0
- package/dist/transactions/beginTransaction.d.ts +3 -0
- package/dist/transactions/beginTransaction.d.ts.map +1 -0
- package/dist/transactions/beginTransaction.js +59 -0
- package/dist/transactions/beginTransaction.js.map +1 -0
- package/dist/transactions/commitTransaction.d.ts +3 -0
- package/dist/transactions/commitTransaction.d.ts.map +1 -0
- package/dist/transactions/commitTransaction.js +18 -0
- package/dist/transactions/commitTransaction.js.map +1 -0
- package/dist/transactions/rollbackTransaction.d.ts +3 -0
- package/dist/transactions/rollbackTransaction.d.ts.map +1 -0
- package/dist/transactions/rollbackTransaction.js +16 -0
- package/dist/transactions/rollbackTransaction.js.map +1 -0
- package/dist/transform/read/hasManyNumber.d.ts +11 -0
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -0
- package/dist/transform/read/hasManyNumber.js +28 -0
- package/dist/transform/read/hasManyNumber.js.map +1 -0
- package/dist/transform/read/hasManyText.d.ts +11 -0
- package/dist/transform/read/hasManyText.d.ts.map +1 -0
- package/dist/transform/read/hasManyText.js +20 -0
- package/dist/transform/read/hasManyText.js.map +1 -0
- package/dist/transform/read/index.d.ts +16 -0
- package/dist/transform/read/index.d.ts.map +1 -0
- package/dist/transform/read/index.js +49 -0
- package/dist/transform/read/index.js.map +1 -0
- package/dist/transform/read/relationship.d.ts +11 -0
- package/dist/transform/read/relationship.d.ts.map +1 -0
- package/dist/transform/read/relationship.js +69 -0
- package/dist/transform/read/relationship.js.map +1 -0
- package/dist/transform/read/traverseFields.d.ts +68 -0
- package/dist/transform/read/traverseFields.d.ts.map +1 -0
- package/dist/transform/read/traverseFields.js +542 -0
- package/dist/transform/read/traverseFields.js.map +1 -0
- package/dist/transform/write/array.d.ts +34 -0
- package/dist/transform/write/array.d.ts.map +1 -0
- package/dist/transform/write/array.js +73 -0
- package/dist/transform/write/array.js.map +1 -0
- package/dist/transform/write/blocks.d.ts +33 -0
- package/dist/transform/write/blocks.d.ts.map +1 -0
- package/dist/transform/write/blocks.js +78 -0
- package/dist/transform/write/blocks.js.map +1 -0
- package/dist/transform/write/index.d.ts +15 -0
- package/dist/transform/write/index.d.ts.map +1 -0
- package/dist/transform/write/index.js +51 -0
- package/dist/transform/write/index.js.map +1 -0
- package/dist/transform/write/numbers.d.ts +8 -0
- package/dist/transform/write/numbers.d.ts.map +1 -0
- package/dist/transform/write/numbers.js +11 -0
- package/dist/transform/write/numbers.js.map +1 -0
- package/dist/transform/write/relationships.d.ts +10 -0
- package/dist/transform/write/relationships.d.ts.map +1 -0
- package/dist/transform/write/relationships.js +27 -0
- package/dist/transform/write/relationships.js.map +1 -0
- package/dist/transform/write/selects.d.ts +8 -0
- package/dist/transform/write/selects.d.ts.map +1 -0
- package/dist/transform/write/selects.js +20 -0
- package/dist/transform/write/selects.js.map +1 -0
- package/dist/transform/write/texts.d.ts +8 -0
- package/dist/transform/write/texts.d.ts.map +1 -0
- package/dist/transform/write/texts.js +11 -0
- package/dist/transform/write/texts.js.map +1 -0
- package/dist/transform/write/traverseFields.d.ts +68 -0
- package/dist/transform/write/traverseFields.d.ts.map +1 -0
- package/dist/transform/write/traverseFields.js +661 -0
- package/dist/transform/write/traverseFields.js.map +1 -0
- package/dist/transform/write/types.d.ts +71 -0
- package/dist/transform/write/types.d.ts.map +1 -0
- package/dist/transform/write/types.js +3 -0
- package/dist/transform/write/types.js.map +1 -0
- package/dist/types.d.ts +355 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/updateGlobal.d.ts +4 -0
- package/dist/updateGlobal.d.ts.map +1 -0
- package/dist/updateGlobal.js +34 -0
- package/dist/updateGlobal.js.map +1 -0
- package/dist/updateGlobalVersion.d.ts +4 -0
- package/dist/updateGlobalVersion.d.ts.map +1 -0
- package/dist/updateGlobalVersion.js +44 -0
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateJobs.d.ts +3 -0
- package/dist/updateJobs.d.ts.map +1 -0
- package/dist/updateJobs.js +84 -0
- package/dist/updateJobs.js.map +1 -0
- package/dist/updateMany.d.ts +3 -0
- package/dist/updateMany.d.ts.map +1 -0
- package/dist/updateMany.js +76 -0
- package/dist/updateMany.js.map +1 -0
- package/dist/updateOne.d.ts +3 -0
- package/dist/updateOne.d.ts.map +1 -0
- package/dist/updateOne.js +69 -0
- package/dist/updateOne.js.map +1 -0
- package/dist/updateVersion.d.ts +4 -0
- package/dist/updateVersion.d.ts.map +1 -0
- package/dist/updateVersion.js +45 -0
- package/dist/updateVersion.js.map +1 -0
- package/dist/upsert.d.ts +3 -0
- package/dist/upsert.d.ts.map +1 -0
- package/dist/upsert.js +17 -0
- package/dist/upsert.js.map +1 -0
- package/dist/upsertRow/deleteExistingArrayRows.d.ts +10 -0
- package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -0
- package/dist/upsertRow/deleteExistingArrayRows.js +14 -0
- package/dist/upsertRow/deleteExistingArrayRows.js.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts +14 -0
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -0
- package/dist/upsertRow/deleteExistingRowsByPath.js +45 -0
- package/dist/upsertRow/deleteExistingRowsByPath.js.map +1 -0
- package/dist/upsertRow/handleUpsertError.d.ts +19 -0
- package/dist/upsertRow/handleUpsertError.d.ts.map +1 -0
- package/dist/upsertRow/handleUpsertError.js +66 -0
- package/dist/upsertRow/handleUpsertError.js.map +1 -0
- package/dist/upsertRow/handleUpsertError.spec.js +42 -0
- package/dist/upsertRow/handleUpsertError.spec.js.map +1 -0
- package/dist/upsertRow/index.d.ts +11 -0
- package/dist/upsertRow/index.d.ts.map +1 -0
- package/dist/upsertRow/index.js +668 -0
- package/dist/upsertRow/index.js.map +1 -0
- package/dist/upsertRow/insertArrays.d.ts +14 -0
- package/dist/upsertRow/insertArrays.d.ts.map +1 -0
- package/dist/upsertRow/insertArrays.js +87 -0
- package/dist/upsertRow/insertArrays.js.map +1 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts +10 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts.map +1 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.js +63 -0
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.js.map +1 -0
- package/dist/upsertRow/types.d.ts +47 -0
- package/dist/upsertRow/types.d.ts.map +1 -0
- package/dist/upsertRow/types.js +3 -0
- package/dist/upsertRow/types.js.map +1 -0
- package/dist/utilities/appendPrefixToKeys.d.ts +2 -0
- package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -0
- package/dist/utilities/appendPrefixToKeys.js +6 -0
- package/dist/utilities/appendPrefixToKeys.js.map +1 -0
- package/dist/utilities/blocksToJsonMigrator.d.ts +15 -0
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -0
- package/dist/utilities/blocksToJsonMigrator.js +587 -0
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -0
- package/dist/utilities/buildCreateMigration.d.ts +10 -0
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -0
- package/dist/utilities/buildCreateMigration.js +121 -0
- package/dist/utilities/buildCreateMigration.js.map +1 -0
- package/dist/utilities/buildForeignKeyName.d.ts +7 -0
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -0
- package/dist/utilities/buildForeignKeyName.js +18 -0
- package/dist/utilities/buildForeignKeyName.js.map +1 -0
- package/dist/utilities/buildIndexName.d.ts +8 -0
- package/dist/utilities/buildIndexName.d.ts.map +1 -0
- package/dist/utilities/buildIndexName.js +19 -0
- package/dist/utilities/buildIndexName.js.map +1 -0
- package/dist/utilities/createBlocksMap.d.ts +5 -0
- package/dist/utilities/createBlocksMap.d.ts.map +1 -0
- package/dist/utilities/createBlocksMap.js +35 -0
- package/dist/utilities/createBlocksMap.js.map +1 -0
- package/dist/utilities/createRelationshipMap.d.ts +2 -0
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -0
- package/dist/utilities/createRelationshipMap.js +21 -0
- package/dist/utilities/createRelationshipMap.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts +11 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -0
- package/dist/utilities/createSchemaGenerator.js +257 -0
- package/dist/utilities/createSchemaGenerator.js.map +1 -0
- package/dist/utilities/escapeSQLValue.d.ts +3 -0
- package/dist/utilities/escapeSQLValue.d.ts.map +1 -0
- package/dist/utilities/escapeSQLValue.js +20 -0
- package/dist/utilities/escapeSQLValue.js.map +1 -0
- package/dist/utilities/executeSchemaHooks.d.ts +24 -0
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -0
- package/dist/utilities/executeSchemaHooks.js +21 -0
- package/dist/utilities/executeSchemaHooks.js.map +1 -0
- package/dist/utilities/extendDrizzleTable.d.ts +19 -0
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/extendDrizzleTable.js +38 -0
- package/dist/utilities/extendDrizzleTable.js.map +1 -0
- package/dist/utilities/getArrayRelationName.d.ts +7 -0
- package/dist/utilities/getArrayRelationName.d.ts.map +1 -0
- package/dist/utilities/getArrayRelationName.js +8 -0
- package/dist/utilities/getArrayRelationName.js.map +1 -0
- package/dist/utilities/getCollectionIdType.d.ts +7 -0
- package/dist/utilities/getCollectionIdType.d.ts.map +1 -0
- package/dist/utilities/getCollectionIdType.js +12 -0
- package/dist/utilities/getCollectionIdType.js.map +1 -0
- package/dist/utilities/getMigrationTemplate.d.ts +4 -0
- package/dist/utilities/getMigrationTemplate.d.ts.map +1 -0
- package/dist/utilities/getMigrationTemplate.js +13 -0
- package/dist/utilities/getMigrationTemplate.js.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts +3 -0
- package/dist/utilities/getNameFromDrizzleTable.d.ts.map +1 -0
- package/dist/utilities/getNameFromDrizzleTable.js +6 -0
- package/dist/utilities/getNameFromDrizzleTable.js.map +1 -0
- package/dist/utilities/getPrimaryDb.d.ts +6 -0
- package/dist/utilities/getPrimaryDb.d.ts.map +1 -0
- package/dist/utilities/getPrimaryDb.js +10 -0
- package/dist/utilities/getPrimaryDb.js.map +1 -0
- package/dist/utilities/getTransaction.d.ts +13 -0
- package/dist/utilities/getTransaction.d.ts.map +1 -0
- package/dist/utilities/getTransaction.js +20 -0
- package/dist/utilities/getTransaction.js.map +1 -0
- package/dist/utilities/hasLocalesTable.d.ts +9 -0
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -0
- package/dist/utilities/hasLocalesTable.js +30 -0
- package/dist/utilities/hasLocalesTable.js.map +1 -0
- package/dist/utilities/isArrayOfRows.d.ts +2 -0
- package/dist/utilities/isArrayOfRows.d.ts.map +1 -0
- package/dist/utilities/isArrayOfRows.js +5 -0
- package/dist/utilities/isArrayOfRows.js.map +1 -0
- package/dist/utilities/isPolymorphicRelationship.d.ts +6 -0
- package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -0
- package/dist/utilities/isPolymorphicRelationship.js +5 -0
- package/dist/utilities/isPolymorphicRelationship.js.map +1 -0
- package/dist/utilities/isUUIDType.d.ts +2 -0
- package/dist/utilities/isUUIDType.d.ts.map +1 -0
- package/dist/utilities/isUUIDType.js +3 -0
- package/dist/utilities/isUUIDType.js.map +1 -0
- package/dist/utilities/isValidStringID.d.ts +2 -0
- package/dist/utilities/isValidStringID.d.ts.map +1 -0
- package/dist/utilities/isValidStringID.js +5 -0
- package/dist/utilities/isValidStringID.js.map +1 -0
- package/dist/utilities/isValidStringID.spec.js +15 -0
- package/dist/utilities/isValidStringID.spec.js.map +1 -0
- package/dist/utilities/json.d.ts +9 -0
- package/dist/utilities/json.d.ts.map +1 -0
- package/dist/utilities/json.js +33 -0
- package/dist/utilities/json.js.map +1 -0
- package/dist/utilities/migrationTableExists.d.ts +4 -0
- package/dist/utilities/migrationTableExists.d.ts.map +1 -0
- package/dist/utilities/migrationTableExists.js +25 -0
- package/dist/utilities/migrationTableExists.js.map +1 -0
- package/dist/utilities/parseError.d.ts +5 -0
- package/dist/utilities/parseError.d.ts.map +1 -0
- package/dist/utilities/parseError.js +15 -0
- package/dist/utilities/parseError.js.map +1 -0
- package/dist/utilities/pushDevSchema.d.ts +9 -0
- package/dist/utilities/pushDevSchema.d.ts.map +1 -0
- package/dist/utilities/pushDevSchema.js +83 -0
- package/dist/utilities/pushDevSchema.js.map +1 -0
- package/dist/utilities/rawConstraint.d.ts +10 -0
- package/dist/utilities/rawConstraint.d.ts.map +1 -0
- package/dist/utilities/rawConstraint.js +13 -0
- package/dist/utilities/rawConstraint.js.map +1 -0
- package/dist/utilities/readAfterWrite.d.ts +17 -0
- package/dist/utilities/readAfterWrite.d.ts.map +1 -0
- package/dist/utilities/readAfterWrite.js +21 -0
- package/dist/utilities/readAfterWrite.js.map +1 -0
- package/dist/utilities/sanitizePathSegment.d.ts +2 -0
- package/dist/utilities/sanitizePathSegment.d.ts.map +1 -0
- package/dist/utilities/sanitizePathSegment.js +14 -0
- package/dist/utilities/sanitizePathSegment.js.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +22 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js +100 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,810 @@
|
|
|
1
|
+
import { InvalidConfiguration } from '@hanzo/cms';
|
|
2
|
+
import { fieldAffectsData, fieldIsVirtual, fieldShouldBeLocalized, optionIsObject } from '@hanzo/cms/shared';
|
|
3
|
+
import toSnakeCase from 'to-snake-case';
|
|
4
|
+
import { createTableName } from '../createTableName.js';
|
|
5
|
+
import { buildIndexName } from '../utilities/buildIndexName.js';
|
|
6
|
+
import { getArrayRelationName } from '../utilities/getArrayRelationName.js';
|
|
7
|
+
import { hasLocalesTable } from '../utilities/hasLocalesTable.js';
|
|
8
|
+
import { isUUIDType } from '../utilities/isUUIDType.js';
|
|
9
|
+
import { InternalBlockTableNameIndex, setInternalBlockIndex, validateExistingBlockIsIdentical } from '../utilities/validateExistingBlockIsIdentical.js';
|
|
10
|
+
import { buildTable } from './build.js';
|
|
11
|
+
import { idToUUID } from './idToUUID.js';
|
|
12
|
+
import { withDefault } from './withDefault.js';
|
|
13
|
+
export const traverseFields = ({ adapter, blocksTableNameMap, columnPrefix, columns, disableNotNull, disableRelsTableUnique, disableUnique = false, fieldPrefix, fields, forceLocalized, indexes, localesColumns, localesIndexes, newTableName, parentIsLocalized, parentTableName, relationships, relationsToBuild, rootRelationsToBuild, rootTableIDColType, rootTableName, setColumnID, uniqueRelationships, versions, withinLocalizedArrayOrBlock })=>{
|
|
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
|
+
const idColumn = columns.id;
|
|
23
|
+
if (idColumn && [
|
|
24
|
+
'numeric',
|
|
25
|
+
'text',
|
|
26
|
+
'uuid',
|
|
27
|
+
'varchar'
|
|
28
|
+
].includes(idColumn.type)) {
|
|
29
|
+
parentIDColType = idColumn.type;
|
|
30
|
+
}
|
|
31
|
+
fields.forEach((field)=>{
|
|
32
|
+
if ('name' in field && field.name === 'id') {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (fieldIsVirtual(field)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let targetTable = columns;
|
|
39
|
+
let targetIndexes = indexes;
|
|
40
|
+
const columnName = `${columnPrefix || ''}${field.name[0] === '_' ? '_' : ''}${toSnakeCase(field.name)}`;
|
|
41
|
+
const fieldName = `${fieldPrefix?.replace('.', '_') || ''}${field.name}`;
|
|
42
|
+
const isFieldLocalized = fieldShouldBeLocalized({
|
|
43
|
+
field,
|
|
44
|
+
parentIsLocalized
|
|
45
|
+
});
|
|
46
|
+
// If field is localized,
|
|
47
|
+
// add the column to the locale table instead of main table
|
|
48
|
+
if (adapter.cms.config.localization && (isFieldLocalized || forceLocalized) && field.type !== 'array' && (field.type !== 'blocks' || adapter.blocksAsJSON) && ('hasMany' in field && field.hasMany !== true || !('hasMany' in field))) {
|
|
49
|
+
hasLocalizedField = true;
|
|
50
|
+
targetTable = localesColumns;
|
|
51
|
+
targetIndexes = localesIndexes;
|
|
52
|
+
}
|
|
53
|
+
if ((field.unique || field.index || [
|
|
54
|
+
'relationship',
|
|
55
|
+
'upload'
|
|
56
|
+
].includes(field.type)) && ![
|
|
57
|
+
'array',
|
|
58
|
+
'blocks',
|
|
59
|
+
'group'
|
|
60
|
+
].includes(field.type) && !('hasMany' in field && field.hasMany === true) && !('relationTo' in field && Array.isArray(field.relationTo))) {
|
|
61
|
+
const unique = disableUnique !== true && field.unique;
|
|
62
|
+
if (unique) {
|
|
63
|
+
const constraintValue = `${fieldPrefix || ''}${field.name}`;
|
|
64
|
+
if (!adapter.fieldConstraints?.[rootTableName]) {
|
|
65
|
+
adapter.fieldConstraints[rootTableName] = {};
|
|
66
|
+
}
|
|
67
|
+
adapter.fieldConstraints[rootTableName][`${columnName}_idx`] = constraintValue;
|
|
68
|
+
}
|
|
69
|
+
const indexName = buildIndexName({
|
|
70
|
+
name: `${newTableName}_${columnName}`,
|
|
71
|
+
adapter
|
|
72
|
+
});
|
|
73
|
+
targetIndexes[indexName] = {
|
|
74
|
+
name: indexName,
|
|
75
|
+
on: isFieldLocalized ? [
|
|
76
|
+
fieldName,
|
|
77
|
+
'_locale'
|
|
78
|
+
] : fieldName,
|
|
79
|
+
unique
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
switch(field.type){
|
|
83
|
+
case 'array':
|
|
84
|
+
{
|
|
85
|
+
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
|
86
|
+
const arrayTableName = createTableName({
|
|
87
|
+
adapter,
|
|
88
|
+
config: field,
|
|
89
|
+
parentTableName: newTableName,
|
|
90
|
+
prefix: `${newTableName}_`,
|
|
91
|
+
throwValidationError,
|
|
92
|
+
versionsCustomName: versions
|
|
93
|
+
});
|
|
94
|
+
const baseColumns = {
|
|
95
|
+
_order: {
|
|
96
|
+
name: '_order',
|
|
97
|
+
type: 'integer',
|
|
98
|
+
notNull: true
|
|
99
|
+
},
|
|
100
|
+
_parentID: {
|
|
101
|
+
name: '_parent_id',
|
|
102
|
+
type: parentIDColType,
|
|
103
|
+
notNull: true
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const baseIndexes = {
|
|
107
|
+
_orderIdx: {
|
|
108
|
+
name: `${arrayTableName}_order_idx`,
|
|
109
|
+
on: [
|
|
110
|
+
'_order'
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
_parentIDIdx: {
|
|
114
|
+
name: `${arrayTableName}_parent_id_idx`,
|
|
115
|
+
on: '_parentID'
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const baseForeignKeys = {
|
|
119
|
+
_parentIDFk: {
|
|
120
|
+
name: `${arrayTableName}_parent_id_fk`,
|
|
121
|
+
columns: [
|
|
122
|
+
'_parentID'
|
|
123
|
+
],
|
|
124
|
+
foreignColumns: [
|
|
125
|
+
{
|
|
126
|
+
name: 'id',
|
|
127
|
+
table: parentTableName
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
onDelete: 'cascade'
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const isLocalized = Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
134
|
+
if (isLocalized) {
|
|
135
|
+
baseColumns._locale = {
|
|
136
|
+
name: '_locale',
|
|
137
|
+
type: 'enum',
|
|
138
|
+
locale: true,
|
|
139
|
+
notNull: true
|
|
140
|
+
};
|
|
141
|
+
baseIndexes._localeIdx = {
|
|
142
|
+
name: `${arrayTableName}_locale_idx`,
|
|
143
|
+
on: '_locale'
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
147
|
+
adapter,
|
|
148
|
+
baseColumns,
|
|
149
|
+
baseForeignKeys,
|
|
150
|
+
baseIndexes,
|
|
151
|
+
blocksTableNameMap,
|
|
152
|
+
disableNotNull: disableNotNullFromHere,
|
|
153
|
+
disableRelsTableUnique: true,
|
|
154
|
+
disableUnique,
|
|
155
|
+
fields: disableUnique ? idToUUID(field.flattenedFields) : field.flattenedFields,
|
|
156
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
157
|
+
rootRelationships: relationships,
|
|
158
|
+
rootRelationsToBuild,
|
|
159
|
+
rootTableIDColType,
|
|
160
|
+
rootTableName,
|
|
161
|
+
rootUniqueRelationships: uniqueRelationships,
|
|
162
|
+
setColumnID,
|
|
163
|
+
tableName: arrayTableName,
|
|
164
|
+
versions,
|
|
165
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
166
|
+
});
|
|
167
|
+
if (subHasLocalizedManyNumberField) {
|
|
168
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
169
|
+
}
|
|
170
|
+
if (subHasLocalizedRelationshipField) {
|
|
171
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
172
|
+
}
|
|
173
|
+
if (subHasLocalizedManyTextField) {
|
|
174
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
175
|
+
}
|
|
176
|
+
if (subHasManyTextField) {
|
|
177
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
178
|
+
hasManyTextField = subHasManyTextField;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (subHasManyNumberField) {
|
|
182
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
183
|
+
hasManyNumberField = subHasManyNumberField;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const relationName = getArrayRelationName({
|
|
187
|
+
field,
|
|
188
|
+
path: fieldName,
|
|
189
|
+
tableName: arrayTableName
|
|
190
|
+
});
|
|
191
|
+
relationsToBuild.set(relationName, {
|
|
192
|
+
type: 'many',
|
|
193
|
+
// arrays have their own localized table, independent of the base table.
|
|
194
|
+
localized: false,
|
|
195
|
+
target: arrayTableName
|
|
196
|
+
});
|
|
197
|
+
const arrayRelations = {
|
|
198
|
+
_parentID: {
|
|
199
|
+
type: 'one',
|
|
200
|
+
fields: [
|
|
201
|
+
{
|
|
202
|
+
name: '_parentID',
|
|
203
|
+
table: arrayTableName
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
references: [
|
|
207
|
+
'id'
|
|
208
|
+
],
|
|
209
|
+
relationName,
|
|
210
|
+
to: parentTableName
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
if (hasLocalesTable({
|
|
214
|
+
fields: field.fields,
|
|
215
|
+
parentIsLocalized: parentIsLocalized || field.localized
|
|
216
|
+
})) {
|
|
217
|
+
arrayRelations._locales = {
|
|
218
|
+
type: 'many',
|
|
219
|
+
relationName: '_locales',
|
|
220
|
+
to: `${arrayTableName}${adapter.localesSuffix}`
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
|
224
|
+
if (type === 'one') {
|
|
225
|
+
const arrayWithLocalized = localized ? `${arrayTableName}${adapter.localesSuffix}` : arrayTableName;
|
|
226
|
+
arrayRelations[key] = {
|
|
227
|
+
type: 'one',
|
|
228
|
+
fields: [
|
|
229
|
+
{
|
|
230
|
+
name: key,
|
|
231
|
+
table: arrayWithLocalized
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
references: [
|
|
235
|
+
'id'
|
|
236
|
+
],
|
|
237
|
+
relationName: key,
|
|
238
|
+
to: target
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (type === 'many') {
|
|
242
|
+
arrayRelations[key] = {
|
|
243
|
+
type: 'many',
|
|
244
|
+
relationName: key,
|
|
245
|
+
to: target
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
adapter.rawRelations[arrayTableName] = arrayRelations;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'blocks':
|
|
253
|
+
{
|
|
254
|
+
if (adapter.blocksAsJSON) {
|
|
255
|
+
targetTable[fieldName] = withDefault({
|
|
256
|
+
name: columnName,
|
|
257
|
+
type: 'jsonb'
|
|
258
|
+
}, field);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
|
262
|
+
(field.blockReferences ?? field.blocks).forEach((_block)=>{
|
|
263
|
+
const block = typeof _block === 'string' ? adapter.cms.blocks[_block] : _block;
|
|
264
|
+
let blockTableName = createTableName({
|
|
265
|
+
adapter,
|
|
266
|
+
config: block,
|
|
267
|
+
parentTableName: rootTableName,
|
|
268
|
+
prefix: `${rootTableName}_blocks_`,
|
|
269
|
+
throwValidationError,
|
|
270
|
+
versionsCustomName: versions
|
|
271
|
+
});
|
|
272
|
+
if (typeof blocksTableNameMap[blockTableName] === 'undefined') {
|
|
273
|
+
blocksTableNameMap[blockTableName] = 1;
|
|
274
|
+
} else if (!adapter.rawTables[blockTableName] || !validateExistingBlockIsIdentical({
|
|
275
|
+
block,
|
|
276
|
+
localized: field.localized,
|
|
277
|
+
rootTableName,
|
|
278
|
+
table: adapter.rawTables[blockTableName],
|
|
279
|
+
tableLocales: adapter.rawTables[`${blockTableName}${adapter.localesSuffix}`]
|
|
280
|
+
})) {
|
|
281
|
+
blocksTableNameMap[blockTableName]++;
|
|
282
|
+
setInternalBlockIndex(block, blocksTableNameMap[blockTableName]);
|
|
283
|
+
blockTableName = `${blockTableName}_${blocksTableNameMap[blockTableName]}`;
|
|
284
|
+
}
|
|
285
|
+
let relationName = `_blocks_${block.slug}`;
|
|
286
|
+
if (typeof block[InternalBlockTableNameIndex] !== 'undefined') {
|
|
287
|
+
relationName = `_blocks_${block.slug}_${block[InternalBlockTableNameIndex]}`;
|
|
288
|
+
}
|
|
289
|
+
if (!adapter.rawTables[blockTableName]) {
|
|
290
|
+
const baseColumns = {
|
|
291
|
+
_order: {
|
|
292
|
+
name: '_order',
|
|
293
|
+
type: 'integer',
|
|
294
|
+
notNull: true
|
|
295
|
+
},
|
|
296
|
+
_parentID: {
|
|
297
|
+
name: '_parent_id',
|
|
298
|
+
type: rootTableIDColType,
|
|
299
|
+
notNull: true
|
|
300
|
+
},
|
|
301
|
+
_path: {
|
|
302
|
+
name: '_path',
|
|
303
|
+
type: 'text',
|
|
304
|
+
notNull: true
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const baseIndexes = {
|
|
308
|
+
_orderIdx: {
|
|
309
|
+
name: `${blockTableName}_order_idx`,
|
|
310
|
+
on: '_order'
|
|
311
|
+
},
|
|
312
|
+
_parentIDIdx: {
|
|
313
|
+
name: `${blockTableName}_parent_id_idx`,
|
|
314
|
+
on: [
|
|
315
|
+
'_parentID'
|
|
316
|
+
]
|
|
317
|
+
},
|
|
318
|
+
_pathIdx: {
|
|
319
|
+
name: `${blockTableName}_path_idx`,
|
|
320
|
+
on: '_path'
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const baseForeignKeys = {
|
|
324
|
+
_parentIdFk: {
|
|
325
|
+
name: `${blockTableName}_parent_id_fk`,
|
|
326
|
+
columns: [
|
|
327
|
+
'_parentID'
|
|
328
|
+
],
|
|
329
|
+
foreignColumns: [
|
|
330
|
+
{
|
|
331
|
+
name: 'id',
|
|
332
|
+
table: rootTableName
|
|
333
|
+
}
|
|
334
|
+
],
|
|
335
|
+
onDelete: 'cascade'
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
const isLocalized = Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
339
|
+
if (isLocalized) {
|
|
340
|
+
baseColumns._locale = {
|
|
341
|
+
name: '_locale',
|
|
342
|
+
type: 'enum',
|
|
343
|
+
locale: true,
|
|
344
|
+
notNull: true
|
|
345
|
+
};
|
|
346
|
+
baseIndexes._localeIdx = {
|
|
347
|
+
name: `${blockTableName}_locale_idx`,
|
|
348
|
+
on: '_locale'
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const { hasLocalizedManyNumberField: subHasLocalizedManyNumberField, hasLocalizedManyTextField: subHasLocalizedManyTextField, hasLocalizedRelationshipField: subHasLocalizedRelationshipField, hasManyNumberField: subHasManyNumberField, hasManyTextField: subHasManyTextField, relationsToBuild: subRelationsToBuild } = buildTable({
|
|
352
|
+
adapter,
|
|
353
|
+
baseColumns,
|
|
354
|
+
baseForeignKeys,
|
|
355
|
+
baseIndexes,
|
|
356
|
+
blocksTableNameMap,
|
|
357
|
+
disableNotNull: disableNotNullFromHere,
|
|
358
|
+
disableRelsTableUnique: true,
|
|
359
|
+
disableUnique,
|
|
360
|
+
fields: disableUnique ? idToUUID(block.flattenedFields) : block.flattenedFields,
|
|
361
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
362
|
+
rootRelationships: relationships,
|
|
363
|
+
rootRelationsToBuild,
|
|
364
|
+
rootTableIDColType,
|
|
365
|
+
rootTableName,
|
|
366
|
+
rootUniqueRelationships: uniqueRelationships,
|
|
367
|
+
setColumnID,
|
|
368
|
+
tableName: blockTableName,
|
|
369
|
+
versions,
|
|
370
|
+
withinLocalizedArrayOrBlock: isLocalized
|
|
371
|
+
});
|
|
372
|
+
if (subHasLocalizedManyNumberField) {
|
|
373
|
+
hasLocalizedManyNumberField = subHasLocalizedManyNumberField;
|
|
374
|
+
}
|
|
375
|
+
if (subHasLocalizedRelationshipField) {
|
|
376
|
+
hasLocalizedRelationshipField = subHasLocalizedRelationshipField;
|
|
377
|
+
}
|
|
378
|
+
if (subHasLocalizedManyTextField) {
|
|
379
|
+
hasLocalizedManyTextField = subHasLocalizedManyTextField;
|
|
380
|
+
}
|
|
381
|
+
if (subHasManyTextField) {
|
|
382
|
+
if (!hasManyTextField || subHasManyTextField === 'index') {
|
|
383
|
+
hasManyTextField = subHasManyTextField;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (subHasManyNumberField) {
|
|
387
|
+
if (!hasManyNumberField || subHasManyNumberField === 'index') {
|
|
388
|
+
hasManyNumberField = subHasManyNumberField;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const blockRelations = {
|
|
392
|
+
_parentID: {
|
|
393
|
+
type: 'one',
|
|
394
|
+
fields: [
|
|
395
|
+
{
|
|
396
|
+
name: '_parentID',
|
|
397
|
+
table: blockTableName
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
references: [
|
|
401
|
+
'id'
|
|
402
|
+
],
|
|
403
|
+
relationName,
|
|
404
|
+
to: rootTableName
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
if (hasLocalesTable({
|
|
408
|
+
fields: block.fields,
|
|
409
|
+
parentIsLocalized: parentIsLocalized || field.localized
|
|
410
|
+
})) {
|
|
411
|
+
blockRelations._locales = {
|
|
412
|
+
type: 'many',
|
|
413
|
+
relationName: '_locales',
|
|
414
|
+
to: `${blockTableName}${adapter.localesSuffix}`
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
subRelationsToBuild.forEach(({ type, localized, target }, key)=>{
|
|
418
|
+
if (type === 'one') {
|
|
419
|
+
const blockWithLocalized = localized ? `${blockTableName}${adapter.localesSuffix}` : blockTableName;
|
|
420
|
+
blockRelations[key] = {
|
|
421
|
+
type: 'one',
|
|
422
|
+
fields: [
|
|
423
|
+
{
|
|
424
|
+
name: key,
|
|
425
|
+
table: blockWithLocalized
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
references: [
|
|
429
|
+
'id'
|
|
430
|
+
],
|
|
431
|
+
relationName: key,
|
|
432
|
+
to: target
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
if (type === 'many') {
|
|
436
|
+
blockRelations[key] = {
|
|
437
|
+
type: 'many',
|
|
438
|
+
relationName: key,
|
|
439
|
+
to: target
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
adapter.rawRelations[blockTableName] = blockRelations;
|
|
444
|
+
}
|
|
445
|
+
// blocks relationships are defined from the collection or globals table down to the block, bypassing any subBlocks
|
|
446
|
+
rootRelationsToBuild.set(relationName, {
|
|
447
|
+
type: 'many',
|
|
448
|
+
// blocks are not localized on the parent table
|
|
449
|
+
localized: false,
|
|
450
|
+
target: blockTableName
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
case 'checkbox':
|
|
456
|
+
{
|
|
457
|
+
targetTable[fieldName] = withDefault({
|
|
458
|
+
name: columnName,
|
|
459
|
+
type: 'boolean'
|
|
460
|
+
}, field);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case 'code':
|
|
464
|
+
case 'email':
|
|
465
|
+
case 'textarea':
|
|
466
|
+
{
|
|
467
|
+
targetTable[fieldName] = withDefault({
|
|
468
|
+
name: columnName,
|
|
469
|
+
type: 'varchar'
|
|
470
|
+
}, field);
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
case 'date':
|
|
474
|
+
{
|
|
475
|
+
targetTable[fieldName] = withDefault({
|
|
476
|
+
name: columnName,
|
|
477
|
+
type: 'timestamp',
|
|
478
|
+
mode: 'string',
|
|
479
|
+
precision: 3,
|
|
480
|
+
withTimezone: true
|
|
481
|
+
}, field);
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
case 'group':
|
|
485
|
+
case 'tab':
|
|
486
|
+
{
|
|
487
|
+
const disableNotNullFromHere = Boolean(field.admin?.condition) || disableNotNull;
|
|
488
|
+
const { hasLocalizedField: groupHasLocalizedField, hasLocalizedManyNumberField: groupHasLocalizedManyNumberField, hasLocalizedManyTextField: groupHasLocalizedManyTextField, hasLocalizedRelationshipField: groupHasLocalizedRelationshipField, hasManyNumberField: groupHasManyNumberField, hasManyTextField: groupHasManyTextField } = traverseFields({
|
|
489
|
+
adapter,
|
|
490
|
+
blocksTableNameMap,
|
|
491
|
+
columnPrefix: `${columnName}_`,
|
|
492
|
+
columns,
|
|
493
|
+
disableNotNull: disableNotNullFromHere,
|
|
494
|
+
disableUnique,
|
|
495
|
+
fieldPrefix: `${fieldName}.`,
|
|
496
|
+
fields: field.flattenedFields,
|
|
497
|
+
forceLocalized: isFieldLocalized || Boolean(forceLocalized),
|
|
498
|
+
indexes,
|
|
499
|
+
localesColumns,
|
|
500
|
+
localesIndexes,
|
|
501
|
+
newTableName: `${parentTableName}_${columnName}`,
|
|
502
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
503
|
+
parentTableName,
|
|
504
|
+
relationships,
|
|
505
|
+
relationsToBuild,
|
|
506
|
+
rootRelationsToBuild,
|
|
507
|
+
rootTableIDColType,
|
|
508
|
+
rootTableName,
|
|
509
|
+
setColumnID,
|
|
510
|
+
uniqueRelationships,
|
|
511
|
+
versions,
|
|
512
|
+
withinLocalizedArrayOrBlock: withinLocalizedArrayOrBlock || isFieldLocalized
|
|
513
|
+
});
|
|
514
|
+
if (groupHasLocalizedField) {
|
|
515
|
+
hasLocalizedField = true;
|
|
516
|
+
}
|
|
517
|
+
if (groupHasLocalizedRelationshipField) {
|
|
518
|
+
hasLocalizedRelationshipField = true;
|
|
519
|
+
}
|
|
520
|
+
if (groupHasManyTextField) {
|
|
521
|
+
hasManyTextField = true;
|
|
522
|
+
}
|
|
523
|
+
if (groupHasLocalizedManyTextField) {
|
|
524
|
+
hasLocalizedManyTextField = true;
|
|
525
|
+
}
|
|
526
|
+
if (groupHasManyNumberField) {
|
|
527
|
+
hasManyNumberField = true;
|
|
528
|
+
}
|
|
529
|
+
if (groupHasLocalizedManyNumberField) {
|
|
530
|
+
hasLocalizedManyNumberField = true;
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
case 'json':
|
|
535
|
+
case 'richText':
|
|
536
|
+
{
|
|
537
|
+
targetTable[fieldName] = withDefault({
|
|
538
|
+
name: columnName,
|
|
539
|
+
type: 'jsonb'
|
|
540
|
+
}, field);
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
case 'number':
|
|
544
|
+
{
|
|
545
|
+
if (field.hasMany) {
|
|
546
|
+
const isLocalized = Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
547
|
+
if (isLocalized) {
|
|
548
|
+
hasLocalizedManyNumberField = true;
|
|
549
|
+
}
|
|
550
|
+
if (field.index) {
|
|
551
|
+
hasManyNumberField = 'index';
|
|
552
|
+
} else if (!hasManyNumberField) {
|
|
553
|
+
hasManyNumberField = true;
|
|
554
|
+
}
|
|
555
|
+
if (field.unique) {
|
|
556
|
+
throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany number fields.');
|
|
557
|
+
}
|
|
558
|
+
} else {
|
|
559
|
+
targetTable[fieldName] = withDefault({
|
|
560
|
+
name: columnName,
|
|
561
|
+
type: 'numeric'
|
|
562
|
+
}, field);
|
|
563
|
+
}
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
case 'point':
|
|
567
|
+
{
|
|
568
|
+
targetTable[fieldName] = withDefault({
|
|
569
|
+
name: columnName,
|
|
570
|
+
type: 'geometry'
|
|
571
|
+
}, field);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case 'radio':
|
|
575
|
+
case 'select':
|
|
576
|
+
{
|
|
577
|
+
const enumName = createTableName({
|
|
578
|
+
adapter,
|
|
579
|
+
config: field,
|
|
580
|
+
parentTableName: newTableName,
|
|
581
|
+
prefix: `enum_${newTableName}_`,
|
|
582
|
+
target: 'enumName',
|
|
583
|
+
throwValidationError
|
|
584
|
+
});
|
|
585
|
+
const options = field.options.map((option)=>{
|
|
586
|
+
if (optionIsObject(option)) {
|
|
587
|
+
return option.value;
|
|
588
|
+
}
|
|
589
|
+
return option;
|
|
590
|
+
});
|
|
591
|
+
if (field.type === 'select' && field.hasMany) {
|
|
592
|
+
const selectTableName = createTableName({
|
|
593
|
+
adapter,
|
|
594
|
+
config: field,
|
|
595
|
+
parentTableName: newTableName,
|
|
596
|
+
prefix: `${newTableName}_`,
|
|
597
|
+
throwValidationError,
|
|
598
|
+
versionsCustomName: versions
|
|
599
|
+
});
|
|
600
|
+
const baseColumns = {
|
|
601
|
+
order: {
|
|
602
|
+
name: 'order',
|
|
603
|
+
type: 'integer',
|
|
604
|
+
notNull: true
|
|
605
|
+
},
|
|
606
|
+
parent: {
|
|
607
|
+
name: 'parent_id',
|
|
608
|
+
type: parentIDColType,
|
|
609
|
+
notNull: true
|
|
610
|
+
},
|
|
611
|
+
value: {
|
|
612
|
+
name: 'value',
|
|
613
|
+
type: 'enum',
|
|
614
|
+
enumName: createTableName({
|
|
615
|
+
adapter,
|
|
616
|
+
config: field,
|
|
617
|
+
parentTableName: newTableName,
|
|
618
|
+
prefix: `enum_${newTableName}_`,
|
|
619
|
+
target: 'enumName',
|
|
620
|
+
throwValidationError
|
|
621
|
+
}),
|
|
622
|
+
options
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
const baseIndexes = {
|
|
626
|
+
orderIdx: {
|
|
627
|
+
name: `${selectTableName}_order_idx`,
|
|
628
|
+
on: 'order'
|
|
629
|
+
},
|
|
630
|
+
parentIdx: {
|
|
631
|
+
name: `${selectTableName}_parent_idx`,
|
|
632
|
+
on: 'parent'
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
const baseForeignKeys = {
|
|
636
|
+
parentFk: {
|
|
637
|
+
name: `${selectTableName}_parent_fk`,
|
|
638
|
+
columns: [
|
|
639
|
+
'parent'
|
|
640
|
+
],
|
|
641
|
+
foreignColumns: [
|
|
642
|
+
{
|
|
643
|
+
name: 'id',
|
|
644
|
+
table: parentTableName
|
|
645
|
+
}
|
|
646
|
+
],
|
|
647
|
+
onDelete: 'cascade'
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
const isLocalized = Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
651
|
+
if (isLocalized) {
|
|
652
|
+
baseColumns.locale = {
|
|
653
|
+
name: 'locale',
|
|
654
|
+
type: 'enum',
|
|
655
|
+
locale: true,
|
|
656
|
+
notNull: true
|
|
657
|
+
};
|
|
658
|
+
baseIndexes.localeIdx = {
|
|
659
|
+
name: `${selectTableName}_locale_idx`,
|
|
660
|
+
on: 'locale'
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
if (field.index) {
|
|
664
|
+
baseIndexes.value = {
|
|
665
|
+
name: `${selectTableName}_value_idx`,
|
|
666
|
+
on: 'value'
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
buildTable({
|
|
670
|
+
adapter,
|
|
671
|
+
baseColumns,
|
|
672
|
+
baseForeignKeys,
|
|
673
|
+
baseIndexes,
|
|
674
|
+
blocksTableNameMap,
|
|
675
|
+
disableNotNull,
|
|
676
|
+
disableUnique,
|
|
677
|
+
fields: [],
|
|
678
|
+
parentIsLocalized: parentIsLocalized || field.localized,
|
|
679
|
+
rootTableName,
|
|
680
|
+
setColumnID,
|
|
681
|
+
tableName: selectTableName,
|
|
682
|
+
versions
|
|
683
|
+
});
|
|
684
|
+
relationsToBuild.set(fieldName, {
|
|
685
|
+
type: 'many',
|
|
686
|
+
// selects have their own localized table, independent of the base table.
|
|
687
|
+
localized: false,
|
|
688
|
+
target: selectTableName
|
|
689
|
+
});
|
|
690
|
+
adapter.rawRelations[selectTableName] = {
|
|
691
|
+
parent: {
|
|
692
|
+
type: 'one',
|
|
693
|
+
fields: [
|
|
694
|
+
{
|
|
695
|
+
name: 'parent',
|
|
696
|
+
table: selectTableName
|
|
697
|
+
}
|
|
698
|
+
],
|
|
699
|
+
references: [
|
|
700
|
+
'id'
|
|
701
|
+
],
|
|
702
|
+
relationName: fieldName,
|
|
703
|
+
to: parentTableName
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
} else {
|
|
707
|
+
targetTable[fieldName] = withDefault({
|
|
708
|
+
name: columnName,
|
|
709
|
+
type: 'enum',
|
|
710
|
+
enumName,
|
|
711
|
+
options
|
|
712
|
+
}, field);
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
case 'relationship':
|
|
717
|
+
case 'upload':
|
|
718
|
+
if (Array.isArray(field.relationTo)) {
|
|
719
|
+
field.relationTo.forEach((relation)=>{
|
|
720
|
+
relationships.add(relation);
|
|
721
|
+
if (field.unique && !disableUnique && !disableRelsTableUnique) {
|
|
722
|
+
uniqueRelationships.add(relation);
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
} else if (field.hasMany) {
|
|
726
|
+
relationships.add(field.relationTo);
|
|
727
|
+
if (field.unique && !disableUnique && !disableRelsTableUnique) {
|
|
728
|
+
uniqueRelationships.add(field.relationTo);
|
|
729
|
+
}
|
|
730
|
+
} else {
|
|
731
|
+
// simple relationships get a column on the targetTable with a foreign key to the relationTo table
|
|
732
|
+
const relationshipConfig = adapter.cms.collections[field.relationTo].config;
|
|
733
|
+
const tableName = adapter.tableNameMap.get(toSnakeCase(field.relationTo));
|
|
734
|
+
// get the id type of the related collection
|
|
735
|
+
let colType = isUUIDType(adapter.idType) ? 'uuid' : 'integer';
|
|
736
|
+
const relatedCollectionCustomID = relationshipConfig.fields.find((field)=>fieldAffectsData(field) && field.name === 'id');
|
|
737
|
+
if (relatedCollectionCustomID?.type === 'number') {
|
|
738
|
+
colType = 'numeric';
|
|
739
|
+
}
|
|
740
|
+
if (relatedCollectionCustomID?.type === 'text') {
|
|
741
|
+
colType = 'varchar';
|
|
742
|
+
}
|
|
743
|
+
// make the foreign key column for relationship using the correct id column type
|
|
744
|
+
targetTable[fieldName] = {
|
|
745
|
+
name: `${columnName}_id`,
|
|
746
|
+
type: colType,
|
|
747
|
+
reference: {
|
|
748
|
+
name: 'id',
|
|
749
|
+
onDelete: 'set null',
|
|
750
|
+
table: tableName
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
// add relationship to table
|
|
754
|
+
relationsToBuild.set(fieldName, {
|
|
755
|
+
type: 'one',
|
|
756
|
+
localized: adapter.cms.config.localization && (isFieldLocalized || forceLocalized),
|
|
757
|
+
target: tableName
|
|
758
|
+
});
|
|
759
|
+
// add notNull when not required
|
|
760
|
+
if (!disableNotNull && field.required && !field.admin?.condition) {
|
|
761
|
+
targetTable[fieldName].notNull = true;
|
|
762
|
+
}
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
if (Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock) {
|
|
766
|
+
hasLocalizedRelationshipField = true;
|
|
767
|
+
}
|
|
768
|
+
break;
|
|
769
|
+
case 'text':
|
|
770
|
+
{
|
|
771
|
+
if (field.hasMany) {
|
|
772
|
+
const isLocalized = Boolean(isFieldLocalized && adapter.cms.config.localization) || withinLocalizedArrayOrBlock || forceLocalized;
|
|
773
|
+
if (isLocalized) {
|
|
774
|
+
hasLocalizedManyTextField = true;
|
|
775
|
+
}
|
|
776
|
+
if (field.index) {
|
|
777
|
+
hasManyTextField = 'index';
|
|
778
|
+
} else if (!hasManyTextField) {
|
|
779
|
+
hasManyTextField = true;
|
|
780
|
+
}
|
|
781
|
+
if (field.unique) {
|
|
782
|
+
throw new InvalidConfiguration('Unique is not supported in Postgres for hasMany text fields.');
|
|
783
|
+
}
|
|
784
|
+
} else {
|
|
785
|
+
targetTable[fieldName] = withDefault({
|
|
786
|
+
name: columnName,
|
|
787
|
+
type: 'varchar'
|
|
788
|
+
}, field);
|
|
789
|
+
}
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
default:
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
const condition = field.admin && field.admin.condition;
|
|
796
|
+
if (!disableNotNull && targetTable[fieldName] && 'required' in field && field.required && !condition) {
|
|
797
|
+
targetTable[fieldName].notNull = true;
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
return {
|
|
801
|
+
hasLocalizedField,
|
|
802
|
+
hasLocalizedManyNumberField,
|
|
803
|
+
hasLocalizedManyTextField,
|
|
804
|
+
hasLocalizedRelationshipField,
|
|
805
|
+
hasManyNumberField,
|
|
806
|
+
hasManyTextField
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
//# sourceMappingURL=traverseFields.js.map
|