@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,587 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { APIError, buildVersionCollectionFields, buildVersionGlobalFields, dynamicImport } from '@hanzo/cms';
|
|
4
|
+
import { findConfig } from '@hanzo/cms/node';
|
|
5
|
+
import { fieldShouldBeLocalized } from '@hanzo/cms/shared';
|
|
6
|
+
import { getTransaction } from './getTransaction.js';
|
|
7
|
+
const DEFAULT_BATCH_SIZE = 100;
|
|
8
|
+
const TEMP_FOLDER_NAME = '.cms-blocks-migration';
|
|
9
|
+
const writeEntitiesToTempFile = (entities, tempFolderPath, batchIndex)=>{
|
|
10
|
+
const filePath = path.join(tempFolderPath, `entities-batch-${batchIndex}.json`);
|
|
11
|
+
writeFileSync(filePath, JSON.stringify(entities, null, 2), 'utf-8');
|
|
12
|
+
};
|
|
13
|
+
const acceptDrizzlePrompts = async (callPrompt, { silenceLogs = false } = {})=>{
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
15
|
+
const write = process.stdout.write;
|
|
16
|
+
if (silenceLogs) {
|
|
17
|
+
process.stdout.write = ()=>true;
|
|
18
|
+
}
|
|
19
|
+
const promise = callPrompt();
|
|
20
|
+
const interval = setInterval(()=>process.stdin.emit('keypress', '\n', {
|
|
21
|
+
name: 'return',
|
|
22
|
+
ctrl: false
|
|
23
|
+
}), 25);
|
|
24
|
+
const res = await promise;
|
|
25
|
+
if (silenceLogs) {
|
|
26
|
+
process.stdout.write = write;
|
|
27
|
+
}
|
|
28
|
+
clearInterval(interval);
|
|
29
|
+
return res;
|
|
30
|
+
};
|
|
31
|
+
const entityHasBlocksField = (entity)=>{
|
|
32
|
+
for (const field of entity.flattenedFields){
|
|
33
|
+
if (field.type === 'blocks') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if ('flattenedFields' in field && entityHasBlocksField({
|
|
37
|
+
flattenedFields: field.flattenedFields
|
|
38
|
+
})) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
const collectBlocksToMigrate = ({ config, data, fields, parentAccessor, parentIsLocalized })=>{
|
|
45
|
+
const result = [];
|
|
46
|
+
for (const field of fields){
|
|
47
|
+
switch(field.type){
|
|
48
|
+
case 'array':
|
|
49
|
+
{
|
|
50
|
+
const arrayData = data[field.name];
|
|
51
|
+
if (!Array.isArray(arrayData)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (config.localization && fieldShouldBeLocalized({
|
|
55
|
+
field,
|
|
56
|
+
parentIsLocalized
|
|
57
|
+
})) {
|
|
58
|
+
result.push(...collectBlocksToMigrate({
|
|
59
|
+
config,
|
|
60
|
+
data: arrayData,
|
|
61
|
+
fields: config.localization.localeCodes.map((code)=>({
|
|
62
|
+
...field,
|
|
63
|
+
name: code,
|
|
64
|
+
localized: false
|
|
65
|
+
})),
|
|
66
|
+
parentAccessor: [
|
|
67
|
+
...parentAccessor,
|
|
68
|
+
field.name
|
|
69
|
+
],
|
|
70
|
+
parentIsLocalized: true
|
|
71
|
+
}));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
for (const [index, row] of arrayData.entries()){
|
|
75
|
+
result.push(...collectBlocksToMigrate({
|
|
76
|
+
config,
|
|
77
|
+
data: row,
|
|
78
|
+
fields: field.flattenedFields,
|
|
79
|
+
parentAccessor: [
|
|
80
|
+
...parentAccessor,
|
|
81
|
+
field.name,
|
|
82
|
+
index
|
|
83
|
+
],
|
|
84
|
+
parentIsLocalized
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'blocks':
|
|
90
|
+
{
|
|
91
|
+
result.push({
|
|
92
|
+
data: data[field.name],
|
|
93
|
+
fieldAccessor: [
|
|
94
|
+
...parentAccessor,
|
|
95
|
+
field.name
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'group':
|
|
101
|
+
case 'tab':
|
|
102
|
+
{
|
|
103
|
+
if (config.localization && fieldShouldBeLocalized({
|
|
104
|
+
field,
|
|
105
|
+
parentIsLocalized
|
|
106
|
+
})) {
|
|
107
|
+
result.push(...collectBlocksToMigrate({
|
|
108
|
+
config,
|
|
109
|
+
data: data[field.name],
|
|
110
|
+
fields: config.localization.localeCodes.map((code)=>({
|
|
111
|
+
...field,
|
|
112
|
+
name: code,
|
|
113
|
+
localized: false
|
|
114
|
+
})),
|
|
115
|
+
parentAccessor: [
|
|
116
|
+
...parentAccessor,
|
|
117
|
+
field.name
|
|
118
|
+
],
|
|
119
|
+
parentIsLocalized: true
|
|
120
|
+
}));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
result.push(...collectBlocksToMigrate({
|
|
124
|
+
config,
|
|
125
|
+
data: data[field.name],
|
|
126
|
+
fields: field.flattenedFields,
|
|
127
|
+
parentAccessor: [
|
|
128
|
+
...parentAccessor,
|
|
129
|
+
field.name
|
|
130
|
+
],
|
|
131
|
+
parentIsLocalized
|
|
132
|
+
}));
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
default:
|
|
136
|
+
{
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
class BlocksToJsonMigratorImpl {
|
|
144
|
+
adapter;
|
|
145
|
+
sanitizeStatements;
|
|
146
|
+
executeMethod;
|
|
147
|
+
batchSize;
|
|
148
|
+
tempFolderPath;
|
|
149
|
+
constructor(adapter, sanitizeStatements, executeMethod, batchSize){
|
|
150
|
+
this.adapter = adapter;
|
|
151
|
+
this.sanitizeStatements = sanitizeStatements;
|
|
152
|
+
this.executeMethod = executeMethod;
|
|
153
|
+
this.batchSize = batchSize || DEFAULT_BATCH_SIZE;
|
|
154
|
+
this.tempFolderPath = path.resolve(this.adapter.migrationDir, TEMP_FOLDER_NAME);
|
|
155
|
+
}
|
|
156
|
+
ensureTempFolder() {
|
|
157
|
+
if (!existsSync(this.tempFolderPath)) {
|
|
158
|
+
mkdirSync(this.tempFolderPath, {
|
|
159
|
+
recursive: true
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
*fetchEntitiesFromJsonBatches() {
|
|
164
|
+
if (!existsSync(this.tempFolderPath)) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const files = readdirSync(this.tempFolderPath).filter((file)=>file.startsWith('entities-batch-') && file.endsWith('.json')).sort((a, b)=>{
|
|
168
|
+
const aNum = parseInt(a.match(/\d+/)?.[0] || '0', 10);
|
|
169
|
+
const bNum = parseInt(b.match(/\d+/)?.[0] || '0', 10);
|
|
170
|
+
return aNum - bNum;
|
|
171
|
+
});
|
|
172
|
+
for (const file of files){
|
|
173
|
+
const filePath = path.join(this.tempFolderPath, file);
|
|
174
|
+
const fileContent = readFileSync(filePath, 'utf-8');
|
|
175
|
+
const batchEntities = JSON.parse(fileContent);
|
|
176
|
+
yield batchEntities;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async migrateEntities(entities, req) {
|
|
180
|
+
this.adapter.blocksAsJSON = true;
|
|
181
|
+
this.resetSchema();
|
|
182
|
+
await this.adapter.init();
|
|
183
|
+
await this.adapter.connect();
|
|
184
|
+
await this.syncTransactionDrizzleInstance(req);
|
|
185
|
+
const totalEntities = entities.length;
|
|
186
|
+
let processed = 0;
|
|
187
|
+
for (const entity of entities){
|
|
188
|
+
switch(entity.type){
|
|
189
|
+
case 'collection':
|
|
190
|
+
{
|
|
191
|
+
await this.adapter.updateOne({
|
|
192
|
+
collection: entity.slug,
|
|
193
|
+
data: entity.originalData,
|
|
194
|
+
joins: false,
|
|
195
|
+
req,
|
|
196
|
+
where: {
|
|
197
|
+
id: {
|
|
198
|
+
equals: entity.id
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'collectionVersion':
|
|
205
|
+
{
|
|
206
|
+
await this.adapter.updateVersion({
|
|
207
|
+
id: entity.id,
|
|
208
|
+
collection: entity.slug,
|
|
209
|
+
req,
|
|
210
|
+
versionData: entity.originalData
|
|
211
|
+
});
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'global':
|
|
215
|
+
{
|
|
216
|
+
await this.adapter.updateGlobal({
|
|
217
|
+
slug: entity.slug,
|
|
218
|
+
data: entity.originalData,
|
|
219
|
+
req
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case 'globalVersion':
|
|
224
|
+
{
|
|
225
|
+
await this.adapter.updateGlobalVersion({
|
|
226
|
+
id: entity.id,
|
|
227
|
+
global: entity.slug,
|
|
228
|
+
req,
|
|
229
|
+
versionData: entity.originalData
|
|
230
|
+
});
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
processed++;
|
|
235
|
+
if (processed % this.batchSize === 0 || processed === totalEntities) {
|
|
236
|
+
this.adapter.cms.logger.info(`Migrated ${processed}/${totalEntities} entities (${Math.round(processed / totalEntities * 100)}%)`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
resetSchema() {
|
|
241
|
+
this.adapter.schema = {};
|
|
242
|
+
this.adapter.tables = {};
|
|
243
|
+
this.adapter.indexes = new Set();
|
|
244
|
+
this.adapter.foreignKeys = new Set();
|
|
245
|
+
this.adapter.relations = {};
|
|
246
|
+
this.adapter.rawTables = {};
|
|
247
|
+
this.adapter.rawRelations = {};
|
|
248
|
+
this.adapter.tableNameMap = new Map();
|
|
249
|
+
this.adapter.enums = {};
|
|
250
|
+
}
|
|
251
|
+
async syncTransactionDrizzleInstance(req) {
|
|
252
|
+
const tsx = await getTransaction(this.adapter, req);
|
|
253
|
+
tsx._ = this.adapter.drizzle._;
|
|
254
|
+
tsx.schema = this.adapter.drizzle._;
|
|
255
|
+
tsx.session.schema = this.adapter.drizzle.session.schema;
|
|
256
|
+
}
|
|
257
|
+
cleanupTempFolder() {
|
|
258
|
+
rmSync(this.tempFolderPath, {
|
|
259
|
+
force: true,
|
|
260
|
+
recursive: true
|
|
261
|
+
});
|
|
262
|
+
this.adapter.cms.logger.info(`Cleaned up temp folder at ${this.tempFolderPath}`);
|
|
263
|
+
}
|
|
264
|
+
async collectAndSaveEntitiesToBatches(req, options) {
|
|
265
|
+
const batchSize = options?.batchSize ?? this.batchSize;
|
|
266
|
+
this.cleanupTempFolder();
|
|
267
|
+
this.ensureTempFolder();
|
|
268
|
+
this.adapter.blocksAsJSON = false;
|
|
269
|
+
this.resetSchema();
|
|
270
|
+
await this.adapter.init();
|
|
271
|
+
await this.adapter.connect();
|
|
272
|
+
// Count total entities to migrate
|
|
273
|
+
let totalExpected = 0;
|
|
274
|
+
for (const collection of this.adapter.cms.config.collections.filter(entityHasBlocksField)){
|
|
275
|
+
const { totalDocs } = await this.adapter.count({
|
|
276
|
+
collection: collection.slug
|
|
277
|
+
});
|
|
278
|
+
totalExpected += totalDocs;
|
|
279
|
+
if (collection.versions) {
|
|
280
|
+
const { totalDocs: totalVersions } = await this.adapter.countVersions({
|
|
281
|
+
collection: collection.slug
|
|
282
|
+
});
|
|
283
|
+
totalExpected += totalVersions;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
for (const globalConfig of this.adapter.cms.config.globals.filter(entityHasBlocksField)){
|
|
287
|
+
totalExpected += 1; // Global itself
|
|
288
|
+
if (globalConfig.versions) {
|
|
289
|
+
const { totalDocs: totalGlobalVersions } = await this.adapter.countGlobalVersions({
|
|
290
|
+
global: globalConfig.slug
|
|
291
|
+
});
|
|
292
|
+
totalExpected += totalGlobalVersions;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
this.adapter.cms.logger.info(`Found ${totalExpected} total entities to collect and save to batches`);
|
|
296
|
+
let batchIndex = 0;
|
|
297
|
+
let currentBatch = [];
|
|
298
|
+
let totalCollected = 0;
|
|
299
|
+
const flushBatch = ()=>{
|
|
300
|
+
if (currentBatch.length > 0) {
|
|
301
|
+
writeEntitiesToTempFile(currentBatch, this.tempFolderPath, batchIndex);
|
|
302
|
+
const percentage = totalExpected > 0 ? Math.round(totalCollected / totalExpected * 100) : 0;
|
|
303
|
+
this.adapter.cms.logger.info(`Saved batch ${batchIndex} with ${currentBatch.length} entities (${totalCollected}/${totalExpected} - ${percentage}%)`);
|
|
304
|
+
batchIndex++;
|
|
305
|
+
currentBatch = [];
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const addEntity = (entity)=>{
|
|
309
|
+
currentBatch.push(entity);
|
|
310
|
+
totalCollected++;
|
|
311
|
+
if (currentBatch.length >= batchSize) {
|
|
312
|
+
flushBatch();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
for (const collection of this.adapter.cms.config.collections.filter(entityHasBlocksField)){
|
|
316
|
+
let page = 1;
|
|
317
|
+
let hasMore = true;
|
|
318
|
+
while(hasMore){
|
|
319
|
+
const { docs, hasNextPage } = await this.adapter.find({
|
|
320
|
+
collection: collection.slug,
|
|
321
|
+
limit: batchSize,
|
|
322
|
+
page
|
|
323
|
+
});
|
|
324
|
+
for (const doc of docs){
|
|
325
|
+
const entity = {
|
|
326
|
+
id: doc.id,
|
|
327
|
+
slug: collection.slug,
|
|
328
|
+
type: 'collection',
|
|
329
|
+
blocks: collectBlocksToMigrate({
|
|
330
|
+
config: this.adapter.cms.config,
|
|
331
|
+
data: doc,
|
|
332
|
+
fields: collection.flattenedFields,
|
|
333
|
+
parentAccessor: [],
|
|
334
|
+
parentIsLocalized: false
|
|
335
|
+
}),
|
|
336
|
+
originalData: doc
|
|
337
|
+
};
|
|
338
|
+
addEntity(entity);
|
|
339
|
+
}
|
|
340
|
+
this.adapter.cms.logger.info(`Collected ${docs.length} entries from ${collection.slug} (page ${page})`);
|
|
341
|
+
hasMore = hasNextPage;
|
|
342
|
+
page++;
|
|
343
|
+
}
|
|
344
|
+
if (collection.versions) {
|
|
345
|
+
let versionPage = 1;
|
|
346
|
+
let hasMoreVersions = true;
|
|
347
|
+
while(hasMoreVersions){
|
|
348
|
+
const { docs: versionDocs, hasNextPage: hasNextVersionPage } = await this.adapter.findVersions({
|
|
349
|
+
collection: collection.slug,
|
|
350
|
+
limit: batchSize,
|
|
351
|
+
page: versionPage
|
|
352
|
+
});
|
|
353
|
+
for (const versionDoc of versionDocs){
|
|
354
|
+
const entity = {
|
|
355
|
+
id: versionDoc.id,
|
|
356
|
+
slug: collection.slug,
|
|
357
|
+
type: 'collectionVersion',
|
|
358
|
+
blocks: collectBlocksToMigrate({
|
|
359
|
+
config: this.adapter.cms.config,
|
|
360
|
+
data: versionDoc,
|
|
361
|
+
fields: buildVersionCollectionFields(this.adapter.cms.config, collection, true),
|
|
362
|
+
parentAccessor: [],
|
|
363
|
+
parentIsLocalized: false
|
|
364
|
+
}),
|
|
365
|
+
originalData: versionDoc
|
|
366
|
+
};
|
|
367
|
+
addEntity(entity);
|
|
368
|
+
}
|
|
369
|
+
this.adapter.cms.logger.info(`Collected ${versionDocs.length} versions from ${collection.slug} (page ${versionPage})`);
|
|
370
|
+
hasMoreVersions = hasNextVersionPage;
|
|
371
|
+
versionPage++;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
for (const globalConfig of this.adapter.cms.config.globals.filter(entityHasBlocksField)){
|
|
376
|
+
const globalDoc = await this.adapter.findGlobal({
|
|
377
|
+
slug: globalConfig.slug
|
|
378
|
+
});
|
|
379
|
+
const entity = {
|
|
380
|
+
slug: globalConfig.slug,
|
|
381
|
+
type: 'global',
|
|
382
|
+
blocks: collectBlocksToMigrate({
|
|
383
|
+
config: this.adapter.cms.config,
|
|
384
|
+
data: globalDoc,
|
|
385
|
+
fields: globalConfig.flattenedFields,
|
|
386
|
+
parentAccessor: [],
|
|
387
|
+
parentIsLocalized: false
|
|
388
|
+
}),
|
|
389
|
+
originalData: globalDoc
|
|
390
|
+
};
|
|
391
|
+
addEntity(entity);
|
|
392
|
+
this.adapter.cms.logger.info(`Collected global ${globalConfig.slug}`);
|
|
393
|
+
if (globalConfig.versions) {
|
|
394
|
+
let globalVersionPage = 1;
|
|
395
|
+
let hasMoreGlobalVersions = true;
|
|
396
|
+
while(hasMoreGlobalVersions){
|
|
397
|
+
const { docs: globalVersionDocs, hasNextPage: hasNextGlobalVersionPage } = await this.adapter.findGlobalVersions({
|
|
398
|
+
global: globalConfig.slug,
|
|
399
|
+
limit: batchSize,
|
|
400
|
+
page: globalVersionPage
|
|
401
|
+
});
|
|
402
|
+
for (const globalVersionDoc of globalVersionDocs){
|
|
403
|
+
const entity = {
|
|
404
|
+
id: globalVersionDoc.id,
|
|
405
|
+
slug: globalConfig.slug,
|
|
406
|
+
type: 'globalVersion',
|
|
407
|
+
blocks: collectBlocksToMigrate({
|
|
408
|
+
config: this.adapter.cms.config,
|
|
409
|
+
data: globalVersionDoc,
|
|
410
|
+
fields: buildVersionGlobalFields(this.adapter.cms.config, globalConfig, true),
|
|
411
|
+
parentAccessor: [],
|
|
412
|
+
parentIsLocalized: false
|
|
413
|
+
}),
|
|
414
|
+
originalData: globalVersionDoc
|
|
415
|
+
};
|
|
416
|
+
addEntity(entity);
|
|
417
|
+
}
|
|
418
|
+
this.adapter.cms.logger.info(`Collected ${globalVersionDocs.length} versions from global ${globalConfig.slug} (page ${globalVersionPage})`);
|
|
419
|
+
hasMoreGlobalVersions = hasNextGlobalVersionPage;
|
|
420
|
+
globalVersionPage++;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
flushBatch();
|
|
425
|
+
this.adapter.cms.logger.info(`Collected total of ${totalCollected} entities across ${batchIndex} batches`);
|
|
426
|
+
}
|
|
427
|
+
async getMigrationStatements() {
|
|
428
|
+
const { generateDrizzleJson, generateMigration } = this.adapter.requireDrizzleKit();
|
|
429
|
+
const drizzleJsonBefore = await generateDrizzleJson(this.adapter.schema);
|
|
430
|
+
this.adapter.blocksAsJSON = true;
|
|
431
|
+
this.resetSchema();
|
|
432
|
+
await this.adapter.init();
|
|
433
|
+
const drizzleJsonAfter = await generateDrizzleJson(this.adapter.schema);
|
|
434
|
+
this.adapter.blocksAsJSON = false;
|
|
435
|
+
this.resetSchema();
|
|
436
|
+
await this.adapter.init();
|
|
437
|
+
const statements = await acceptDrizzlePrompts(()=>generateMigration(drizzleJsonBefore, drizzleJsonAfter), {
|
|
438
|
+
silenceLogs: true
|
|
439
|
+
});
|
|
440
|
+
const sqlExecute = `await db.${this.executeMethod}(` + 'sql`';
|
|
441
|
+
return {
|
|
442
|
+
statements: this.sanitizeStatements({
|
|
443
|
+
sqlExecute,
|
|
444
|
+
statements
|
|
445
|
+
}),
|
|
446
|
+
writeDrizzleSnapshot (filePath) {
|
|
447
|
+
writeFileSync(`${filePath}.json`, JSON.stringify(drizzleJsonAfter, null, 2));
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
async migrateEntitiesFromTempFolder(req, options) {
|
|
452
|
+
const clearBatches = options?.clearBatches ?? true;
|
|
453
|
+
let totalEntities = 0;
|
|
454
|
+
let hasEntities = false;
|
|
455
|
+
for (const entities of this.fetchEntitiesFromJsonBatches()){
|
|
456
|
+
hasEntities = true;
|
|
457
|
+
totalEntities += entities.length;
|
|
458
|
+
this.adapter.cms.logger.info(`Migrating batch with ${entities.length} entities (total: ${totalEntities})`);
|
|
459
|
+
await this.migrateEntities(entities, req);
|
|
460
|
+
}
|
|
461
|
+
if (!hasEntities) {
|
|
462
|
+
this.adapter.cms.logger.warn('No entities found in temp folder to migrate');
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
this.adapter.cms.logger.info(`Completed migration of ${totalEntities} entities from temp folder`);
|
|
466
|
+
if (clearBatches) {
|
|
467
|
+
this.cleanupTempFolder();
|
|
468
|
+
} else {
|
|
469
|
+
this.adapter.cms.logger.info(`Temp folder preserved at ${this.tempFolderPath} (clearBatches: false)`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
setTempFolder(tempFolderPath) {
|
|
473
|
+
this.tempFolderPath = tempFolderPath;
|
|
474
|
+
}
|
|
475
|
+
async updateCMSConfigFile() {
|
|
476
|
+
let configPath;
|
|
477
|
+
try {
|
|
478
|
+
configPath = findConfig();
|
|
479
|
+
} catch {
|
|
480
|
+
this.adapter.cms.logger.info('updateCMSConfigFile failed - could not find the cms config. Please set the blocksAsJSON DB adapter property manually to "true"');
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const configFile = readFileSync(configPath, 'utf-8');
|
|
484
|
+
const ts = await dynamicImport('typescript');
|
|
485
|
+
const source = ts.createSourceFile(configPath, configFile, ts.ScriptTarget.ESNext);
|
|
486
|
+
let hadChanges = false;
|
|
487
|
+
const result = ts.transform(source, [
|
|
488
|
+
(ctx)=>(sourceFile)=>{
|
|
489
|
+
const factory = ctx.factory;
|
|
490
|
+
const visit = (node)=>{
|
|
491
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === 'db' && ts.isCallExpression(node.initializer) && node.initializer.arguments.length > 0 && ts.isObjectLiteralExpression(node.initializer.arguments[0])) {
|
|
492
|
+
const call = node.initializer;
|
|
493
|
+
const obj = node.initializer.arguments[0];
|
|
494
|
+
const filteredProps = obj.properties.filter((prop)=>{
|
|
495
|
+
if (!ts.isPropertyAssignment(prop)) {
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
return !(ts.isIdentifier(prop.name) && prop.name.text === 'blocksAsJSON');
|
|
499
|
+
});
|
|
500
|
+
const newProperty = factory.createPropertyAssignment('blocksAsJSON', factory.createTrue());
|
|
501
|
+
hadChanges = true;
|
|
502
|
+
const newObject = factory.updateObjectLiteralExpression(obj, [
|
|
503
|
+
...filteredProps,
|
|
504
|
+
newProperty
|
|
505
|
+
]);
|
|
506
|
+
const newCall = factory.updateCallExpression(call, call.expression, call.typeArguments, [
|
|
507
|
+
newObject
|
|
508
|
+
]);
|
|
509
|
+
return factory.updatePropertyAssignment(node, node.name, newCall);
|
|
510
|
+
}
|
|
511
|
+
return ts.visitEachChild(node, visit, ctx);
|
|
512
|
+
};
|
|
513
|
+
return ts.visitNode(sourceFile, visit);
|
|
514
|
+
}
|
|
515
|
+
]);
|
|
516
|
+
if (!hadChanges) {
|
|
517
|
+
this.adapter.cms.logger.info('No changes made to cms config. Set blocksAsJSON to true manually.');
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
const printer = ts.createPrinter({
|
|
521
|
+
newLine: ts.NewLineKind.LineFeed
|
|
522
|
+
});
|
|
523
|
+
let output = printer.printFile(result.transformed[0]);
|
|
524
|
+
try {
|
|
525
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
526
|
+
const prettier = await dynamicImport('prettier');
|
|
527
|
+
const configPath = await prettier.resolveConfigFile();
|
|
528
|
+
const config = configPath ? await prettier.resolveConfig(configPath) : {};
|
|
529
|
+
output = await prettier.format(output, {
|
|
530
|
+
...config,
|
|
531
|
+
parser: 'typescript'
|
|
532
|
+
});
|
|
533
|
+
} catch (err) {
|
|
534
|
+
this.adapter.cms.logger.error({
|
|
535
|
+
err,
|
|
536
|
+
msg: 'Could not format cms config with Prettier'
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
writeFileSync(configPath, output, 'utf-8');
|
|
540
|
+
this.adapter.cms.logger.info(`Updated ${configPath} with blocksAsJSON: true`);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
export const createBlocksToJsonMigrator = ({ adapter, executeMethod, sanitizeStatements })=>{
|
|
544
|
+
return new BlocksToJsonMigratorImpl(adapter, sanitizeStatements, executeMethod);
|
|
545
|
+
};
|
|
546
|
+
export const getBlocksToJsonMigrator = (cms)=>{
|
|
547
|
+
const migrator = cms.db.blocksToJsonMigrator;
|
|
548
|
+
if (!migrator) {
|
|
549
|
+
throw new APIError(`blocksToJsonMigrator is not defined for ${cms.db.packageName}`);
|
|
550
|
+
}
|
|
551
|
+
return migrator;
|
|
552
|
+
};
|
|
553
|
+
export const buildDynamicPredefinedBlocksToJsonMigration = ({ packageName })=>{
|
|
554
|
+
return async ({ filePath, cms })=>{
|
|
555
|
+
const migrator = getBlocksToJsonMigrator(cms);
|
|
556
|
+
const migrationStatements = await migrator.getMigrationStatements();
|
|
557
|
+
migrationStatements.writeDrizzleSnapshot(filePath);
|
|
558
|
+
await migrator.updateCMSConfigFile();
|
|
559
|
+
const upSQL = `
|
|
560
|
+
const migrator = getBlocksToJsonMigrator(cms)
|
|
561
|
+
migrator.setTempFolder(TEMP_FOLDER)
|
|
562
|
+
await migrator.collectAndSaveEntitiesToBatches(req, { batchSize: BATCH_SIZE })
|
|
563
|
+
|
|
564
|
+
${migrationStatements.statements}
|
|
565
|
+
cms.logger.info("Executed blocks to JSON migration statements.")
|
|
566
|
+
|
|
567
|
+
await migrator.migrateEntitiesFromTempFolder(req, { clearBatches: true })
|
|
568
|
+
`;
|
|
569
|
+
return {
|
|
570
|
+
imports: `
|
|
571
|
+
import { getBlocksToJsonMigrator } from '${packageName}/migration-utils'
|
|
572
|
+
import { fileURLToPath } from 'url'
|
|
573
|
+
import path from 'path'
|
|
574
|
+
|
|
575
|
+
const filename = fileURLToPath(import.meta.url)
|
|
576
|
+
const dirname = path.dirname(filename)
|
|
577
|
+
|
|
578
|
+
// Configure migration options (optional)
|
|
579
|
+
const BATCH_SIZE = 100 // Number of entities to process per batch
|
|
580
|
+
const TEMP_FOLDER = path.resolve(dirname, '${TEMP_FOLDER_NAME}') // Folder path to store migration batch
|
|
581
|
+
`,
|
|
582
|
+
upSQL
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
//# sourceMappingURL=blocksToJsonMigrator.js.map
|