@payloadcms/drizzle 4.0.0-internal.43ccea7 → 4.0.0-internal.44ac9c8
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/dist/createTableName.d.ts.map +1 -1
- package/dist/createTableName.js +2 -7
- package/dist/createTableName.js.map +1 -1
- package/dist/exports/postgres.d.ts +2 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +2 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.d.ts +38 -0
- package/dist/find/buildPolymorphicJoinQuery.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinQuery.js +135 -0
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts +20 -0
- package/dist/find/buildPolymorphicJoinWhere.d.ts.map +1 -0
- package/dist/find/buildPolymorphicJoinWhere.js +301 -0
- package/dist/find/buildPolymorphicJoinWhere.js.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts +37 -0
- package/dist/find/createPolymorphicJoinWherePlan.d.ts.map +1 -0
- package/dist/find/createPolymorphicJoinWherePlan.js +191 -0
- package/dist/find/createPolymorphicJoinWherePlan.js.map +1 -0
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +19 -191
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +41 -15
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts +2 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +17 -4
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts +4 -2
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +26 -9
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts +2 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +20 -5
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts +2 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +18 -4
- package/dist/migrateReset.js.map +1 -1
- package/dist/migrateStatus.d.ts +2 -1
- package/dist/migrateStatus.d.ts.map +1 -1
- package/dist/migrateStatus.js +11 -6
- package/dist/migrateStatus.js.map +1 -1
- package/dist/postgres/createDatabase.d.ts.map +1 -1
- package/dist/postgres/createExtensions.d.ts.map +1 -1
- package/dist/postgres/createJSONQuery/index.d.ts.map +1 -1
- package/dist/postgres/createJSONQuery/index.js +3 -3
- package/dist/postgres/createJSONQuery/index.js.map +1 -1
- package/dist/postgres/init.d.ts.map +1 -1
- package/dist/postgres/init.js +6 -0
- package/dist/postgres/init.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js +8 -4
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/index.js.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -1
- package/dist/postgres/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -1
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts +15 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.d.ts.map +1 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js +25 -0
- package/dist/postgres/query/assertOperatorHandlerExtensionsInstalled.js.map +1 -0
- package/dist/postgres/query/postgresUnaccent.d.ts +13 -0
- package/dist/postgres/query/postgresUnaccent.d.ts.map +1 -0
- package/dist/postgres/query/postgresUnaccent.js +40 -0
- package/dist/postgres/query/postgresUnaccent.js.map +1 -0
- package/dist/postgres/schema/buildDrizzleTable.d.ts.map +1 -1
- package/dist/postgres/schema/geometryColumn.d.ts +2 -2
- package/dist/postgres/schema/geometryColumn.d.ts.map +1 -1
- package/dist/postgres/types.d.ts +13 -2
- package/dist/postgres/types.d.ts.map +1 -1
- package/dist/postgres/types.js.map +1 -1
- package/dist/queries/addJoinTable.d.ts +1 -1
- package/dist/queries/addJoinTable.d.ts.map +1 -1
- package/dist/queries/buildOperatorConstraint.d.ts +22 -0
- package/dist/queries/buildOperatorConstraint.d.ts.map +1 -0
- package/dist/queries/buildOperatorConstraint.js +63 -0
- package/dist/queries/buildOperatorConstraint.js.map +1 -0
- package/dist/queries/buildOrderBy.d.ts +1 -1
- package/dist/queries/buildOrderBy.d.ts.map +1 -1
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/getTableAlias.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +12 -3
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +59 -27
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/operatorMap.d.ts +7 -3
- package/dist/queries/operatorMap.d.ts.map +1 -1
- package/dist/queries/operatorMap.js.map +1 -1
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +262 -10
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/resolveRelationshipPath.d.ts +36 -0
- package/dist/queries/resolveRelationshipPath.d.ts.map +1 -0
- package/dist/queries/resolveRelationshipPath.js +66 -0
- package/dist/queries/resolveRelationshipPath.js.map +1 -0
- package/dist/queries/sanitizeQueryValue.d.ts.map +1 -1
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/queries/validateOperatorHandlers.d.ts +8 -0
- package/dist/queries/validateOperatorHandlers.d.ts.map +1 -0
- package/dist/queries/validateOperatorHandlers.js +30 -0
- package/dist/queries/validateOperatorHandlers.js.map +1 -0
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/buildDrizzleRelations.d.ts.map +1 -1
- package/dist/schema/buildRawSchema.d.ts.map +1 -1
- package/dist/schema/idToUUID.d.ts.map +1 -1
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +5 -5
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/schema/withDefault.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js +3 -2
- package/dist/sqlite/createJSONQuery/convertPathToJSONTraversal.js.map +1 -1
- package/dist/sqlite/createJSONQuery/index.d.ts.map +1 -1
- package/dist/sqlite/createJSONQuery/index.js +6 -5
- package/dist/sqlite/createJSONQuery/index.js.map +1 -1
- package/dist/sqlite/insert.d.ts.map +1 -1
- package/dist/sqlite/insert.js +4 -1
- package/dist/sqlite/insert.js.map +1 -1
- package/dist/transform/read/hasManyNumber.d.ts.map +1 -1
- package/dist/transform/read/hasManyText.d.ts.map +1 -1
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/relationship.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/array.d.ts.map +1 -1
- package/dist/transform/write/blocks.d.ts.map +1 -1
- package/dist/transform/write/index.d.ts.map +1 -1
- package/dist/transform/write/numbers.d.ts.map +1 -1
- package/dist/transform/write/relationships.d.ts.map +1 -1
- package/dist/transform/write/selects.d.ts.map +1 -1
- package/dist/transform/write/texts.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +8 -14
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/types.d.ts +50 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/updateJobs.d.ts.map +1 -1
- package/dist/updateJobs.js +37 -0
- package/dist/updateJobs.js.map +1 -1
- package/dist/updateOne.d.ts.map +1 -1
- package/dist/updateOne.js +41 -1
- package/dist/updateOne.js.map +1 -1
- package/dist/upsertRow/deleteExistingArrayRows.d.ts.map +1 -1
- package/dist/upsertRow/deleteExistingRowsByPath.d.ts.map +1 -1
- package/dist/upsertRow/handleUpsertError.d.ts.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +25 -5
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/insertArrays.d.ts.map +1 -1
- package/dist/upsertRow/shouldUseOptimizedUpsertRow.d.ts.map +1 -1
- package/dist/utilities/appendPrefixToKeys.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.d.ts.map +1 -1
- package/dist/utilities/buildCreateMigration.js +12 -8
- package/dist/utilities/buildCreateMigration.js.map +1 -1
- package/dist/utilities/buildForeignKeyName.d.ts.map +1 -1
- package/dist/utilities/buildForeignKeyName.js +3 -2
- package/dist/utilities/buildForeignKeyName.js.map +1 -1
- package/dist/utilities/buildIndexName.d.ts.map +1 -1
- package/dist/utilities/buildIndexName.js +3 -2
- package/dist/utilities/buildIndexName.js.map +1 -1
- package/dist/utilities/checkTruncatedIdentifiers.d.ts +13 -0
- package/dist/utilities/checkTruncatedIdentifiers.d.ts.map +1 -0
- package/dist/utilities/checkTruncatedIdentifiers.js +56 -0
- package/dist/utilities/checkTruncatedIdentifiers.js.map +1 -0
- package/dist/utilities/createBlocksMap.d.ts.map +1 -1
- package/dist/utilities/createRelationshipMap.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +3 -0
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/escapeSQLValue.d.ts.map +1 -1
- package/dist/utilities/executeSchemaHooks.d.ts.map +1 -1
- package/dist/utilities/extendDrizzleTable.d.ts.map +1 -1
- package/dist/utilities/getArrayRelationName.d.ts.map +1 -1
- package/dist/utilities/getCollectionIdType.d.ts.map +1 -1
- package/dist/utilities/getMigrationTemplate.d.ts.map +1 -1
- package/dist/utilities/getNameFromDrizzleTable.d.ts.map +1 -1
- package/dist/utilities/getPrimaryDb.d.ts +1 -1
- package/dist/utilities/getPrimaryDb.d.ts.map +1 -1
- package/dist/utilities/getTransaction.d.ts +1 -1
- package/dist/utilities/getTransaction.d.ts.map +1 -1
- package/dist/utilities/hasLocalesTable.d.ts.map +1 -1
- package/dist/utilities/isPolymorphicRelationship.d.ts.map +1 -1
- package/dist/utilities/isUUIDType.d.ts.map +1 -1
- package/dist/utilities/json.d.ts.map +1 -1
- package/dist/utilities/migrationTableExists.d.ts.map +1 -1
- package/dist/utilities/parseError.d.ts.map +1 -1
- package/dist/utilities/parseJSONPathSegment.d.ts +9 -0
- package/dist/utilities/parseJSONPathSegment.d.ts.map +1 -0
- package/dist/utilities/parseJSONPathSegment.js +17 -0
- package/dist/utilities/parseJSONPathSegment.js.map +1 -0
- package/dist/utilities/pushDevSchema.d.ts.map +1 -1
- package/dist/utilities/rawConstraint.d.ts.map +1 -1
- package/dist/utilities/sanitizePathSegment.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts +1 -5
- package/dist/utilities/validateExistingBlockIsIdentical.d.ts.map +1 -1
- package/dist/utilities/validateExistingBlockIsIdentical.js.map +1 -1
- package/dist/utilities/validateIdentifierLength.d.ts +12 -0
- package/dist/utilities/validateIdentifierLength.d.ts.map +1 -0
- package/dist/utilities/validateIdentifierLength.js +18 -0
- package/dist/utilities/validateIdentifierLength.js.map +1 -0
- package/package.json +4 -4
- package/dist/upsertRow/handleUpsertError.spec.js +0 -42
- package/dist/upsertRow/handleUpsertError.spec.js.map +0 -1
- package/dist/utilities/isValidStringID.spec.js +0 -15
- package/dist/utilities/isValidStringID.spec.js.map +0 -1
package/dist/migrateFresh.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
-
import { commitTransaction,
|
|
1
|
+
import { commitTransaction, createPayloadRequest, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
2
|
import prompts from 'prompts';
|
|
3
3
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
4
4
|
import { parseError } from './utilities/parseError.js';
|
|
5
5
|
/**
|
|
6
6
|
* Drop the current database and run all migrate up functions
|
|
7
|
-
*/ export async function migrateFresh({ forceAcceptWarning = false }) {
|
|
7
|
+
*/ export async function migrateFresh({ forceAcceptWarning = false, shouldPrompt = true }) {
|
|
8
8
|
const { payload } = this;
|
|
9
9
|
if (forceAcceptWarning === false) {
|
|
10
|
+
if (!shouldPrompt) {
|
|
11
|
+
return {
|
|
12
|
+
cancelled: true,
|
|
13
|
+
migrated: [],
|
|
14
|
+
rolledBack: []
|
|
15
|
+
};
|
|
16
|
+
}
|
|
10
17
|
const { confirm: acceptWarning } = await prompts({
|
|
11
18
|
name: 'confirm',
|
|
12
19
|
type: 'confirm',
|
|
13
20
|
initial: false,
|
|
14
21
|
message: `WARNING: This will drop your database and run all migrations. Are you sure you want to proceed?`
|
|
15
|
-
}, {
|
|
16
|
-
onCancel: ()=>{
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
22
|
});
|
|
20
23
|
if (!acceptWarning) {
|
|
21
|
-
|
|
24
|
+
return {
|
|
25
|
+
cancelled: true,
|
|
26
|
+
migrated: [],
|
|
27
|
+
rolledBack: []
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
payload.logger.info({
|
|
@@ -33,7 +40,10 @@ import { parseError } from './utilities/parseError.js';
|
|
|
33
40
|
payload.logger.debug({
|
|
34
41
|
msg: `Found ${migrationFiles.length} migration files.`
|
|
35
42
|
});
|
|
36
|
-
const req = await
|
|
43
|
+
const req = await createPayloadRequest({
|
|
44
|
+
payload
|
|
45
|
+
});
|
|
46
|
+
const migrated = [];
|
|
37
47
|
if ('createExtensions' in this && typeof this.createExtensions === 'function') {
|
|
38
48
|
await this.createExtensions();
|
|
39
49
|
}
|
|
@@ -57,9 +67,11 @@ import { parseError } from './utilities/parseError.js';
|
|
|
57
67
|
name: migration.name,
|
|
58
68
|
batch: 1
|
|
59
69
|
},
|
|
70
|
+
overrideAccess: true,
|
|
60
71
|
req
|
|
61
72
|
});
|
|
62
73
|
await commitTransaction(req);
|
|
74
|
+
migrated.push(migration.name);
|
|
63
75
|
payload.logger.info({
|
|
64
76
|
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
|
|
65
77
|
});
|
|
@@ -69,9 +81,14 @@ import { parseError } from './utilities/parseError.js';
|
|
|
69
81
|
err,
|
|
70
82
|
msg: parseError(err, `Error running migration ${migration.name}. Rolling back`)
|
|
71
83
|
});
|
|
72
|
-
|
|
84
|
+
throw err;
|
|
73
85
|
}
|
|
74
86
|
}
|
|
87
|
+
return {
|
|
88
|
+
batch: 1,
|
|
89
|
+
migrated,
|
|
90
|
+
rolledBack: []
|
|
91
|
+
};
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
//# sourceMappingURL=migrateFresh.js.map
|
package/dist/migrateFresh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import {\n commitTransaction,\n
|
|
1
|
+
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\n commitTransaction,\n createPayloadRequest,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\nimport prompts from 'prompts'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { getTransaction } from './utilities/getTransaction.js'\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, shouldPrompt = true },\n): Promise<MigrationResult> {\n const { payload } = this\n\n if (forceAcceptWarning === false) {\n if (!shouldPrompt) {\n return { cancelled: true, migrated: [], rolledBack: [] }\n }\n\n const { confirm: acceptWarning } = await prompts({\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 if (!acceptWarning) {\n return { cancelled: true, migrated: [], rolledBack: [] }\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 = await createPayloadRequest({ payload })\n const migrated: string[] = []\n\n if ('createExtensions' in this && typeof this.createExtensions === 'function') {\n await this.createExtensions()\n }\n\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 db = await getTransaction(this, req)\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 overrideAccess: true,\n req,\n })\n await commitTransaction(req)\n migrated.push(migration.name)\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 throw err\n }\n }\n\n return { batch: 1, migrated, rolledBack: [] }\n}\n"],"names":["commitTransaction","createPayloadRequest","initTransaction","killTransaction","readMigrationFiles","prompts","getTransaction","parseError","migrateFresh","forceAcceptWarning","shouldPrompt","payload","cancelled","migrated","rolledBack","confirm","acceptWarning","name","type","initial","message","logger","info","msg","dropDatabase","adapter","migrationFiles","debug","length","req","createExtensions","migration","start","Date","now","db","up","create","collection","data","batch","overrideAccess","push","err","error"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAChB,OAAOC,aAAa,UAAS;AAI7B,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC,aAEpB,EAAEC,qBAAqB,KAAK,EAAEC,eAAe,IAAI,EAAE;IAEnD,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IAExB,IAAIF,uBAAuB,OAAO;QAChC,IAAI,CAACC,cAAc;YACjB,OAAO;gBAAEE,WAAW;gBAAMC,UAAU,EAAE;gBAAEC,YAAY,EAAE;YAAC;QACzD;QAEA,MAAM,EAAEC,SAASC,aAAa,EAAE,GAAG,MAAMX,QAAQ;YAC/CY,MAAM;YACNC,MAAM;YACNC,SAAS;YACTC,SAAS,CAAC,+FAA+F,CAAC;QAC5G;QAEA,IAAI,CAACJ,eAAe;YAClB,OAAO;gBAAEJ,WAAW;gBAAMC,UAAU,EAAE;gBAAEC,YAAY,EAAE;YAAC;QACzD;IACF;IAEAH,QAAQU,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,kBAAkB,CAAC;IAC3B;IAEA,MAAM,IAAI,CAACC,YAAY,CAAC;QAAEC,SAAS,IAAI;IAAC;IAExC,MAAMC,iBAAiB,MAAMtB,mBAAmB;QAAEO;IAAQ;IAC1DA,QAAQU,MAAM,CAACM,KAAK,CAAC;QACnBJ,KAAK,CAAC,MAAM,EAAEG,eAAeE,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,MAAMC,MAAM,MAAM5B,qBAAqB;QAAEU;IAAQ;IACjD,MAAME,WAAqB,EAAE;IAE7B,IAAI,sBAAsB,IAAI,IAAI,OAAO,IAAI,CAACiB,gBAAgB,KAAK,YAAY;QAC7E,MAAM,IAAI,CAACA,gBAAgB;IAC7B;IAEA,qBAAqB;IACrB,KAAK,MAAMC,aAAaL,eAAgB;QACtCf,QAAQU,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK,CAAC,WAAW,EAAEQ,UAAUd,IAAI,EAAE;QAAC;QAC1D,IAAI;YACF,MAAMe,QAAQC,KAAKC,GAAG;YACtB,MAAMhC,gBAAgB2B;YACtB,MAAMM,KAAK,MAAM7B,eAAe,IAAI,EAAEuB;YACtC,MAAME,UAAUK,EAAE,CAAC;gBAAED;gBAAIxB;gBAASkB;YAAI;YACtC,MAAMlB,QAAQ0B,MAAM,CAAC;gBACnBC,YAAY;gBACZC,MAAM;oBACJtB,MAAMc,UAAUd,IAAI;oBACpBuB,OAAO;gBACT;gBACAC,gBAAgB;gBAChBZ;YACF;YACA,MAAM7B,kBAAkB6B;YACxBhB,SAAS6B,IAAI,CAACX,UAAUd,IAAI;YAE5BN,QAAQU,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEQ,UAAUd,IAAI,CAAC,EAAE,EAAEgB,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOW,KAAc;YACrB,MAAMxC,gBAAgB0B;YACtBlB,QAAQU,MAAM,CAACuB,KAAK,CAAC;gBACnBD;gBACApB,KAAKhB,WAAWoC,KAAK,CAAC,wBAAwB,EAAEZ,UAAUd,IAAI,CAAC,cAAc,CAAC;YAChF;YACA,MAAM0B;QACR;IACF;IAEA,OAAO;QAAEH,OAAO;QAAG3B;QAAUC,YAAY,EAAE;IAAC;AAC9C"}
|
package/dist/migrateRefresh.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { MigrationResult } from 'payload';
|
|
1
2
|
import type { DrizzleAdapter } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Run all migration down functions before running up
|
|
4
5
|
*/
|
|
5
|
-
export declare function migrateRefresh(this: DrizzleAdapter): Promise<
|
|
6
|
+
export declare function migrateRefresh(this: DrizzleAdapter): Promise<MigrationResult>;
|
|
6
7
|
//# sourceMappingURL=migrateRefresh.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../src/migrateRefresh.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrateRefresh.d.ts","sourceRoot":"","sources":["../src/migrateRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAW9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD;;GAEG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAgGnF"}
|
package/dist/migrateRefresh.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commitTransaction,
|
|
1
|
+
import { commitTransaction, createPayloadRequest, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
2
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
3
3
|
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
4
4
|
import { parseError } from './utilities/parseError.js';
|
|
@@ -16,12 +16,19 @@ import { parseError } from './utilities/parseError.js';
|
|
|
16
16
|
payload.logger.info({
|
|
17
17
|
msg: 'No migrations to rollback.'
|
|
18
18
|
});
|
|
19
|
-
return
|
|
19
|
+
return {
|
|
20
|
+
migrated: [],
|
|
21
|
+
rolledBack: []
|
|
22
|
+
};
|
|
20
23
|
}
|
|
21
24
|
payload.logger.info({
|
|
22
25
|
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
|
|
23
26
|
});
|
|
24
|
-
const req = await
|
|
27
|
+
const req = await createPayloadRequest({
|
|
28
|
+
payload
|
|
29
|
+
});
|
|
30
|
+
const migrated = [];
|
|
31
|
+
const rolledBack = [];
|
|
25
32
|
// Reverse order of migrations to rollback
|
|
26
33
|
existingMigrations.reverse();
|
|
27
34
|
for (const migration of existingMigrations){
|
|
@@ -48,6 +55,7 @@ import { parseError } from './utilities/parseError.js';
|
|
|
48
55
|
if (tableExists) {
|
|
49
56
|
await payload.delete({
|
|
50
57
|
collection: 'payload-migrations',
|
|
58
|
+
overrideAccess: true,
|
|
51
59
|
req,
|
|
52
60
|
where: {
|
|
53
61
|
name: {
|
|
@@ -57,13 +65,14 @@ import { parseError } from './utilities/parseError.js';
|
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
await commitTransaction(req);
|
|
68
|
+
rolledBack.push(migration.name);
|
|
60
69
|
} catch (err) {
|
|
61
70
|
await killTransaction(req);
|
|
62
71
|
payload.logger.error({
|
|
63
72
|
err,
|
|
64
73
|
msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
|
|
65
74
|
});
|
|
66
|
-
|
|
75
|
+
throw err;
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
// Run all migrate up
|
|
@@ -84,9 +93,11 @@ import { parseError } from './utilities/parseError.js';
|
|
|
84
93
|
name: migration.name,
|
|
85
94
|
executed: true
|
|
86
95
|
},
|
|
96
|
+
overrideAccess: true,
|
|
87
97
|
req
|
|
88
98
|
});
|
|
89
99
|
await commitTransaction(req);
|
|
100
|
+
migrated.push(migration.name);
|
|
90
101
|
payload.logger.info({
|
|
91
102
|
msg: `Migrated: ${migration.name} (${Date.now() - start}ms)`
|
|
92
103
|
});
|
|
@@ -96,9 +107,13 @@ import { parseError } from './utilities/parseError.js';
|
|
|
96
107
|
err,
|
|
97
108
|
msg: parseError(err, `Error running migration ${migration.name}. Rolling back.`)
|
|
98
109
|
});
|
|
99
|
-
|
|
110
|
+
throw err;
|
|
100
111
|
}
|
|
101
112
|
}
|
|
113
|
+
return {
|
|
114
|
+
migrated,
|
|
115
|
+
rolledBack
|
|
116
|
+
};
|
|
102
117
|
}
|
|
103
118
|
|
|
104
119
|
//# sourceMappingURL=migrateRefresh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["import {\n commitTransaction,\n
|
|
1
|
+
{"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\n commitTransaction,\n createPayloadRequest,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { getTransaction } from './utilities/getTransaction.js'\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\nimport { parseError } from './utilities/parseError.js'\n\n/**\n * Run all migration down functions before running up\n */\nexport async function migrateRefresh(this: DrizzleAdapter): Promise<MigrationResult> {\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 { migrated: [], rolledBack: [] }\n }\n\n payload.logger.info({\n msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`,\n })\n\n const req = await createPayloadRequest({ payload })\n const migrated: string[] = []\n const rolledBack: string[] = []\n\n // Reverse order of migrations to rollback\n existingMigrations.reverse()\n\n for (const migration of existingMigrations) {\n try {\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 payload.logger.info({ msg: `Migrating down: ${migration.name}` })\n const start = Date.now()\n await initTransaction(req)\n const db = await getTransaction(this, req)\n await migrationFile.down({ db, payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migration.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this, db)\n if (tableExists) {\n await payload.delete({\n collection: 'payload-migrations',\n overrideAccess: true,\n req,\n where: {\n name: {\n equals: migration.name,\n },\n },\n })\n }\n await commitTransaction(req)\n rolledBack.push(migration.name)\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 throw err\n }\n }\n\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 await migration.up({ payload, req })\n await payload.create({\n collection: 'payload-migrations',\n data: {\n name: migration.name,\n executed: true,\n },\n overrideAccess: true,\n req,\n })\n await commitTransaction(req)\n migrated.push(migration.name)\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 throw err\n }\n }\n\n return { migrated, rolledBack }\n}\n"],"names":["commitTransaction","createPayloadRequest","getMigrations","initTransaction","killTransaction","readMigrationFiles","getTransaction","migrationTableExists","parseError","migrateRefresh","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","migrated","rolledBack","req","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","db","down","tableExists","delete","collection","overrideAccess","where","equals","push","err","error","up","create","data","executed"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,oBAAoB,EACpBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMN,mBAAmB;QAAEK;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAEC,WAAW,EAAE,GAAG,MAAMX,cAAc;QAC9DQ;IACF;IAEA,IAAI,CAACE,oBAAoBE,QAAQ;QAC/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Reset.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { MigrationResult } from 'payload';
|
|
1
2
|
import type { DrizzleAdapter } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Run all migrate down functions
|
|
4
5
|
*/
|
|
5
|
-
export declare function migrateReset(this: DrizzleAdapter): Promise<
|
|
6
|
+
export declare function migrateReset(this: DrizzleAdapter): Promise<MigrationResult>;
|
|
6
7
|
//# sourceMappingURL=migrateReset.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateReset.d.ts","sourceRoot":"","sources":["../src/migrateReset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrateReset.d.ts","sourceRoot":"","sources":["../src/migrateReset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAW9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD;;GAEG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAkFjF"}
|
package/dist/migrateReset.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commitTransaction,
|
|
1
|
+
import { commitTransaction, createPayloadRequest, getMigrations, initTransaction, killTransaction, readMigrationFiles } from 'payload';
|
|
2
2
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
3
3
|
import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
4
4
|
/**
|
|
@@ -15,10 +15,16 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
15
15
|
payload.logger.info({
|
|
16
16
|
msg: 'No migrations to reset.'
|
|
17
17
|
});
|
|
18
|
-
return
|
|
18
|
+
return {
|
|
19
|
+
migrated: [],
|
|
20
|
+
rolledBack: []
|
|
21
|
+
};
|
|
19
22
|
}
|
|
20
|
-
const req = await
|
|
23
|
+
const req = await createPayloadRequest({
|
|
24
|
+
payload
|
|
25
|
+
});
|
|
21
26
|
existingMigrations.reverse();
|
|
27
|
+
const rolledBack = [];
|
|
22
28
|
// Rollback all migrations in order
|
|
23
29
|
for (const migration of existingMigrations){
|
|
24
30
|
const migrationFile = migrationFiles.find((m)=>m.name === migration.name);
|
|
@@ -45,10 +51,12 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
45
51
|
await payload.delete({
|
|
46
52
|
id: migration.id,
|
|
47
53
|
collection: 'payload-migrations',
|
|
54
|
+
overrideAccess: true,
|
|
48
55
|
req
|
|
49
56
|
});
|
|
50
57
|
}
|
|
51
58
|
await commitTransaction(req);
|
|
59
|
+
rolledBack.push(migrationFile.name);
|
|
52
60
|
} catch (err) {
|
|
53
61
|
let msg = `Error running migration ${migrationFile.name}.`;
|
|
54
62
|
if (err instanceof Error) {
|
|
@@ -59,7 +67,7 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
59
67
|
err,
|
|
60
68
|
msg
|
|
61
69
|
});
|
|
62
|
-
|
|
70
|
+
throw err;
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
// Delete dev migration
|
|
@@ -68,6 +76,7 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
68
76
|
try {
|
|
69
77
|
await payload.delete({
|
|
70
78
|
collection: 'payload-migrations',
|
|
79
|
+
overrideAccess: true,
|
|
71
80
|
where: {
|
|
72
81
|
batch: {
|
|
73
82
|
equals: -1
|
|
@@ -79,8 +88,13 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
79
88
|
err,
|
|
80
89
|
msg: 'Error deleting dev migration'
|
|
81
90
|
});
|
|
91
|
+
throw err;
|
|
82
92
|
}
|
|
83
93
|
}
|
|
94
|
+
return {
|
|
95
|
+
migrated: [],
|
|
96
|
+
rolledBack
|
|
97
|
+
};
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
//# sourceMappingURL=migrateReset.js.map
|
package/dist/migrateReset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["import {\n commitTransaction,\n
|
|
1
|
+
{"version":3,"sources":["../src/migrateReset.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\n commitTransaction,\n createPayloadRequest,\n getMigrations,\n initTransaction,\n killTransaction,\n readMigrationFiles,\n} from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { getTransaction } from './utilities/getTransaction.js'\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\n/**\n * Run all migrate down functions\n */\nexport async function migrateReset(this: DrizzleAdapter): Promise<MigrationResult> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n const { existingMigrations } = await getMigrations({ payload })\n\n if (!existingMigrations?.length) {\n payload.logger.info({ msg: 'No migrations to reset.' })\n return { migrated: [], rolledBack: [] }\n }\n\n const req = await createPayloadRequest({ payload })\n\n existingMigrations.reverse()\n const rolledBack: string[] = []\n\n // Rollback all migrations in order\n for (const migration of existingMigrations) {\n const migrationFile = migrationFiles.find((m) => m.name === migration.name)\n try {\n if (!migrationFile) {\n throw new Error(`Migration ${migration.name} not found locally.`)\n }\n\n const start = Date.now()\n payload.logger.info({ msg: `Migrating down: ${migrationFile.name}` })\n await initTransaction(req)\n const db = await getTransaction(this, req)\n await migrationFile.down({ db, payload, req })\n payload.logger.info({\n msg: `Migrated down: ${migrationFile.name} (${Date.now() - start}ms)`,\n })\n\n const tableExists = await migrationTableExists(this, db)\n if (tableExists) {\n await payload.delete({\n id: migration.id,\n collection: 'payload-migrations',\n overrideAccess: true,\n req,\n })\n }\n\n await commitTransaction(req)\n rolledBack.push(migrationFile.name)\n } catch (err: unknown) {\n let msg = `Error running migration ${migrationFile.name}.`\n\n if (err instanceof Error) {\n msg += ` ${err.message}`\n }\n\n await killTransaction(req)\n payload.logger.error({\n err,\n msg,\n })\n throw err\n }\n }\n\n // Delete dev migration\n\n const tableExists = await migrationTableExists(this)\n if (tableExists) {\n try {\n await payload.delete({\n collection: 'payload-migrations',\n overrideAccess: true,\n where: {\n batch: {\n equals: -1,\n },\n },\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: 'Error deleting dev migration' })\n throw err\n }\n }\n\n return { migrated: [], rolledBack }\n}\n"],"names":["commitTransaction","createPayloadRequest","getMigrations","initTransaction","killTransaction","readMigrationFiles","getTransaction","migrationTableExists","migrateReset","payload","migrationFiles","existingMigrations","length","logger","info","msg","migrated","rolledBack","req","reverse","migration","migrationFile","find","m","name","Error","start","Date","now","db","down","tableExists","delete","id","collection","overrideAccess","push","err","message","error","where","batch","equals"],"mappings":"AAEA,SACEA,iBAAiB,EACjBC,oBAAoB,EACpBC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,kBAAkB,QACb,UAAS;AAIhB,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E;;CAEC,GACD,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAML,mBAAmB;QAAEI;IAAQ;IAE1D,MAAM,EAAEE,kBAAkB,EAAE,GAAG,MAAMT,cAAc;QAAEO;IAAQ;IAE7D,IAAI,CAACE,oBAAoBC,QAAQ;QAC/BH,QAAQI,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA0B;QACrD,OAAO;YAAEC,UAAU,EAAE;YAAEC,YAAY,EAAE;QAAC;IACxC;IAEA,MAAMC,MAAM,MAAMjB,qBAAqB;QAAEQ;IAAQ;IAEjDE,mBAAmBQ,OAAO;IAC1B,MAAMF,aAAuB,EAAE;IAE/B,mCAAmC;IACnC,KAAK,MAAMG,aAAaT,mBAAoB;QAC1C,MAAMU,gBAAgBX,eAAeY,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI;YACF,IAAI,CAACH,eAAe;gBAClB,MAAM,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,CAAC;oBACX;gBACF;YACF;QACF,EAAE,OAAOL,KAAc;YACrB5B,QAAQI,MAAM,CAAC0B,KAAK,CAAC;gBAAEF;gBAAKtB,KAAK;YAA+B;YAChE,MAAMsB;QACR;IACF;IAEA,OAAO;QAAErB,UAAU,EAAE;QAAEC;IAAW;AACpC"}
|
package/dist/migrateStatus.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MigrationStatus } from 'payload';
|
|
1
2
|
import type { DrizzleAdapter } from './types.js';
|
|
2
|
-
export declare function migrateStatus(this: DrizzleAdapter): Promise<
|
|
3
|
+
export declare function migrateStatus(this: DrizzleAdapter): Promise<MigrationStatus[]>;
|
|
3
4
|
//# sourceMappingURL=migrateStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateStatus.d.ts","sourceRoot":"","sources":["../src/migrateStatus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrateStatus.d.ts","sourceRoot":"","sources":["../src/migrateStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAK9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAIhD,wBAAsB,aAAa,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CA2CpF"}
|
package/dist/migrateStatus.js
CHANGED
|
@@ -21,24 +21,29 @@ export async function migrateStatus() {
|
|
|
21
21
|
payload.logger.info({
|
|
22
22
|
msg: 'No migrations found.'
|
|
23
23
|
});
|
|
24
|
-
return;
|
|
24
|
+
return [];
|
|
25
25
|
}
|
|
26
26
|
// Compare migration files to existing migrations
|
|
27
27
|
const statuses = migrationFiles.map((migration)=>{
|
|
28
28
|
const existingMigration = existingMigrations.find((m)=>m.name === migration.name);
|
|
29
29
|
return {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
name: migration.name,
|
|
31
|
+
batch: existingMigration?.batch,
|
|
32
|
+
ran: Boolean(existingMigration)
|
|
33
33
|
};
|
|
34
34
|
});
|
|
35
35
|
const p = new Table();
|
|
36
36
|
statuses.forEach((s)=>{
|
|
37
|
-
p.addRow(
|
|
38
|
-
|
|
37
|
+
p.addRow({
|
|
38
|
+
Batch: s.batch,
|
|
39
|
+
Name: s.name,
|
|
40
|
+
Ran: s.ran ? 'Yes' : 'No'
|
|
41
|
+
}, {
|
|
42
|
+
color: s.ran ? 'green' : 'red'
|
|
39
43
|
});
|
|
40
44
|
});
|
|
41
45
|
p.printTable();
|
|
46
|
+
return statuses;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
//# sourceMappingURL=migrateStatus.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: DrizzleAdapter): Promise<
|
|
1
|
+
{"version":3,"sources":["../src/migrateStatus.ts"],"sourcesContent":["import type { MigrationStatus } from 'payload'\n\nimport { Table } from 'console-table-printer'\nimport { getMigrations, readMigrationFiles } from 'payload'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { migrationTableExists } from './utilities/migrationTableExists.js'\n\nexport async function migrateStatus(this: DrizzleAdapter): Promise<MigrationStatus[]> {\n const { payload } = this\n const migrationFiles = await readMigrationFiles({ payload })\n\n payload.logger.debug({\n msg: `Found ${migrationFiles.length} migration files.`,\n })\n\n let existingMigrations = []\n const hasMigrationTable = await migrationTableExists(this)\n\n if (hasMigrationTable) {\n ;({ existingMigrations } = await getMigrations({ payload }))\n }\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations found.' })\n return []\n }\n\n // Compare migration files to existing migrations\n const statuses = migrationFiles.map((migration) => {\n const existingMigration = existingMigrations.find((m) => m.name === migration.name)\n return {\n name: migration.name,\n batch: existingMigration?.batch,\n ran: Boolean(existingMigration),\n }\n })\n\n const p = new Table()\n\n statuses.forEach((s) => {\n p.addRow(\n { Batch: s.batch, Name: s.name, Ran: s.ran ? 'Yes' : 'No' },\n {\n color: s.ran ? 'green' : 'red',\n },\n )\n })\n p.printTable()\n\n return statuses\n}\n"],"names":["Table","getMigrations","readMigrationFiles","migrationTableExists","migrateStatus","payload","migrationFiles","logger","debug","msg","length","existingMigrations","hasMigrationTable","info","statuses","map","migration","existingMigration","find","m","name","batch","ran","Boolean","p","forEach","s","addRow","Batch","Name","Ran","color","printTable"],"mappings":"AAEA,SAASA,KAAK,QAAQ,wBAAuB;AAC7C,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,UAAS;AAI3D,SAASC,oBAAoB,QAAQ,sCAAqC;AAE1E,OAAO,eAAeC;IACpB,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAMC,iBAAiB,MAAMJ,mBAAmB;QAAEG;IAAQ;IAE1DA,QAAQE,MAAM,CAACC,KAAK,CAAC;QACnBC,KAAK,CAAC,MAAM,EAAEH,eAAeI,MAAM,CAAC,iBAAiB,CAAC;IACxD;IAEA,IAAIC,qBAAqB,EAAE;IAC3B,MAAMC,oBAAoB,MAAMT,qBAAqB,IAAI;IAEzD,IAAIS,mBAAmB;;QACnB,CAAA,EAAED,kBAAkB,EAAE,GAAG,MAAMV,cAAc;YAAEI;QAAQ,EAAC;IAC5D;IAEA,IAAI,CAACC,eAAeI,MAAM,EAAE;QAC1BL,QAAQE,MAAM,CAACM,IAAI,CAAC;YAAEJ,KAAK;QAAuB;QAClD,OAAO,EAAE;IACX;IAEA,iDAAiD;IACjD,MAAMK,WAAWR,eAAeS,GAAG,CAAC,CAACC;QACnC,MAAMC,oBAAoBN,mBAAmBO,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAClF,OAAO;YACLA,MAAMJ,UAAUI,IAAI;YACpBC,OAAOJ,mBAAmBI;YAC1BC,KAAKC,QAAQN;QACf;IACF;IAEA,MAAMO,IAAI,IAAIxB;IAEdc,SAASW,OAAO,CAAC,CAACC;QAChBF,EAAEG,MAAM,CACN;YAAEC,OAAOF,EAAEL,KAAK;YAAEQ,MAAMH,EAAEN,IAAI;YAAEU,KAAKJ,EAAEJ,GAAG,GAAG,QAAQ;QAAK,GAC1D;YACES,OAAOL,EAAEJ,GAAG,GAAG,UAAU;QAC3B;IAEJ;IACAE,EAAEQ,UAAU;IAEZ,OAAOlB;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDatabase.d.ts","sourceRoot":"","sources":["../../src/postgres/createDatabase.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAgBrD,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"createDatabase.d.ts","sourceRoot":"","sources":["../../src/postgres/createDatabase.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAgBrD,KAAK,IAAI,GAAG;IACV;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AACD,eAAO,MAAM,cAAc,SAAyB,mBAAmB,SAAQ,IAAI,qBAkFlF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExtensions.d.ts","sourceRoot":"","sources":["../../src/postgres/createExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"createExtensions.d.ts","sourceRoot":"","sources":["../../src/postgres/createExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,eAAO,MAAM,gBAAgB,SAAyB,mBAAmB,KAAG,OAAO,CAAC,IAAI,CAUvF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAuCzD,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/postgres/createJSONQuery/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAuCzD,eAAO,MAAM,eAAe,8CAA+C,mBAAmB,WA8B7F,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIError } from 'payload';
|
|
2
2
|
import { SAFE_STRING_REGEX } from '../../utilities/escapeSQLValue.js';
|
|
3
|
-
import {
|
|
3
|
+
import { parseJSONPathSegment } from '../../utilities/parseJSONPathSegment.js';
|
|
4
4
|
const operatorMap = {
|
|
5
5
|
contains: '~',
|
|
6
6
|
equals: '==',
|
|
@@ -12,7 +12,7 @@ const operatorMap = {
|
|
|
12
12
|
};
|
|
13
13
|
const sanitizeValue = (value, operator)=>{
|
|
14
14
|
if (value === null) {
|
|
15
|
-
return `
|
|
15
|
+
return `null`;
|
|
16
16
|
}
|
|
17
17
|
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
18
18
|
return `${value}`;
|
|
@@ -33,7 +33,7 @@ const sanitizeValue = (value, operator)=>{
|
|
|
33
33
|
export const createJSONQuery = ({ column, operator, pathSegments, value })=>{
|
|
34
34
|
const columnName = typeof column === 'object' ? column.name : column;
|
|
35
35
|
const jsonPaths = pathSegments.slice(1).map((key)=>{
|
|
36
|
-
return `${
|
|
36
|
+
return `${parseJSONPathSegment(key).value}[*]`;
|
|
37
37
|
}).join('.');
|
|
38
38
|
const fullPath = pathSegments.length === 1 ? '$[*]' : `$.${jsonPaths}`;
|
|
39
39
|
let sql = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/postgres/createJSONQuery/index.ts"],"sourcesContent":["import { APIError } from 'payload'\n\nimport type { CreateJSONQueryArgs } from '../../types.js'\n\nimport { SAFE_STRING_REGEX } from '../../utilities/escapeSQLValue.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/postgres/createJSONQuery/index.ts"],"sourcesContent":["import { APIError } from 'payload'\n\nimport type { CreateJSONQueryArgs } from '../../types.js'\n\nimport { SAFE_STRING_REGEX } from '../../utilities/escapeSQLValue.js'\nimport { parseJSONPathSegment } from '../../utilities/parseJSONPathSegment.js'\n\nconst operatorMap: Record<string, string> = {\n contains: '~',\n equals: '==',\n in: 'in',\n like: 'like_regex',\n not_equals: '!=',\n not_in: 'in',\n not_like: '!like_regex',\n}\n\nconst sanitizeValue = (value: unknown, operator?: string): string => {\n if (value === null) {\n return `null`\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return `${value}`\n }\n\n if (typeof value !== 'string') {\n throw new Error('Invalid value type')\n }\n\n if (!SAFE_STRING_REGEX.test(value)) {\n throw new APIError(`${value} is not allowed as a JSON query value`, 400)\n }\n\n const escaped = value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')\n\n const prefix = ['like', 'not_like'].includes(operator ?? '') ? '(?i)' : ''\n\n return `\"${prefix}${escaped}\"`\n}\n\nexport const createJSONQuery = ({ column, operator, pathSegments, value }: CreateJSONQueryArgs) => {\n const columnName = typeof column === 'object' ? column.name : column\n const jsonPaths = pathSegments\n .slice(1)\n .map((key) => {\n return `${parseJSONPathSegment(key).value}[*]`\n })\n .join('.')\n\n const fullPath = pathSegments.length === 1 ? '$[*]' : `$.${jsonPaths}`\n\n let sql = ''\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(value)) {\n sql = '('\n value.forEach((item, i) => {\n sql = `${sql}${createJSONQuery({ column, operator: operator === 'in' ? 'equals' : 'not_equals', pathSegments, value: item })}${i === value.length - 1 ? '' : ` ${operator === 'in' ? 'OR' : 'AND'} `}`\n })\n sql = `${sql})`\n } else if (operator === 'exists') {\n sql = `${value === false ? 'NOT ' : ''}jsonb_path_exists(${columnName}, '${fullPath}')`\n } else if (['not_like'].includes(operator)) {\n const mappedOperator = operatorMap[operator]\n\n sql = `NOT jsonb_path_exists(${columnName}, '${fullPath} ? (@ ${mappedOperator.substring(1)} ${sanitizeValue(value, operator)})')`\n } else {\n sql = `jsonb_path_exists(${columnName}, '${fullPath} ? (@ ${operatorMap[operator]} ${sanitizeValue(value, operator)})')`\n }\n\n return sql\n}\n"],"names":["APIError","SAFE_STRING_REGEX","parseJSONPathSegment","operatorMap","contains","equals","in","like","not_equals","not_in","not_like","sanitizeValue","value","operator","Error","test","escaped","replace","prefix","includes","createJSONQuery","column","pathSegments","columnName","name","jsonPaths","slice","map","key","join","fullPath","length","sql","Array","isArray","forEach","item","i","mappedOperator","substring"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,oBAAoB,QAAQ,0CAAyC;AAE9E,MAAMC,cAAsC;IAC1CC,UAAU;IACVC,QAAQ;IACRC,IAAI;IACJC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,UAAU;AACZ;AAEA,MAAMC,gBAAgB,CAACC,OAAgBC;IACrC,IAAID,UAAU,MAAM;QAClB,OAAO,CAAC,IAAI,CAAC;IACf;IAEA,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,WAAW;QAC3D,OAAO,GAAGA,OAAO;IACnB;IAEA,IAAI,OAAOA,UAAU,UAAU;QAC7B,MAA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AG,kBAAkB,EAAEW,WAAW,GAAG,EAAEO,SAAS,EAAE,CAAC;IACzF,OAAO,IAAI;QAAC;KAAW,CAACX,QAAQ,CAACN,WAAW;QAC1C,MAAMyB,iBAAiBnC,WAAW,CAACU,SAAS;QAE5CmB,MAAM,CAAC,sBAAsB,EAAET,WAAW,GAAG,EAAEO,SAAS,MAAM,EAAEQ,eAAeC,SAAS,CAAC,GAAG,CAAC,EAAE5B,cAAcC,OAAOC,UAAU,GAAG,CAAC;IACpI,OAAO;QACLmB,MAAM,CAAC,kBAAkB,EAAET,WAAW,GAAG,EAAEO,SAAS,MAAM,EAAE3B,WAAW,CAACU,SAAS,CAAC,CAAC,EAAEF,cAAcC,OAAOC,UAAU,GAAG,CAAC;IAC1H;IAEA,OAAOmB;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/postgres/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAWnC,eAAO,MAAM,IAAI,EAAE,IAqClB,CAAA"}
|
package/dist/postgres/init.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js';
|
|
2
2
|
import { buildRawSchema } from '../schema/buildRawSchema.js';
|
|
3
|
+
import { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js';
|
|
3
4
|
import { executeSchemaHooks } from '../utilities/executeSchemaHooks.js';
|
|
4
5
|
import { buildDrizzleTable } from './schema/buildDrizzleTable.js';
|
|
5
6
|
import { setColumnID } from './schema/setColumnID.js';
|
|
@@ -14,6 +15,11 @@ export const init = async function init() {
|
|
|
14
15
|
type: 'beforeSchemaInit',
|
|
15
16
|
adapter: this
|
|
16
17
|
});
|
|
18
|
+
// Warn on identifiers Postgres will truncate past 63 chars; throw only when two collide.
|
|
19
|
+
checkTruncatedIdentifiers({
|
|
20
|
+
adapter: this,
|
|
21
|
+
logWarnings: process.env.NODE_ENV !== 'production'
|
|
22
|
+
});
|
|
17
23
|
if (this.payload.config.localization) {
|
|
18
24
|
this.enums.enum__locales = this.pgSchema.enum('_locales', this.payload.config.localization.locales.map(({ code })=>code));
|
|
19
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init } from 'payload'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js'\nimport { buildRawSchema } from '../schema/buildRawSchema.js'\nimport { executeSchemaHooks } from '../utilities/executeSchemaHooks.js'\nimport { buildDrizzleTable } from './schema/buildDrizzleTable.js'\nimport { setColumnID } from './schema/setColumnID.js'\n\nexport const init: Init = async function init(this: BasePostgresAdapter) {\n this.rawRelations = {}\n this.rawTables = {}\n\n buildRawSchema({\n adapter: this,\n setColumnID,\n })\n\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n for (const tableName in this.rawTables) {\n buildDrizzleTable({ adapter: this, rawTable: this.rawTables[tableName] })\n }\n\n buildDrizzleRelations({\n adapter: this,\n })\n\n await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n}\n"],"names":["buildDrizzleRelations","buildRawSchema","executeSchemaHooks","buildDrizzleTable","setColumnID","init","rawRelations","rawTables","adapter","type","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","tableName","rawTable","schema","tables","relations"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,WAAW,QAAQ,0BAAyB;AAErD,OAAO,MAAMC,OAAa,eAAeA;IACvC,IAAI,CAACC,YAAY,GAAG,CAAC;IACrB,IAAI,CAACC,SAAS,GAAG,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/postgres/init.ts"],"sourcesContent":["import type { Init } from 'payload'\n\nimport type { BasePostgresAdapter } from './types.js'\n\nimport { buildDrizzleRelations } from '../schema/buildDrizzleRelations.js'\nimport { buildRawSchema } from '../schema/buildRawSchema.js'\nimport { checkTruncatedIdentifiers } from '../utilities/checkTruncatedIdentifiers.js'\nimport { executeSchemaHooks } from '../utilities/executeSchemaHooks.js'\nimport { buildDrizzleTable } from './schema/buildDrizzleTable.js'\nimport { setColumnID } from './schema/setColumnID.js'\n\nexport const init: Init = async function init(this: BasePostgresAdapter) {\n this.rawRelations = {}\n this.rawTables = {}\n\n buildRawSchema({\n adapter: this,\n setColumnID,\n })\n\n await executeSchemaHooks({ type: 'beforeSchemaInit', adapter: this })\n\n // Warn on identifiers Postgres will truncate past 63 chars; throw only when two collide.\n checkTruncatedIdentifiers({ adapter: this, logWarnings: process.env.NODE_ENV !== 'production' })\n\n if (this.payload.config.localization) {\n this.enums.enum__locales = this.pgSchema.enum(\n '_locales',\n this.payload.config.localization.locales.map(({ code }) => code) as [string, ...string[]],\n )\n }\n\n for (const tableName in this.rawTables) {\n buildDrizzleTable({ adapter: this, rawTable: this.rawTables[tableName] })\n }\n\n buildDrizzleRelations({\n adapter: this,\n })\n\n await executeSchemaHooks({ type: 'afterSchemaInit', adapter: this })\n\n this.schema = {\n pgSchema: this.pgSchema,\n ...this.tables,\n ...this.relations,\n ...this.enums,\n }\n}\n"],"names":["buildDrizzleRelations","buildRawSchema","checkTruncatedIdentifiers","executeSchemaHooks","buildDrizzleTable","setColumnID","init","rawRelations","rawTables","adapter","type","logWarnings","process","env","NODE_ENV","payload","config","localization","enums","enum__locales","pgSchema","enum","locales","map","code","tableName","rawTable","schema","tables","relations"],"mappings":"AAIA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,4CAA2C;AACrF,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,WAAW,QAAQ,0BAAyB;AAErD,OAAO,MAAMC,OAAa,eAAeA;IACvC,IAAI,CAACC,YAAY,GAAG,CAAC;IACrB,IAAI,CAACC,SAAS,GAAG,CAAC;IAElBP,eAAe;QACbQ,SAAS,IAAI;QACbJ;IACF;IAEA,MAAMF,mBAAmB;QAAEO,MAAM;QAAoBD,SAAS,IAAI;IAAC;IAEnE,yFAAyF;IACzFP,0BAA0B;QAAEO,SAAS,IAAI;QAAEE,aAAaC,QAAQC,GAAG,CAACC,QAAQ,KAAK;IAAa;IAE9F,IAAI,IAAI,CAACC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;QACpC,IAAI,CAACC,KAAK,CAACC,aAAa,GAAG,IAAI,CAACC,QAAQ,CAACC,IAAI,CAC3C,YACA,IAAI,CAACN,OAAO,CAACC,MAAM,CAACC,YAAY,CAACK,OAAO,CAACC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE/D;IAEA,IAAK,MAAMC,aAAa,IAAI,CAACjB,SAAS,CAAE;QACtCJ,kBAAkB;YAAEK,SAAS,IAAI;YAAEiB,UAAU,IAAI,CAAClB,SAAS,CAACiB,UAAU;QAAC;IACzE;IAEAzB,sBAAsB;QACpBS,SAAS,IAAI;IACf;IAEA,MAAMN,mBAAmB;QAAEO,MAAM;QAAmBD,SAAS,IAAI;IAAC;IAElE,IAAI,CAACkB,MAAM,GAAG;QACZP,UAAU,IAAI,CAACA,QAAQ;QACvB,GAAG,IAAI,CAACQ,MAAM;QACd,GAAG,IAAI,CAACC,SAAS;QACjB,GAAG,IAAI,CAACX,KAAK;IACf;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK/C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,UAAU,CAAA;IACd,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/postgres/predefinedMigrations/v2-v3/fetchAndResave/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK/C,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,mBAAmB,CAAA;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,EAAE,UAAU,CAAA;IACd,KAAK,EAAE,OAAO,CAAA;IACd,YAAY,EAAE,YAAY,CAAA;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,cAAc,mHAYxB,IAAI,kBAgNN,CAAA"}
|
|
@@ -13,7 +13,8 @@ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsT
|
|
|
13
13
|
fallbackLocale: null,
|
|
14
14
|
locale: 'all',
|
|
15
15
|
req,
|
|
16
|
-
showHiddenFields: true
|
|
16
|
+
showHiddenFields: true,
|
|
17
|
+
overrideAccess: true
|
|
17
18
|
});
|
|
18
19
|
if (debug) {
|
|
19
20
|
payload.logger.info(`The collection "${collectionConfig.slug}" version with ID ${id} will be migrated`);
|
|
@@ -52,7 +53,8 @@ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsT
|
|
|
52
53
|
fallbackLocale: null,
|
|
53
54
|
locale: 'all',
|
|
54
55
|
req,
|
|
55
|
-
showHiddenFields: true
|
|
56
|
+
showHiddenFields: true,
|
|
57
|
+
overrideAccess: true
|
|
56
58
|
});
|
|
57
59
|
if (debug) {
|
|
58
60
|
payload.logger.info(`The collection "${collectionConfig.slug}" with ID ${doc.id} will be migrated`);
|
|
@@ -97,7 +99,8 @@ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsT
|
|
|
97
99
|
limit: 0,
|
|
98
100
|
locale: 'all',
|
|
99
101
|
req,
|
|
100
|
-
showHiddenFields: true
|
|
102
|
+
showHiddenFields: true,
|
|
103
|
+
overrideAccess: true
|
|
101
104
|
});
|
|
102
105
|
if (debug) {
|
|
103
106
|
payload.logger.info(`${docs.length} global "${globalSlug}" versions will be migrated`);
|
|
@@ -137,7 +140,8 @@ export const fetchAndResave = async ({ adapter, collectionSlug, db, debug, docsT
|
|
|
137
140
|
fallbackLocale: null,
|
|
138
141
|
locale: 'all',
|
|
139
142
|
req,
|
|
140
|
-
showHiddenFields: true
|
|
143
|
+
showHiddenFields: true,
|
|
144
|
+
overrideAccess: true
|
|
141
145
|
});
|
|
142
146
|
traverseFields({
|
|
143
147
|
doc,
|