@payloadcms/drizzle 3.0.0-beta.100
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/README.md +3 -0
- package/dist/count.d.ts +3 -0
- package/dist/count.d.ts.map +1 -0
- package/dist/count.js +25 -0
- package/dist/count.js.map +1 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +19 -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 +19 -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 +36 -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 +35 -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 +45 -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 +32 -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 +63 -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 +35 -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 +14 -0
- package/dist/exports/postgres.d.ts.map +1 -0
- package/dist/exports/postgres.js +15 -0
- package/dist/exports/postgres.js.map +1 -0
- package/dist/find/buildFindManyArgs.d.ts +17 -0
- package/dist/find/buildFindManyArgs.d.ts.map +1 -0
- package/dist/find/buildFindManyArgs.js +66 -0
- package/dist/find/buildFindManyArgs.js.map +1 -0
- package/dist/find/chainMethods.d.ts +16 -0
- package/dist/find/chainMethods.d.ts.map +1 -0
- package/dist/find/chainMethods.js +12 -0
- package/dist/find/chainMethods.js.map +1 -0
- package/dist/find/findMany.d.ts +21 -0
- package/dist/find/findMany.d.ts.map +1 -0
- package/dist/find/findMany.js +141 -0
- package/dist/find/findMany.js.map +1 -0
- package/dist/find/traverseFields.d.ts +18 -0
- package/dist/find/traverseFields.d.ts.map +1 -0
- package/dist/find/traverseFields.js +164 -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 +21 -0
- package/dist/find.js.map +1 -0
- package/dist/findGlobal.d.ts +3 -0
- package/dist/findGlobal.d.ts.map +1 -0
- package/dist/findGlobal.js +23 -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/findMigrationDir.d.ts +16 -0
- package/dist/findMigrationDir.d.ts.map +1 -0
- package/dist/findMigrationDir.js +38 -0
- package/dist/findMigrationDir.js.map +1 -0
- package/dist/findOne.d.ts +4 -0
- package/dist/findOne.d.ts.map +1 -0
- package/dist/findOne.js +21 -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 +24 -0
- package/dist/findVersions.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -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 +94 -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 +63 -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 +76 -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 +103 -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 +84 -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 +43 -0
- package/dist/migrateStatus.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/createJSONQuery/convertPathToJSONTraversal.d.ts +2 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js +16 -0
- package/dist/postgres/createJSONQuery/convertPathToJSONTraversal.js.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts +2 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js +5 -0
- package/dist/postgres/createJSONQuery/formatJSONPathSegment.js.map +1 -0
- package/dist/postgres/createJSONQuery/index.d.ts +10 -0
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -0
- package/dist/postgres/createJSONQuery/index.js +54 -0
- package/dist/postgres/createJSONQuery/index.js.map +1 -0
- package/dist/postgres/createMigration.d.ts +3 -0
- package/dist/postgres/createMigration.d.ts.map +1 -0
- package/dist/postgres/createMigration.js +92 -0
- package/dist/postgres/createMigration.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 +17 -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/getMigrationTemplate.d.ts +4 -0
- package/dist/postgres/getMigrationTemplate.d.ts.map +1 -0
- package/dist/postgres/getMigrationTemplate.js +13 -0
- package/dist/postgres/getMigrationTemplate.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 +95 -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/requireDrizzleKit.d.ts +3 -0
- package/dist/postgres/requireDrizzleKit.d.ts.map +1 -0
- package/dist/postgres/requireDrizzleKit.js +5 -0
- package/dist/postgres/requireDrizzleKit.js.map +1 -0
- package/dist/postgres/schema/build.d.ts +40 -0
- package/dist/postgres/schema/build.d.ts.map +1 -0
- package/dist/postgres/schema/build.js +377 -0
- package/dist/postgres/schema/build.js.map +1 -0
- package/dist/postgres/schema/createIndex.d.ts +12 -0
- package/dist/postgres/schema/createIndex.d.ts.map +1 -0
- package/dist/postgres/schema/createIndex.js +20 -0
- package/dist/postgres/schema/createIndex.js.map +1 -0
- package/dist/postgres/schema/idToUUID.d.ts +3 -0
- package/dist/postgres/schema/idToUUID.d.ts.map +1 -0
- package/dist/postgres/schema/idToUUID.js +11 -0
- package/dist/postgres/schema/idToUUID.js.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts +4 -0
- package/dist/postgres/schema/parentIDColumnMap.d.ts.map +1 -0
- package/dist/postgres/schema/parentIDColumnMap.js +9 -0
- package/dist/postgres/schema/parentIDColumnMap.js.map +1 -0
- package/dist/postgres/schema/setColumnID.d.ts +11 -0
- package/dist/postgres/schema/setColumnID.d.ts.map +1 -0
- package/dist/postgres/schema/setColumnID.js +24 -0
- package/dist/postgres/schema/setColumnID.js.map +1 -0
- package/dist/postgres/schema/traverseFields.d.ts +40 -0
- package/dist/postgres/schema/traverseFields.d.ts.map +1 -0
- package/dist/postgres/schema/traverseFields.js +712 -0
- package/dist/postgres/schema/traverseFields.js.map +1 -0
- package/dist/postgres/schema/withDefault.d.ts +4 -0
- package/dist/postgres/schema/withDefault.d.ts.map +1 -0
- package/dist/postgres/schema/withDefault.js +12 -0
- package/dist/postgres/schema/withDefault.js.map +1 -0
- package/dist/postgres/types.d.ts +112 -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/buildAndOrConditions.d.ts +16 -0
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -0
- package/dist/queries/buildAndOrConditions.js +26 -0
- package/dist/queries/buildAndOrConditions.js.map +1 -0
- package/dist/queries/buildQuery.d.ts +29 -0
- package/dist/queries/buildQuery.d.ts.map +1 -0
- package/dist/queries/buildQuery.js +72 -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 +51 -0
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -0
- package/dist/queries/getTableColumnFromPath.js +534 -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 +24 -0
- package/dist/queries/operatorMap.js.map +1 -0
- package/dist/queries/parseParams.d.ts +16 -0
- package/dist/queries/parseParams.d.ts.map +1 -0
- package/dist/queries/parseParams.js +188 -0
- package/dist/queries/parseParams.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts +15 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -0
- package/dist/queries/sanitizeQueryValue.js +128 -0
- package/dist/queries/sanitizeQueryValue.js.map +1 -0
- package/dist/queries/selectDistinct.d.ts +21 -0
- package/dist/queries/selectDistinct.d.ts.map +1 -0
- package/dist/queries/selectDistinct.js +38 -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 +39 -0
- package/dist/queryDrafts.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 +50 -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 +17 -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 +14 -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 +20 -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 +13 -0
- package/dist/transform/read/index.d.ts.map +1 -0
- package/dist/transform/read/index.js +44 -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 +60 -0
- package/dist/transform/read/traverseFields.d.ts.map +1 -0
- package/dist/transform/read/traverseFields.js +456 -0
- package/dist/transform/read/traverseFields.js.map +1 -0
- package/dist/transform/write/array.d.ts +31 -0
- package/dist/transform/write/array.d.ts.map +1 -0
- package/dist/transform/write/array.js +62 -0
- package/dist/transform/write/array.js.map +1 -0
- package/dist/transform/write/blocks.d.ts +30 -0
- package/dist/transform/write/blocks.d.ts.map +1 -0
- package/dist/transform/write/blocks.js +66 -0
- package/dist/transform/write/blocks.js.map +1 -0
- package/dist/transform/write/index.d.ts +13 -0
- package/dist/transform/write/index.d.ts.map +1 -0
- package/dist/transform/write/index.js +41 -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 +55 -0
- package/dist/transform/write/traverseFields.d.ts.map +1 -0
- package/dist/transform/write/traverseFields.js +474 -0
- package/dist/transform/write/traverseFields.js.map +1 -0
- package/dist/transform/write/types.d.ts +43 -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 +145 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/update.d.ts +3 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +54 -0
- package/dist/update.js.map +1 -0
- package/dist/updateGlobal.d.ts +4 -0
- package/dist/updateGlobal.d.ts.map +1 -0
- package/dist/updateGlobal.js +25 -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 +36 -0
- package/dist/updateGlobalVersion.js.map +1 -0
- package/dist/updateVersion.d.ts +4 -0
- package/dist/updateVersion.d.ts.map +1 -0
- package/dist/updateVersion.js +36 -0
- package/dist/updateVersion.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/index.d.ts +4 -0
- package/dist/upsertRow/index.d.ts.map +1 -0
- package/dist/upsertRow/index.js +372 -0
- package/dist/upsertRow/index.js.map +1 -0
- package/dist/upsertRow/insertArrays.d.ts +13 -0
- package/dist/upsertRow/insertArrays.d.ts.map +1 -0
- package/dist/upsertRow/insertArrays.js +76 -0
- package/dist/upsertRow/insertArrays.js.map +1 -0
- package/dist/upsertRow/types.d.ts +32 -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/createBlocksMap.d.ts +5 -0
- package/dist/utilities/createBlocksMap.d.ts.map +1 -0
- package/dist/utilities/createBlocksMap.js +31 -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/hasLocalesTable.d.ts +3 -0
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -0
- package/dist/utilities/hasLocalesTable.js +21 -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/migrationTableExists.d.ts +3 -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 +55 -0
- package/dist/utilities/pushDevSchema.js.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +11 -0
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js +76 -0
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findMigrationDir.d.ts","sourceRoot":"","sources":["../src/findMigrationDir.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAyB9D"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Attempt to find migrations directory.
|
|
5
|
+
*
|
|
6
|
+
* Checks for the following directories in order:
|
|
7
|
+
* - `migrationDir` argument from Payload config
|
|
8
|
+
* - `src/migrations`
|
|
9
|
+
* - `dist/migrations`
|
|
10
|
+
* - `migrations`
|
|
11
|
+
*
|
|
12
|
+
* Defaults to `src/migrations`
|
|
13
|
+
*
|
|
14
|
+
* @param migrationDir
|
|
15
|
+
* @returns
|
|
16
|
+
*/ export function findMigrationDir(migrationDir) {
|
|
17
|
+
const cwd = process.cwd();
|
|
18
|
+
const srcDir = path.resolve(cwd, 'src/migrations');
|
|
19
|
+
const distDir = path.resolve(cwd, 'dist/migrations');
|
|
20
|
+
const relativeMigrations = path.resolve(cwd, 'migrations');
|
|
21
|
+
// Use arg if provided
|
|
22
|
+
if (migrationDir) {
|
|
23
|
+
return migrationDir;
|
|
24
|
+
}
|
|
25
|
+
// Check other common locations
|
|
26
|
+
if (fs.existsSync(srcDir)) {
|
|
27
|
+
return srcDir;
|
|
28
|
+
}
|
|
29
|
+
if (fs.existsSync(distDir)) {
|
|
30
|
+
return distDir;
|
|
31
|
+
}
|
|
32
|
+
if (fs.existsSync(relativeMigrations)) {
|
|
33
|
+
return relativeMigrations;
|
|
34
|
+
}
|
|
35
|
+
return srcDir;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=findMigrationDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/findMigrationDir.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\n/**\n * Attempt to find migrations directory.\n *\n * Checks for the following directories in order:\n * - `migrationDir` argument from Payload config\n * - `src/migrations`\n * - `dist/migrations`\n * - `migrations`\n *\n * Defaults to `src/migrations`\n *\n * @param migrationDir\n * @returns\n */\nexport function findMigrationDir(migrationDir?: string): string {\n const cwd = process.cwd()\n const srcDir = path.resolve(cwd, 'src/migrations')\n const distDir = path.resolve(cwd, 'dist/migrations')\n const relativeMigrations = path.resolve(cwd, 'migrations')\n\n // Use arg if provided\n if (migrationDir) {\n return migrationDir\n }\n\n // Check other common locations\n if (fs.existsSync(srcDir)) {\n return srcDir\n }\n\n if (fs.existsSync(distDir)) {\n return distDir\n }\n\n if (fs.existsSync(relativeMigrations)) {\n return relativeMigrations\n }\n\n return srcDir\n}\n"],"names":["fs","path","findMigrationDir","migrationDir","cwd","process","srcDir","resolve","distDir","relativeMigrations","existsSync"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AAEvB;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,iBAAiBC,YAAqB;IACpD,MAAMC,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAASL,KAAKM,OAAO,CAACH,KAAK;IACjC,MAAMI,UAAUP,KAAKM,OAAO,CAACH,KAAK;IAClC,MAAMK,qBAAqBR,KAAKM,OAAO,CAACH,KAAK;IAE7C,sBAAsB;IACtB,IAAID,cAAc;QAChB,OAAOA;IACT;IAEA,+BAA+B;IAC/B,IAAIH,GAAGU,UAAU,CAACJ,SAAS;QACzB,OAAOA;IACT;IAEA,IAAIN,GAAGU,UAAU,CAACF,UAAU;QAC1B,OAAOA;IACT;IAEA,IAAIR,GAAGU,UAAU,CAACD,qBAAqB;QACrC,OAAOA;IACT;IAEA,OAAOH;AACT"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FindOneArgs, TypeWithID } from 'payload';
|
|
2
|
+
import type { DrizzleAdapter } from './types.js';
|
|
3
|
+
export declare function findOne<T extends TypeWithID>(this: DrizzleAdapter, { collection, locale, req, where }: FindOneArgs): Promise<T>;
|
|
4
|
+
//# sourceMappingURL=findOne.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findOne.d.ts","sourceRoot":"","sources":["../src/findOne.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA6C,UAAU,EAAE,MAAM,SAAS,CAAA;AAIjG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,wBAAsB,OAAO,CAAC,CAAC,SAAS,UAAU,EAChD,IAAI,EAAE,cAAc,EACpB,EAAE,UAAU,EAAE,MAAM,EAAE,GAA0B,EAAE,KAAK,EAAE,EAAE,WAAW,GACrE,OAAO,CAAC,CAAC,CAAC,CAmBZ"}
|
package/dist/findOne.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { findMany } from './find/findMany.js';
|
|
3
|
+
export async function findOne({ collection, locale, req = {}, where }) {
|
|
4
|
+
const collectionConfig = this.payload.collections[collection].config;
|
|
5
|
+
const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug));
|
|
6
|
+
const { docs } = await findMany({
|
|
7
|
+
adapter: this,
|
|
8
|
+
fields: collectionConfig.fields,
|
|
9
|
+
limit: 1,
|
|
10
|
+
locale,
|
|
11
|
+
page: 1,
|
|
12
|
+
pagination: false,
|
|
13
|
+
req,
|
|
14
|
+
sort: undefined,
|
|
15
|
+
tableName,
|
|
16
|
+
where
|
|
17
|
+
});
|
|
18
|
+
return docs?.[0] || null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=findOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/findOne.ts"],"sourcesContent":["import type { FindOneArgs, PayloadRequest, SanitizedCollectionConfig, TypeWithID } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport async function findOne<T extends TypeWithID>(\n this: DrizzleAdapter,\n { collection, locale, req = {} as PayloadRequest, where }: FindOneArgs,\n): Promise<T> {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const { docs } = await findMany({\n adapter: this,\n fields: collectionConfig.fields,\n limit: 1,\n locale,\n page: 1,\n pagination: false,\n req,\n sort: undefined,\n tableName,\n where,\n })\n\n return docs?.[0] || null\n}\n"],"names":["toSnakeCase","findMany","findOne","collection","locale","req","where","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","docs","adapter","fields","limit","page","pagination","sort","undefined"],"mappings":"AAEA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,eAAeC,QAEpB,EAAEC,UAAU,EAAEC,MAAM,EAAEC,MAAM,CAAC,CAAmB,EAAEC,KAAK,EAAe;IAEtE,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACN,WAAW,CAACO,MAAM;IAE/F,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACb,YAAYO,iBAAiBO,IAAI;IAEzE,MAAM,EAAEC,IAAI,EAAE,GAAG,MAAMd,SAAS;QAC9Be,SAAS,IAAI;QACbC,QAAQV,iBAAiBU,MAAM;QAC/BC,OAAO;QACPd;QACAe,MAAM;QACNC,YAAY;QACZf;QACAgB,MAAMC;QACNX;QACAL;IACF;IAEA,OAAOS,MAAM,CAAC,EAAE,IAAI;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAA6C,MAAM,SAAS,CAAA;AAStF,eAAO,MAAM,YAAY,EAAE,YAoC1B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { buildVersionCollectionFields } from 'payload';
|
|
2
|
+
import toSnakeCase from 'to-snake-case';
|
|
3
|
+
import { findMany } from './find/findMany.js';
|
|
4
|
+
export const findVersions = async function findVersions({ collection, limit, locale, page, pagination, req = {}, skip, sort: sortArg, where }) {
|
|
5
|
+
const collectionConfig = this.payload.collections[collection].config;
|
|
6
|
+
const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort;
|
|
7
|
+
const tableName = this.tableNameMap.get(`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`);
|
|
8
|
+
const fields = buildVersionCollectionFields(collectionConfig);
|
|
9
|
+
return findMany({
|
|
10
|
+
adapter: this,
|
|
11
|
+
fields,
|
|
12
|
+
limit,
|
|
13
|
+
locale,
|
|
14
|
+
page,
|
|
15
|
+
pagination,
|
|
16
|
+
req,
|
|
17
|
+
skip,
|
|
18
|
+
sort,
|
|
19
|
+
tableName,
|
|
20
|
+
where
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=findVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { FindVersions, PayloadRequest, SanitizedCollectionConfig } from 'payload'\n\nimport { buildVersionCollectionFields } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: DrizzleAdapter,\n {\n collection,\n limit,\n locale,\n page,\n pagination,\n req = {} as PayloadRequest,\n skip,\n sort: sortArg,\n where,\n },\n) {\n const collectionConfig: SanitizedCollectionConfig = this.payload.collections[collection].config\n const sort = typeof sortArg === 'string' ? sortArg : collectionConfig.defaultSort\n\n const tableName = this.tableNameMap.get(\n `_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,\n )\n\n const fields = buildVersionCollectionFields(collectionConfig)\n\n return findMany({\n adapter: this,\n fields,\n limit,\n locale,\n page,\n pagination,\n req,\n skip,\n sort,\n tableName,\n where,\n })\n}\n"],"names":["buildVersionCollectionFields","toSnakeCase","findMany","findVersions","collection","limit","locale","page","pagination","req","skip","sort","sortArg","where","collectionConfig","payload","collections","config","defaultSort","tableName","tableNameMap","get","slug","versionsSuffix","fields","adapter"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,UAAS;AACtD,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAE7C,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAmB,EAC1BC,IAAI,EACJC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,MAAMC,mBAA8C,IAAI,CAACC,OAAO,CAACC,WAAW,CAACZ,WAAW,CAACa,MAAM;IAC/F,MAAMN,OAAO,OAAOC,YAAY,WAAWA,UAAUE,iBAAiBI,WAAW;IAEjF,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CACrC,CAAC,CAAC,EAAEpB,YAAYa,iBAAiBQ,IAAI,EAAE,EAAE,IAAI,CAACC,cAAc,CAAC,CAAC;IAGhE,MAAMC,SAASxB,6BAA6Bc;IAE5C,OAAOZ,SAAS;QACduB,SAAS,IAAI;QACbD;QACAnB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAQ;QACAN;IACF;AACF,EAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { count } from './count.js';
|
|
2
|
+
export { create } from './create.js';
|
|
3
|
+
export { createGlobal } from './createGlobal.js';
|
|
4
|
+
export { createGlobalVersion } from './createGlobalVersion.js';
|
|
5
|
+
export { createTableName } from './createTableName.js';
|
|
6
|
+
export { createVersion } from './createVersion.js';
|
|
7
|
+
export { deleteMany } from './deleteMany.js';
|
|
8
|
+
export { deleteOne } from './deleteOne.js';
|
|
9
|
+
export { deleteVersions } from './deleteVersions.js';
|
|
10
|
+
export { destroy } from './destroy.js';
|
|
11
|
+
export { find } from './find.js';
|
|
12
|
+
export { chainMethods } from './find/chainMethods.js';
|
|
13
|
+
export { findGlobal } from './findGlobal.js';
|
|
14
|
+
export { findGlobalVersions } from './findGlobalVersions.js';
|
|
15
|
+
export { findMigrationDir } from './findMigrationDir.js';
|
|
16
|
+
export { findOne } from './findOne.js';
|
|
17
|
+
export { findVersions } from './findVersions.js';
|
|
18
|
+
export { migrate } from './migrate.js';
|
|
19
|
+
export { migrateDown } from './migrateDown.js';
|
|
20
|
+
export { migrateFresh } from './migrateFresh.js';
|
|
21
|
+
export { migrateRefresh } from './migrateRefresh.js';
|
|
22
|
+
export { migrateReset } from './migrateReset.js';
|
|
23
|
+
export { migrateStatus } from './migrateStatus.js';
|
|
24
|
+
export { operatorMap } from './queries/operatorMap.js';
|
|
25
|
+
export type { Operators } from './queries/operatorMap.js';
|
|
26
|
+
export { queryDrafts } from './queryDrafts.js';
|
|
27
|
+
export { beginTransaction } from './transactions/beginTransaction.js';
|
|
28
|
+
export { commitTransaction } from './transactions/commitTransaction.js';
|
|
29
|
+
export { rollbackTransaction } from './transactions/rollbackTransaction.js';
|
|
30
|
+
export { updateOne } from './update.js';
|
|
31
|
+
export { updateGlobal } from './updateGlobal.js';
|
|
32
|
+
export { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
33
|
+
export { updateVersion } from './updateVersion.js';
|
|
34
|
+
export { upsertRow } from './upsertRow/index.js';
|
|
35
|
+
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
36
|
+
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
37
|
+
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { count } from './count.js';
|
|
2
|
+
export { create } from './create.js';
|
|
3
|
+
export { createGlobal } from './createGlobal.js';
|
|
4
|
+
export { createGlobalVersion } from './createGlobalVersion.js';
|
|
5
|
+
export { createTableName } from './createTableName.js';
|
|
6
|
+
export { createVersion } from './createVersion.js';
|
|
7
|
+
export { deleteMany } from './deleteMany.js';
|
|
8
|
+
export { deleteOne } from './deleteOne.js';
|
|
9
|
+
export { deleteVersions } from './deleteVersions.js';
|
|
10
|
+
export { destroy } from './destroy.js';
|
|
11
|
+
export { find } from './find.js';
|
|
12
|
+
export { chainMethods } from './find/chainMethods.js';
|
|
13
|
+
export { findGlobal } from './findGlobal.js';
|
|
14
|
+
export { findGlobalVersions } from './findGlobalVersions.js';
|
|
15
|
+
export { findMigrationDir } from './findMigrationDir.js';
|
|
16
|
+
export { findOne } from './findOne.js';
|
|
17
|
+
export { findVersions } from './findVersions.js';
|
|
18
|
+
export { migrate } from './migrate.js';
|
|
19
|
+
export { migrateDown } from './migrateDown.js';
|
|
20
|
+
export { migrateFresh } from './migrateFresh.js';
|
|
21
|
+
export { migrateRefresh } from './migrateRefresh.js';
|
|
22
|
+
export { migrateReset } from './migrateReset.js';
|
|
23
|
+
export { migrateStatus } from './migrateStatus.js';
|
|
24
|
+
export { operatorMap } from './queries/operatorMap.js';
|
|
25
|
+
export { queryDrafts } from './queryDrafts.js';
|
|
26
|
+
export { beginTransaction } from './transactions/beginTransaction.js';
|
|
27
|
+
export { commitTransaction } from './transactions/commitTransaction.js';
|
|
28
|
+
export { rollbackTransaction } from './transactions/rollbackTransaction.js';
|
|
29
|
+
export { updateOne } from './update.js';
|
|
30
|
+
export { updateGlobal } from './updateGlobal.js';
|
|
31
|
+
export { updateGlobalVersion } from './updateGlobalVersion.js';
|
|
32
|
+
export { updateVersion } from './updateVersion.js';
|
|
33
|
+
export { upsertRow } from './upsertRow/index.js';
|
|
34
|
+
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
35
|
+
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
36
|
+
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { create } from './create.js'\nexport { createGlobal } from './createGlobal.js'\nexport { createGlobalVersion } from './createGlobalVersion.js'\nexport { createTableName } from './createTableName.js'\nexport { createVersion } from './createVersion.js'\nexport { deleteMany } from './deleteMany.js'\nexport { deleteOne } from './deleteOne.js'\nexport { deleteVersions } from './deleteVersions.js'\nexport { destroy } from './destroy.js'\nexport { find } from './find.js'\nexport { chainMethods } from './find/chainMethods.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.js'\nexport { findMigrationDir } from './findMigrationDir.js'\nexport { findOne } from './findOne.js'\nexport { findVersions } from './findVersions.js'\nexport { migrate } from './migrate.js'\nexport { migrateDown } from './migrateDown.js'\nexport { migrateFresh } from './migrateFresh.js'\nexport { migrateRefresh } from './migrateRefresh.js'\nexport { migrateReset } from './migrateReset.js'\nexport { migrateStatus } from './migrateStatus.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { Operators } from './queries/operatorMap.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport { updateOne } from './update.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\n"],"names":["count","create","createGlobal","createGlobalVersion","createTableName","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","chainMethods","findGlobal","findGlobalVersions","findMigrationDir","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","operatorMap","queryDrafts","beginTransaction","commitTransaction","rollbackTransaction","updateOne","updateGlobal","updateGlobalVersion","updateVersion","upsertRow","hasLocalesTable","pushDevSchema","validateExistingBlockIsIdentical"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAY;AAClC,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,cAAc,QAAQ,sBAAqB;AACpD,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,WAAW,QAAQ,2BAA0B;AAEtD,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,SAAS,QAAQ,cAAa;AACvC,SAASC,YAAY,QAAQ,oBAAmB;AAChD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,gCAAgC,QAAQ,kDAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,YAAY,CAAA;AAK3D,eAAO,MAAM,OAAO,EAAE,cAAc,CAAC,SAAS,CA+D7C,CAAA"}
|
package/dist/migrate.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
|
+
import prompts from 'prompts';
|
|
3
|
+
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
4
|
+
import { parseError } from './utilities/parseError.js';
|
|
5
|
+
export const migrate = async function migrate(args) {
|
|
6
|
+
const { payload } = this;
|
|
7
|
+
const migrationFiles = args?.migrations || await readMigrationFiles({
|
|
8
|
+
payload
|
|
9
|
+
});
|
|
10
|
+
if (!migrationFiles.length) {
|
|
11
|
+
payload.logger.info({
|
|
12
|
+
msg: 'No migrations to run.'
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
let latestBatch = 0;
|
|
17
|
+
let migrationsInDB = [];
|
|
18
|
+
const hasMigrationTable = await migrationTableExists(this);
|
|
19
|
+
if (hasMigrationTable) {
|
|
20
|
+
({ docs: migrationsInDB } = await payload.find({
|
|
21
|
+
collection: 'payload-migrations',
|
|
22
|
+
limit: 0,
|
|
23
|
+
sort: '-name'
|
|
24
|
+
}));
|
|
25
|
+
if (Number(migrationsInDB?.[0]?.batch) > 0) {
|
|
26
|
+
latestBatch = Number(migrationsInDB[0]?.batch);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (migrationsInDB.find((m)=>m.batch === -1)) {
|
|
30
|
+
const { confirm: runMigrations } = await prompts({
|
|
31
|
+
name: 'confirm',
|
|
32
|
+
type: 'confirm',
|
|
33
|
+
initial: false,
|
|
34
|
+
message: "It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\n\n" + "If you'd like to run migrations, data loss will occur. Would you like to proceed?"
|
|
35
|
+
}, {
|
|
36
|
+
onCancel: ()=>{
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (!runMigrations) {
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const newBatch = latestBatch + 1;
|
|
45
|
+
// Execute 'up' function for each migration sequentially
|
|
46
|
+
for (const migration of migrationFiles){
|
|
47
|
+
const alreadyRan = migrationsInDB.find((existing)=>existing.name === migration.name);
|
|
48
|
+
// If already ran, skip
|
|
49
|
+
if (alreadyRan) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
await runMigrationFile(payload, migration, newBatch);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
async function runMigrationFile(payload, migration, batch) {
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
const req = {
|
|
58
|
+
payload
|
|
59
|
+
};
|
|
60
|
+
const adapter = payload.db;
|
|
61
|
+
payload.logger.info({
|
|
62
|
+
msg: `Migrating: ${migration.name}`
|
|
63
|
+
});
|
|
64
|
+
try {
|
|
65
|
+
await initTransaction(req);
|
|
66
|
+
const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle;
|
|
67
|
+
await migration.up({
|
|
68
|
+
db,
|
|
69
|
+
payload,
|
|
70
|
+
req
|
|
71
|
+
});
|
|
72
|
+
payload.logger.info({
|
|
73
|
+
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
|
|
74
|
+
});
|
|
75
|
+
await payload.create({
|
|
76
|
+
collection: 'payload-migrations',
|
|
77
|
+
data: {
|
|
78
|
+
name: migration.name,
|
|
79
|
+
batch
|
|
80
|
+
},
|
|
81
|
+
req
|
|
82
|
+
});
|
|
83
|
+
await commitTransaction(req);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
await killTransaction(req);
|
|
86
|
+
payload.logger.error({
|
|
87
|
+
err,
|
|
88
|
+
msg: parseError(err, `Error running migration ${migration.name}`)
|
|
89
|
+
});
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter, Migration } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nexport const migrate: DrizzleAdapter['migrate'] = async function migrate(\n this: DrizzleAdapter,\n args,\n): Promise<void> {\n const { payload } = this\n const migrationFiles = args?.migrations || (await readMigrationFiles({ payload }))\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations to run.' })\n return\n }\n\n let latestBatch = 0\n let migrationsInDB = []\n\n const hasMigrationTable = await migrationTableExists(this)\n\n if (hasMigrationTable) {\n ;({ docs: migrationsInDB } = await payload.find({\n collection: 'payload-migrations',\n limit: 0,\n sort: '-name',\n }))\n if (Number(migrationsInDB?.[0]?.batch) > 0) {\n latestBatch = Number(migrationsInDB[0]?.batch)\n }\n }\n\n if (migrationsInDB.find((m) => m.batch === -1)) {\n const { confirm: runMigrations } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message:\n \"It looks like you've run Payload in dev mode, meaning you've dynamically pushed changes to your database.\\n\\n\" +\n \"If you'd like to run migrations, data loss will occur. Would you like to proceed?\",\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!runMigrations) {\n process.exit(0)\n }\n }\n\n const newBatch = latestBatch + 1\n\n // Execute 'up' function for each migration sequentially\n for (const migration of migrationFiles) {\n const alreadyRan = migrationsInDB.find((existing) => existing.name === migration.name)\n\n // If already ran, skip\n if (alreadyRan) {\n continue\n }\n\n await runMigrationFile(payload, migration, newBatch)\n }\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const start = Date.now()\n const req = { payload } as PayloadRequest\n const adapter = payload.db as DrizzleAdapter\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n try {\n await initTransaction(req)\n const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle\n await migration.up({ db, payload, req })\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch,\n },\n req,\n })\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}`),\n })\n process.exit(1)\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","migrationTableExists","parseError","migrate","args","payload","migrationFiles","migrations","length","logger","info","msg","latestBatch","migrationsInDB","hasMigrationTable","docs","find","collection","limit","sort","Number","batch","m","confirm","runMigrations","name","type","initial","message","onCancel","process","exit","newBatch","migration","alreadyRan","existing","runMigrationFile","start","Date","now","req","adapter","db","sessions","transactionID","drizzle","up","create","data","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,UAAqC,eAAeA,QAE/DC,IAAI;IAEJ,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiBF,MAAMG,cAAe,MAAMR,mBAAmB;QAAEM;IAAQ;IAE/E,IAAI,CAACC,eAAeE,MAAM,EAAE;QAC1BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAAwB;QACnD;IACF;IAEA,IAAIC,cAAc;IAClB,IAAIC,iBAAiB,EAAE;IAEvB,MAAMC,oBAAoB,MAAMb,qBAAqB,IAAI;IAEzD,IAAIa,mBAAmB;QACnB,CAAA,EAAEC,MAAMF,cAAc,EAAE,GAAG,MAAMR,QAAQW,IAAI,CAAC;YAC9CC,YAAY;YACZC,OAAO;YACPC,MAAM;QACR,EAAC;QACD,IAAIC,OAAOP,gBAAgB,CAAC,EAAE,EAAEQ,SAAS,GAAG;YAC1CT,cAAcQ,OAAOP,cAAc,CAAC,EAAE,EAAEQ;QAC1C;IACF;IAEA,IAAIR,eAAeG,IAAI,CAAC,CAACM,IAAMA,EAAED,KAAK,KAAK,CAAC,IAAI;QAC9C,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAMxB,QACvC;YACEyB,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SACE,kHACA;QACJ,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEA,MAAMC,WAAWpB,cAAc;IAE/B,wDAAwD;IACxD,KAAK,MAAMqB,aAAa3B,eAAgB;QACtC,MAAM4B,aAAarB,eAAeG,IAAI,CAAC,CAACmB,WAAaA,SAASV,IAAI,KAAKQ,UAAUR,IAAI;QAErF,uBAAuB;QACvB,IAAIS,YAAY;YACd;QACF;QAEA,MAAME,iBAAiB/B,SAAS4B,WAAWD;IAC7C;AACF,EAAC;AAED,eAAeI,iBAAiB/B,OAAgB,EAAE4B,SAAoB,EAAEZ,KAAa;IACnF,MAAMgB,QAAQC,KAAKC,GAAG;IACtB,MAAMC,MAAM;QAAEnC;IAAQ;IACtB,MAAMoC,UAAUpC,QAAQqC,EAAE;IAE1BrC,QAAQI,MAAM,CAACC,IAAI,CAAC;QAAEC,KAAK,CAAC,WAAW,EAAEsB,UAAUR,IAAI,CAAC,CAAC;IAAC;IAE1D,IAAI;QACF,MAAM5B,gBAAgB2C;QACtB,MAAME,KAAKD,SAASE,QAAQ,CAAC,MAAMH,IAAII,aAAa,CAAC,EAAEF,MAAMD,QAAQI,OAAO;QAC5E,MAAMZ,UAAUa,EAAE,CAAC;YAAEJ;YAAIrC;YAASmC;QAAI;QACtCnC,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEsB,UAAUR,IAAI,CAAC,EAAE,EAAEa,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;QAAC;QACpF,MAAMhC,QAAQ0C,MAAM,CAAC;YACnB9B,YAAY;YACZ+B,MAAM;gBACJvB,MAAMQ,UAAUR,IAAI;gBACpBJ;YACF;YACAmB;QACF;QACA,MAAM5C,kBAAkB4C;IAC1B,EAAE,OAAOS,KAAc;QACrB,MAAMnD,gBAAgB0C;QACtBnC,QAAQI,MAAM,CAACyC,KAAK,CAAC;YACnBD;YACAtC,KAAKT,WAAW+C,KAAK,CAAC,wBAAwB,EAAEhB,UAAUR,IAAI,CAAC,CAAC;QAClE;QACAK,QAAQC,IAAI,CAAC;IACf;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrateDown.d.ts","sourceRoot":"","sources":["../src/migrateDown.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD,wBAAsB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAwDrE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { commitTransaction, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
|
+
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
3
|
+
import { parseError } from './utilities/parseError.js';
|
|
4
|
+
export async function migrateDown() {
|
|
5
|
+
const { payload } = this;
|
|
6
|
+
const migrationFiles = await readMigrationFiles({
|
|
7
|
+
payload
|
|
8
|
+
});
|
|
9
|
+
const { existingMigrations, latestBatch } = await getMigrations({
|
|
10
|
+
payload
|
|
11
|
+
});
|
|
12
|
+
if (!existingMigrations?.length) {
|
|
13
|
+
payload.logger.info({
|
|
14
|
+
msg: 'No migrations to rollback.'
|
|
15
|
+
});
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
payload.logger.info({
|
|
19
|
+
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
|
|
20
|
+
});
|
|
21
|
+
const latestBatchMigrations = existingMigrations.filter(({ batch })=>batch === latestBatch);
|
|
22
|
+
for (const migration of latestBatchMigrations){
|
|
23
|
+
const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
|
|
24
|
+
if (!migrationFile) {
|
|
25
|
+
throw new Error(`Migration ${migration.name} not found locally.`);
|
|
26
|
+
}
|
|
27
|
+
const start = Date.now();
|
|
28
|
+
const req = {
|
|
29
|
+
payload
|
|
30
|
+
};
|
|
31
|
+
try {
|
|
32
|
+
payload.logger.info({
|
|
33
|
+
msg: `Migrating down: ${migrationFile.name}`
|
|
34
|
+
});
|
|
35
|
+
await initTransaction(req);
|
|
36
|
+
await migrationFile.down({
|
|
37
|
+
payload,
|
|
38
|
+
req
|
|
39
|
+
});
|
|
40
|
+
payload.logger.info({
|
|
41
|
+
msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`
|
|
42
|
+
});
|
|
43
|
+
const tableExists = await migrationTableExists(this);
|
|
44
|
+
if (tableExists) {
|
|
45
|
+
await payload.delete({
|
|
46
|
+
id: migration.id,
|
|
47
|
+
collection: 'payload-migrations',
|
|
48
|
+
req
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
await commitTransaction(req);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
await killTransaction(req);
|
|
54
|
+
payload.logger.error({
|
|
55
|
+
err,
|
|
56
|
+
msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`)
|
|
57
|
+
});
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=migrateDown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/migrateDown.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport {\n commitTransaction,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\nexport async function migrateDown(this: DrizzleAdapter): Promise<void> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations, latestBatch } = await getMigrations({\n payload,\n })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to rollback.' })\n return\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const latestBatchMigrations = existingMigrations.filter(({ batch }) => batch === latestBatch)\n\n for (const migration of latestBatchMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n const req = { payload } as PayloadRequest\n\n try {\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n await migrationFile.down({ payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n req,\n })\n }\n\n await commitTransaction(req)\n } catch (err: unknown) {\n await killTransaction(req)\n\n payload.logger.error({\n err,\n msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`),\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","getMigrations","initTransaction","killTransaction","readMigrationFiles","migrationTableExists","parseError","migrateDown","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","latestBatchMigrations","filter","batch","migration","migrationFile","find","m","name","Error","start","Date","now","req","down","tableExists","delete","id","collection","err","error","process","exit"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAML,mBAAmB;QAAEI;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMV,cAAc;QAC9DO;IACF;IAEA,IAAI,CAACE,oBAAoBE,QAAQ;QAC/BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;QACxD;IACF;IAEAP,QAAQK,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,mBAAmB,EAAEJ,YAAY,eAAe,EAAED,mBAAmBE,MAAM,CAAC,cAAc,CAAC;IACnG;IAEA,MAAMI,wBAAwBN,mBAAmBO,MAAM,CAAC,CAAC,EAAEC,KAAK,EAAE,GAAKA,UAAUP;IAEjF,KAAK,MAAMQ,aAAaH,sBAAuB;QAC7C,MAAMI,gBAAgBX,eAAeY,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI,CAACH,eAAe;YAClB,MAAM,IAAII,MAAM,CAAC,UAAU,EAAEL,UAAUI,IAAI,CAAC,mBAAmB,CAAC;QAClE;QAEA,MAAME,QAAQC,KAAKC,GAAG;QACtB,MAAMC,MAAM;YAAEpB;QAAQ;QAEtB,IAAI;YACFA,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,CAAC;YAAC;YACnE,MAAMrB,gBAAgB0B;YACtB,MAAMR,cAAcS,IAAI,CAAC;gBAAErB;gBAASoB;YAAI;YACxCpB,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAClBC,KAAK,CAAC,gBAAgB,EAAEK,cAAcG,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YACxE;YAEA,MAAMK,cAAc,MAAMzB,qBAAqB,IAAI;YACnD,IAAIyB,aAAa;gBACf,MAAMtB,QAAQuB,MAAM,CAAC;oBACnBC,IAAIb,UAAUa,EAAE;oBAChBC,YAAY;oBACZL;gBACF;YACF;YAEA,MAAM5B,kBAAkB4B;QAC1B,EAAE,OAAOM,KAAc;YACrB,MAAM/B,gBAAgByB;YAEtBpB,QAAQK,MAAM,CAACsB,KAAK,CAAC;gBACnBD;gBACAnB,KAAKT,WAAW4B,KAAK,CAAC,qBAAqB,EAAEd,cAAcG,IAAI,CAAC,eAAe,CAAC;YAClF;YACAa,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DrizzleAdapter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Drop the current database and run all migrate up functions
|
|
4
|
+
*/
|
|
5
|
+
export declare function migrateFresh(this: DrizzleAdapter, { forceAcceptWarning }: {
|
|
6
|
+
forceAcceptWarning?: boolean;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=migrateFresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,YAAY,CAAA;AAI3D;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,cAAc,EACpB,EAAE,kBAA0B,EAAE;;CAAA,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgEf"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
|
+
import prompts from 'prompts';
|
|
3
|
+
import { parseError } from './utilities/parseError.js';
|
|
4
|
+
/**
|
|
5
|
+
* Drop the current database and run all migrate up functions
|
|
6
|
+
*/ export async function migrateFresh({ forceAcceptWarning = false }) {
|
|
7
|
+
const { payload } = this;
|
|
8
|
+
if (forceAcceptWarning === false) {
|
|
9
|
+
const { confirm: acceptWarning } = await prompts({
|
|
10
|
+
name: 'confirm',
|
|
11
|
+
type: 'confirm',
|
|
12
|
+
initial: false,
|
|
13
|
+
message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
|
|
14
|
+
}, {
|
|
15
|
+
onCancel: ()=>{
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (!acceptWarning) {
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
payload.logger.info({
|
|
24
|
+
msg: `Dropping database.`
|
|
25
|
+
});
|
|
26
|
+
await this.dropDatabase({
|
|
27
|
+
adapter: this
|
|
28
|
+
});
|
|
29
|
+
const migrationFiles = await readMigrationFiles({
|
|
30
|
+
payload
|
|
31
|
+
});
|
|
32
|
+
payload.logger.debug({
|
|
33
|
+
msg: `Found ${migrationFiles.length} migration files.`
|
|
34
|
+
});
|
|
35
|
+
const req = {
|
|
36
|
+
payload
|
|
37
|
+
};
|
|
38
|
+
// Run all migrate up
|
|
39
|
+
for (const migration of migrationFiles){
|
|
40
|
+
payload.logger.info({
|
|
41
|
+
msg: `Migrating: ${migration.name}`
|
|
42
|
+
});
|
|
43
|
+
try {
|
|
44
|
+
const start = Date.now();
|
|
45
|
+
await initTransaction(req);
|
|
46
|
+
const adapter = payload.db;
|
|
47
|
+
const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle;
|
|
48
|
+
await migration.up({
|
|
49
|
+
db,
|
|
50
|
+
payload,
|
|
51
|
+
req
|
|
52
|
+
});
|
|
53
|
+
await payload.create({
|
|
54
|
+
collection: 'payload-migrations',
|
|
55
|
+
data: {
|
|
56
|
+
name: migration.name,
|
|
57
|
+
batch: 1
|
|
58
|
+
},
|
|
59
|
+
req
|
|
60
|
+
});
|
|
61
|
+
await commitTransaction(req);
|
|
62
|
+
payload.logger.info({
|
|
63
|
+
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
|
|
64
|
+
});
|
|
65
|
+
} catch (err) {
|
|
66
|
+
await killTransaction(req);
|
|
67
|
+
payload.logger.error({
|
|
68
|
+
err,
|
|
69
|
+
msg: parseError(err, `Error running migration ${migration.name}. Rolling back`)
|
|
70
|
+
});
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=migrateFresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { commitTransaction, initTransaction, killTransaction, readMigrationFiles } from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter, Migration } from './types.js'\n\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Drop the current database and run all migrate up functions\n */\nexport async function migrateFresh(\n this: DrizzleAdapter,\n { forceAcceptWarning = false },\n): Promise<void> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n const { confirm: acceptWarning } = await prompts(\n {\n name: 'confirm',\n type: 'confirm',\n initial: false,\n message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`,\n },\n {\n onCancel: () => {\n process.exit(0)\n },\n },\n )\n\n if (!acceptWarning) {\n process.exit(0)\n }\n }\n\n payload.logger.info({\n msg: `Dropping database.`,\n })\n\n await this.dropDatabase({ adapter: this })\n\n const migrationFiles = await readMigrationFiles({ payload })\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n const req = { payload } as PayloadRequest\n // Run all migrate up\n for (const migration of migrationFiles) {\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n try {\n const start = Date.now()\n await initTransaction(req)\n const adapter = payload.db as DrizzleAdapter\n const db = adapter?.sessions[await req.transactionID]?.db || adapter.drizzle\n await migration.up({ db, payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n batch: 1,\n },\n req,\n })\n await commitTransaction(req)\n\n payload.logger.info({ msg: `Migrated: ${migration.name} (${Date.now() - start}ms)` })\n } catch (err: unknown) {\n await killTransaction(req)\n payload.logger.error({\n err,\n msg: parseError(err, `Error running migration ${migration.name}. Rolling back`),\n })\n process.exit(1)\n }\n }\n}\n"],"names":["commitTransaction","initTransaction","killTransaction","readMigrationFiles","prompts","parseError","migrateFresh","forceAcceptWarning","payload","confirm","acceptWarning","name","type","initial","message","onCancel","process","exit","logger","info","msg","dropDatabase","adapter","migrationFiles","debug","length","req","migration","start","Date","now","db","sessions","transactionID","drizzle","up","create","collection","data","batch","err","error"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,UAAS;AACjG,OAAOC,aAAa,UAAS;AAI7B,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAE;IAE9B,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAID,uBAAuB,OAAO;QAChC,MAAM,EAAEE,SAASC,aAAa,EAAE,GAAG,MAAMN,QACvC;YACEO,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G,GACA;YACEC,UAAU;gBACRC,QAAQC,IAAI,CAAC;YACf;QACF;QAGF,IAAI,CAACP,eAAe;YAClBM,QAAQC,IAAI,CAAC;QACf;IACF;IAEAT,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,YAAY,CAAC;QAAEC,SAAS,IAAI;IAAC;IAExC,MAAMC,iBAAiB,MAAMpB,mBAAmB;QAAEK;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM;QAAElB;IAAQ;IACtB,qBAAqB;IACrB,KAAK,MAAMmB,aAAaJ,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,CAAC;QAAC;QAC1D,IAAI;YACF,MAAMiB,QAAQC,KAAKC,GAAG;YACtB,MAAM7B,gBAAgByB;YACtB,MAAMJ,UAAUd,QAAQuB,EAAE;YAC1B,MAAMA,KAAKT,SAASU,QAAQ,CAAC,MAAMN,IAAIO,aAAa,CAAC,EAAEF,MAAMT,QAAQY,OAAO;YAC5E,MAAMP,UAAUQ,EAAE,CAAC;gBAAEJ;gBAAIvB;gBAASkB;YAAI;YACtC,MAAMlB,QAAQ4B,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJ3B,MAAMgB,UAAUhB,IAAI;oBACpB4B,OAAO;gBACT;gBACAb;YACF;YACA,MAAM1B,kBAAkB0B;YAExBlB,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEO,UAAUhB,IAAI,CAAC,EAAE,EAAEkB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOY,KAAc;YACrB,MAAMtC,gBAAgBwB;YACtBlB,QAAQU,MAAM,CAACuB,KAAK,CAAC;gBACnBD;gBACApB,KAAKf,WAAWmC,KAAK,CAAC,wBAAwB,EAAEb,UAAUhB,IAAI,CAAC,cAAc,CAAC;YAChF;YACAK,QAAQC,IAAI,CAAC;QACf;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../src/migrateRefresh.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,iBAuFxD"}
|