@payloadcms/drizzle 4.0.0-internal.d21c039 → 4.0.0-internal.d3909a9
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/exports/postgres.d.ts +1 -0
- package/dist/exports/postgres.d.ts.map +1 -1
- package/dist/exports/postgres.js +1 -0
- package/dist/exports/postgres.js.map +1 -1
- package/dist/exports/sqlite.d.ts +1 -0
- package/dist/exports/sqlite.d.ts.map +1 -1
- package/dist/exports/sqlite.js +1 -0
- package/dist/exports/sqlite.js.map +1 -1
- package/dist/find/buildPolymorphicJoinQuery.js.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +6 -2
- package/dist/migrate.js.map +1 -1
- package/dist/migrateDown.d.ts.map +1 -1
- package/dist/migrateDown.js +5 -2
- package/dist/migrateDown.js.map +1 -1
- package/dist/migrateFresh.d.ts.map +1 -1
- package/dist/migrateFresh.js +5 -2
- package/dist/migrateFresh.js.map +1 -1
- package/dist/migrateRefresh.d.ts.map +1 -1
- package/dist/migrateRefresh.js +6 -2
- package/dist/migrateRefresh.js.map +1 -1
- package/dist/migrateReset.d.ts.map +1 -1
- package/dist/migrateReset.js +6 -2
- package/dist/migrateReset.js.map +1 -1
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts +35 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js +185 -0
- package/dist/postgres/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- 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/schema/build.js +3 -3
- package/dist/schema/build.js.map +1 -1
- package/dist/sqlite/execute.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/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts +15 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.d.ts.map +1 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js +114 -0
- package/dist/sqlite/predefinedMigrations/sizes-to-variants/index.js.map +1 -0
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.d.ts.map +1 -1
- package/dist/utilities/blocksToJsonMigrator.js +6 -17
- package/dist/utilities/blocksToJsonMigrator.js.map +1 -1
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts +15 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.d.ts.map +1 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js +110 -0
- package/dist/utilities/buildDynamicPredefinedSizesToVariantsMigration.js.map +1 -0
- package/dist/utilities/createSchemaGenerator.d.ts.map +1 -1
- package/dist/utilities/createSchemaGenerator.js +7 -12
- package/dist/utilities/createSchemaGenerator.js.map +1 -1
- package/dist/utilities/executeSchemaHooks.js +1 -1
- package/dist/utilities/executeSchemaHooks.js.map +1 -1
- package/dist/utilities/formatGeneratedFile.d.ts +10 -0
- package/dist/utilities/formatGeneratedFile.d.ts.map +1 -0
- package/dist/utilities/formatGeneratedFile.js +58 -0
- package/dist/utilities/formatGeneratedFile.js.map +1 -0
- package/dist/utilities/getSizesToVariantsRenames.d.ts +54 -0
- package/dist/utilities/getSizesToVariantsRenames.d.ts.map +1 -0
- package/dist/utilities/getSizesToVariantsRenames.js +251 -0
- package/dist/utilities/getSizesToVariantsRenames.js.map +1 -0
- package/dist/utilities/getTransaction.js.map +1 -1
- package/package.json +16 -19
|
@@ -10,6 +10,7 @@ export { execute } from '../postgres/execute.js';
|
|
|
10
10
|
export { init } from '../postgres/init.js';
|
|
11
11
|
export { insert } from '../postgres/insert.js';
|
|
12
12
|
export { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js';
|
|
13
|
+
export { migratePostgresSizesToVariants } from '../postgres/predefinedMigrations/sizes-to-variants/index.js';
|
|
13
14
|
export { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js';
|
|
14
15
|
export { assertOperatorHandlerExtensionsInstalled } from '../postgres/query/assertOperatorHandlerExtensionsInstalled.js';
|
|
15
16
|
export { postgresUnaccent } from '../postgres/query/postgresUnaccent.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/exports/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,2DAA2D,CAAA;AACzG,OAAO,EAAE,qBAAqB,EAA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AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AACrE,cAAc,sBAAsB,CAAA"}
|
package/dist/exports/postgres.js
CHANGED
|
@@ -10,6 +10,7 @@ export { execute } from '../postgres/execute.js';
|
|
|
10
10
|
export { init } from '../postgres/init.js';
|
|
11
11
|
export { insert } from '../postgres/insert.js';
|
|
12
12
|
export { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js';
|
|
13
|
+
export { migratePostgresSizesToVariants } from '../postgres/predefinedMigrations/sizes-to-variants/index.js';
|
|
13
14
|
export { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js';
|
|
14
15
|
export { assertOperatorHandlerExtensionsInstalled } from '../postgres/query/assertOperatorHandlerExtensionsInstalled.js';
|
|
15
16
|
export { postgresUnaccent } from '../postgres/query/postgresUnaccent.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/postgres.ts"],"sourcesContent":["export { columnToCodeConverter } from '../postgres/columnToCodeConverter.js'\nexport { countDistinct } from '../postgres/countDistinct.js'\nexport { createDatabase } from '../postgres/createDatabase.js'\nexport { createExtensions } from '../postgres/createExtensions.js'\nexport { createJSONQuery } from '../postgres/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js'\nexport { deleteWhere } from '../postgres/deleteWhere.js'\nexport { dropDatabase } from '../postgres/dropDatabase.js'\nexport { execute } from '../postgres/execute.js'\nexport { init } from '../postgres/init.js'\nexport { insert } from '../postgres/insert.js'\nexport { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js'\nexport { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js'\nexport { assertOperatorHandlerExtensionsInstalled } from '../postgres/query/assertOperatorHandlerExtensionsInstalled.js'\nexport { postgresUnaccent } from '../postgres/query/postgresUnaccent.js'\nexport { requireDrizzleKit } from '../postgres/requireDrizzleKit.js'\nexport { geometryColumn } from '../postgres/schema/geometryColumn.js'\nexport * from '../postgres/types.js'\n"],"names":["columnToCodeConverter","countDistinct","createDatabase","createExtensions","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migratePostgresLocalizeStatus","migratePostgresV2toV3","assertOperatorHandlerExtensionsInstalled","postgresUnaccent","requireDrizzleKit","geometryColumn"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,uCAAsC;AAC5E,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,OAAO,QAAQ,yBAAwB;AAChD,SAASC,IAAI,QAAQ,sBAAqB;AAC1C,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,6BAA6B,QAAQ,4DAA2D;AACzG,SAASC,qBAAqB,QAAQ,kDAAiD;AACvF,SAASC,wCAAwC,QAAQ,gEAA+D;AACxH,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,cAAc,uBAAsB"}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/postgres.ts"],"sourcesContent":["export { columnToCodeConverter } from '../postgres/columnToCodeConverter.js'\nexport { countDistinct } from '../postgres/countDistinct.js'\nexport { createDatabase } from '../postgres/createDatabase.js'\nexport { createExtensions } from '../postgres/createExtensions.js'\nexport { createJSONQuery } from '../postgres/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../postgres/defaultSnapshot.js'\nexport { deleteWhere } from '../postgres/deleteWhere.js'\nexport { dropDatabase } from '../postgres/dropDatabase.js'\nexport { execute } from '../postgres/execute.js'\nexport { init } from '../postgres/init.js'\nexport { insert } from '../postgres/insert.js'\nexport { migratePostgresLocalizeStatus } from '../postgres/predefinedMigrations/localize-status/index.js'\nexport { migratePostgresSizesToVariants } from '../postgres/predefinedMigrations/sizes-to-variants/index.js'\nexport { migratePostgresV2toV3 } from '../postgres/predefinedMigrations/v2-v3/index.js'\nexport { assertOperatorHandlerExtensionsInstalled } from '../postgres/query/assertOperatorHandlerExtensionsInstalled.js'\nexport { postgresUnaccent } from '../postgres/query/postgresUnaccent.js'\nexport { requireDrizzleKit } from '../postgres/requireDrizzleKit.js'\nexport { geometryColumn } from '../postgres/schema/geometryColumn.js'\nexport * from '../postgres/types.js'\n"],"names":["columnToCodeConverter","countDistinct","createDatabase","createExtensions","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migratePostgresLocalizeStatus","migratePostgresSizesToVariants","migratePostgresV2toV3","assertOperatorHandlerExtensionsInstalled","postgresUnaccent","requireDrizzleKit","geometryColumn"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,uCAAsC;AAC5E,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SAASC,sBAAsB,QAAQ,iCAAgC;AACvE,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,OAAO,QAAQ,yBAAwB;AAChD,SAASC,IAAI,QAAQ,sBAAqB;AAC1C,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,6BAA6B,QAAQ,4DAA2D;AACzG,SAASC,8BAA8B,QAAQ,8DAA6D;AAC5G,SAASC,qBAAqB,QAAQ,kDAAiD;AACvF,SAASC,wCAAwC,QAAQ,gEAA+D;AACxH,SAASC,gBAAgB,QAAQ,wCAAuC;AACxE,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,cAAc,uBAAsB"}
|
package/dist/exports/sqlite.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { execute } from '../sqlite/execute.js';
|
|
|
9
9
|
export { init } from '../sqlite/init.js';
|
|
10
10
|
export { insert } from '../sqlite/insert.js';
|
|
11
11
|
export { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js';
|
|
12
|
+
export { migrateSqliteSizesToVariants } from '../sqlite/predefinedMigrations/sizes-to-variants/index.js';
|
|
12
13
|
export { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js';
|
|
13
14
|
export * from '../sqlite/types.js';
|
|
14
15
|
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yDAAyD,CAAA;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yDAAyD,CAAA;AACrG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,cAAc,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/exports/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yDAAyD,CAAA;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,yDAAyD,CAAA;AACrG,OAAO,EAAE,4BAA4B,EAAE,MAAM,2DAA2D,CAAA;AACxG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,cAAc,oBAAoB,CAAA"}
|
package/dist/exports/sqlite.js
CHANGED
|
@@ -9,6 +9,7 @@ export { execute } from '../sqlite/execute.js';
|
|
|
9
9
|
export { init } from '../sqlite/init.js';
|
|
10
10
|
export { insert } from '../sqlite/insert.js';
|
|
11
11
|
export { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js';
|
|
12
|
+
export { migrateSqliteSizesToVariants } from '../sqlite/predefinedMigrations/sizes-to-variants/index.js';
|
|
12
13
|
export { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js';
|
|
13
14
|
export * from '../sqlite/types.js';
|
|
14
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/sqlite.ts"],"sourcesContent":["export { columnToCodeConverter } from '../sqlite/columnToCodeConverter.js'\nexport { countDistinct } from '../sqlite/countDistinct.js'\nexport { convertPathToJSONTraversal } from '../sqlite/createJSONQuery/convertPathToJSONTraversal.js'\nexport { createJSONQuery } from '../sqlite/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../sqlite/defaultSnapshot.js'\nexport { deleteWhere } from '../sqlite/deleteWhere.js'\nexport { dropDatabase } from '../sqlite/dropDatabase.js'\nexport { execute } from '../sqlite/execute.js'\nexport { init } from '../sqlite/init.js'\nexport { insert } from '../sqlite/insert.js'\nexport { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js'\nexport { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js'\nexport * from '../sqlite/types.js'\n"],"names":["columnToCodeConverter","countDistinct","convertPathToJSONTraversal","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migrateSqliteLocalizeStatus","requireDrizzleKit"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,aAAa,QAAQ,6BAA4B;AAC1D,SAASC,0BAA0B,QAAQ,0DAAyD;AACpG,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,+BAA8B;AACrE,SAASC,WAAW,QAAQ,2BAA0B;AACtD,SAASC,YAAY,QAAQ,4BAA2B;AACxD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SAASC,IAAI,QAAQ,oBAAmB;AACxC,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,2BAA2B,QAAQ,0DAAyD;AACrG,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,cAAc,qBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/sqlite.ts"],"sourcesContent":["export { columnToCodeConverter } from '../sqlite/columnToCodeConverter.js'\nexport { countDistinct } from '../sqlite/countDistinct.js'\nexport { convertPathToJSONTraversal } from '../sqlite/createJSONQuery/convertPathToJSONTraversal.js'\nexport { createJSONQuery } from '../sqlite/createJSONQuery/index.js'\nexport { defaultDrizzleSnapshot } from '../sqlite/defaultSnapshot.js'\nexport { deleteWhere } from '../sqlite/deleteWhere.js'\nexport { dropDatabase } from '../sqlite/dropDatabase.js'\nexport { execute } from '../sqlite/execute.js'\nexport { init } from '../sqlite/init.js'\nexport { insert } from '../sqlite/insert.js'\nexport { migrateSqliteLocalizeStatus } from '../sqlite/predefinedMigrations/localize-status/index.js'\nexport { migrateSqliteSizesToVariants } from '../sqlite/predefinedMigrations/sizes-to-variants/index.js'\nexport { requireDrizzleKit } from '../sqlite/requireDrizzleKit.js'\nexport * from '../sqlite/types.js'\n"],"names":["columnToCodeConverter","countDistinct","convertPathToJSONTraversal","createJSONQuery","defaultDrizzleSnapshot","deleteWhere","dropDatabase","execute","init","insert","migrateSqliteLocalizeStatus","migrateSqliteSizesToVariants","requireDrizzleKit"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,qCAAoC;AAC1E,SAASC,aAAa,QAAQ,6BAA4B;AAC1D,SAASC,0BAA0B,QAAQ,0DAAyD;AACpG,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,+BAA8B;AACrE,SAASC,WAAW,QAAQ,2BAA0B;AACtD,SAASC,YAAY,QAAQ,4BAA2B;AACxD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SAASC,IAAI,QAAQ,oBAAmB;AACxC,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,2BAA2B,QAAQ,0DAAyD;AACrG,SAASC,4BAA4B,QAAQ,4DAA2D;AACxG,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,cAAc,qBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/find/buildPolymorphicJoinQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { SQLiteSelect } from 'drizzle-orm/sqlite-core'\n\nimport { asc, count, desc, eq, sql } from 'drizzle-orm'\nimport { type FlattenedJoinField, type Where } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter, GenericTable } from '../types.js'\nimport type { PolymorphicJoinWherePlan } from './createPolymorphicJoinWherePlan.js'\n\nimport { jsonAggBuildObject } from '../utilities/json.js'\nimport { buildPolymorphicJoinWhere } from './buildPolymorphicJoinWhere.js'\nimport { createPolymorphicJoinWherePlan } from './createPolymorphicJoinWherePlan.js'\n\ntype BuildPolymorphicJoinQueryArgs = {\n adapter: DrizzleAdapter\n currentTableName: string\n field: FlattenedJoinField\n limit: number\n locale?: string\n page?: number\n path: string\n shouldCount: boolean\n sort?: string | string[]\n where?: Where\n}\n\ntype PolymorphicJoinQuery = {\n columnName: string\n count?: SQL.Aliased\n documents: SQL.Aliased\n}\n\n/**\n * Builds the correlated document and optional count projections for a join that targets multiple\n * collections. Every collection branch exposes the same `id`, parent, `relationTo`, and sort\n * columns before the branches are combined. A missing sort field resolves to SQL NULL so targets\n * with different schemas can still share one ordered union.\n *\n * `field.collection` must contain at least one configured collection. Each mapped table must have\n * an `id` column and the column named by `field.on`. The supplied `limit` is used as-is; callers can\n * include an extra look-ahead row when they calculate pagination.\n *\n * @returns The stable projection name, the document projection, and the count projection when\n * `shouldCount` is true.\n * @throws If the join definition, target collection, mapped table, required columns, or sort shape\n * cannot be represented by the polymorphic query.\n */\nexport const buildPolymorphicJoinQuery = ({\n adapter,\n currentTableName,\n field,\n limit,\n locale,\n page,\n path,\n shouldCount,\n sort,\n where,\n}: BuildPolymorphicJoinQueryArgs): PolymorphicJoinQuery => {\n if (!Array.isArray(field.collection)) {\n throw new Error('A polymorphic join requires a collection array')\n }\n\n if (field.collection.length === 0) {\n throw new Error('A polymorphic join requires at least one collection')\n }\n\n if (Array.isArray(sort)) {\n throw new Error('Polymorphic joins do not support multiple sort fields')\n }\n\n const collections = field.collection\n const columnName = `${path.replaceAll('.', '_')}${field.name}`\n const db = adapter.drizzle as LibSQLDatabase\n const onPath = field.on.split('.').join('_')\n const collectionTables = collections.map((collection) => {\n if (!adapter.payload.collections[collection]) {\n throw new Error(`Unknown polymorphic join collection \"${collection}\"`)\n }\n\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection))\n const table = tableName ? (adapter.tables[tableName] as GenericTable | undefined) : undefined\n\n if (!table) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no database table`)\n }\n\n if (!table['id']) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no \"id\" column`)\n }\n\n if (!table[onPath]) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no \"${onPath}\" column`)\n }\n\n return { collection, table }\n })\n const sortField = getSortField({ adapter, collections, sort })\n const sortOrder = sortField.startsWith('-') ? desc : asc\n const sortPath = sortField.replace('-', '').split('.').join('_')\n const wherePlan: PolymorphicJoinWherePlan = where\n ? createPolymorphicJoinWherePlan({ adapter, collections, where })\n : new Map()\n let unionQuery: null | SQLiteSelect = null\n\n for (const { collection, table } of collectionTables) {\n const sortColumn = table[sortPath]\n const selectFields = {\n id: table['id'],\n parent: sql`${table[onPath]}`.as(onPath),\n relationTo: sql`${collection}`.as('relationTo'),\n sortPath: sql`${sortColumn ?? null}`.as('sortPath'),\n }\n const collectionWhere =\n where && Object.keys(where).length > 0\n ? buildPolymorphicJoinWhere({\n adapter,\n collection,\n locale,\n table,\n where,\n wherePlan,\n })\n : undefined\n let collectionQuery = db.select(selectFields).from(table).$dynamic()\n\n if (collectionWhere) {\n collectionQuery = collectionQuery.where(collectionWhere)\n }\n\n if (unionQuery === null) {\n unionQuery = collectionQuery as unknown as SQLiteSelect\n } else {\n unionQuery = unionQuery.unionAll(collectionQuery)\n }\n }\n\n const subQueryAlias = `${columnName}_subquery`\n const parentConstraint = eq(\n sql.raw(`\"${currentTableName}\".\"id\"`),\n sql.raw(`\"${subQueryAlias}\".\"${onPath}\"`),\n )\n const countExpression = shouldCount\n ? sql`${db\n .select({ count: count() })\n .from(sql`${unionQuery.as(subQueryAlias)}`)\n .where(parentConstraint)}`.as(`${columnName}_count`)\n : undefined\n\n unionQuery = unionQuery.orderBy(sortOrder(sql`\"sortPath\"`))\n\n const sortedUnionAlias = `${columnName}_sorted`\n let limitOffsetSQL = sql.empty()\n\n if (limit) {\n limitOffsetSQL = sql` LIMIT ${limit}`\n }\n\n if (page && limit !== 0) {\n const offset = (page - 1) * limit\n\n if (offset > 0) {\n limitOffsetSQL = sql`${limitOffsetSQL} OFFSET ${offset}`\n }\n }\n\n const parentWhere = sql.raw(`\"${sortedUnionAlias}\".\"${onPath}\" = \"${currentTableName}\".\"id\"`)\n const documents = sql`(\n SELECT ${jsonAggBuildObject(adapter, {\n id: sql.raw(`\"${subQueryAlias}\".\"id\"`),\n relationTo: sql.raw(`\"${subQueryAlias}\".\"relationTo\"`),\n })}\n FROM (\n SELECT * FROM ${sql`${unionQuery.as(sortedUnionAlias)}`}\n WHERE ${parentWhere}${limitOffsetSQL}\n ) AS ${sql.raw(`\"${subQueryAlias}\"`)}\n )`.as(columnName)\n\n return {\n columnName,\n count: countExpression,\n documents,\n }\n}\n\nconst getSortField = ({\n adapter,\n collections,\n sort,\n}: {\n adapter: DrizzleAdapter\n collections: string[]\n sort?: string\n}): string => {\n if (sort) {\n return sort\n }\n\n const hasCreatedAt = collections.some((collection) =>\n adapter.payload.collections[collection].config.fields.some(\n (field) => field.type === 'date' && field.name === 'createdAt',\n ),\n )\n\n return hasCreatedAt ? '-createdAt' : 'id'\n}\n"],"names":["asc","count","desc","eq","sql","toSnakeCase","jsonAggBuildObject","buildPolymorphicJoinWhere","createPolymorphicJoinWherePlan","buildPolymorphicJoinQuery","adapter","currentTableName","field","limit","locale","page","path","shouldCount","sort","where","Array","isArray","collection","Error","length","collections","columnName","replaceAll","name","db","drizzle","onPath","on","split","join","collectionTables","map","payload","tableName","tableNameMap","get","table","tables","undefined","sortField","getSortField","sortOrder","startsWith","sortPath","replace","wherePlan","Map","unionQuery","sortColumn","selectFields","id","parent","as","relationTo","collectionWhere","Object","keys","collectionQuery","select","from","$dynamic","unionAll","subQueryAlias","parentConstraint","raw","countExpression","orderBy","sortedUnionAlias","limitOffsetSQL","empty","offset","parentWhere","documents","hasCreatedAt","some","config","fields","type"],"mappings":"AAIA,SAASA,GAAG,EAAEC,KAAK,EAAEC,IAAI,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AAEvD,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,kBAAkB,QAAQ,uBAAsB;AACzD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,8BAA8B,QAAQ,sCAAqC;AAqBpF;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,OAAO,EACPC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,IAAI,EACJC,WAAW,EACXC,IAAI,EACJC,KAAK,EACyB;IAC9B,IAAI,CAACC,MAAMC,OAAO,CAACT,MAAMU,UAAU,GAAG;QACpC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIX,MAAMU,UAAU,CAACE,MAAM,KAAK,GAAG;QACjC,MAAM,IAAID,MAAM;IAClB;IAEA,IAAIH,MAAMC,OAAO,CAACH,OAAO;QACvB,MAAM,IAAIK,MAAM;IAClB;IAEA,MAAME,cAAcb,MAAMU,UAAU;IACpC,MAAMI,aAAa,GAAGV,KAAKW,UAAU,CAAC,KAAK,OAAOf,MAAMgB,IAAI,EAAE;IAC9D,MAAMC,KAAKnB,QAAQoB,OAAO;IAC1B,MAAMC,SAASnB,MAAMoB,EAAE,CAACC,KAAK,CAAC,KAAKC,IAAI,CAAC;IACxC,MAAMC,mBAAmBV,YAAYW,GAAG,CAAC,CAACd;QACxC,IAAI,CAACZ,QAAQ2B,OAAO,CAACZ,WAAW,CAACH,WAAW,EAAE;YAC5C,MAAM,IAAIC,MAAM,CAAC,qCAAqC,EAAED,WAAW,CAAC,CAAC;QACvE;QAEA,MAAMgB,YAAY5B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QAAQ,EAAEE,OAAO,CAAC;QAC1D;IACF;IAEA,MAAMC,cAAcxE,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEG,iBAAiB,GAAG,EAAEzC,OAAO,KAAK,EAAEpB,iBAAiB,MAAM,CAAC;IAC5F,MAAMkE,YAAYzE,GAAG,CAAC;WACb,EAAEE,mBAAmBI,SAAS;QACnC6C,IAAInD,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,MAAM,CAAC;QACrCT,YAAYtD,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,cAAc,CAAC;IACvD,GAAG;;oBAEa,EAAE/D,GAAG,CAAC,EAAEgD,WAAWK,EAAE,CAACe,kBAAkB,CAAC,CAAC;YAClD,EAAEI,YAAY,EAAEH,eAAe;SAClC,EAAErE,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,CAAC,CAAC,EAAE;GACtC,CAAC,CAACV,EAAE,CAAC/B;IAEN,OAAO;QACLA;QACAzB,OAAOqE;QACPO;IACF;AACF,EAAC;AAED,MAAMhC,eAAe,CAAC,EACpBnC,OAAO,EACPe,WAAW,EACXP,IAAI,EAKL;IACC,IAAIA,MAAM;QACR,OAAOA;IACT;IAEA,MAAM4D,eAAerD,YAAYsD,IAAI,CAAC,CAACzD,aACrCZ,QAAQ2B,OAAO,CAACZ,WAAW,CAACH,WAAW,CAAC0D,MAAM,CAACC,MAAM,CAACF,IAAI,CACxD,CAACnE,QAAUA,MAAMsE,IAAI,KAAK,UAAUtE,MAAMgB,IAAI,KAAK;IAIvD,OAAOkD,eAAe,eAAe;AACvC"}
|
|
1
|
+
{"version":3,"sources":["../../src/find/buildPolymorphicJoinQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { SQLiteSelect } from 'drizzle-orm/sqlite-core'\n\nimport { asc, count, desc, eq, sql } from 'drizzle-orm'\nimport { type FlattenedJoinField, type Where } from 'payload'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter, GenericTable } from '../types.js'\nimport type { PolymorphicJoinWherePlan } from './createPolymorphicJoinWherePlan.js'\n\nimport { jsonAggBuildObject } from '../utilities/json.js'\nimport { buildPolymorphicJoinWhere } from './buildPolymorphicJoinWhere.js'\nimport { createPolymorphicJoinWherePlan } from './createPolymorphicJoinWherePlan.js'\n\ntype BuildPolymorphicJoinQueryArgs = {\n adapter: DrizzleAdapter\n currentTableName: string\n field: FlattenedJoinField\n limit: number\n locale?: string\n page?: number\n path: string\n shouldCount: boolean\n sort?: string | string[]\n where?: Where\n}\n\ntype PolymorphicJoinQuery = {\n columnName: string\n count?: SQL.Aliased\n documents: SQL.Aliased\n}\n\n/**\n * Builds the correlated document and optional count projections for a join that targets multiple\n * collections. Every collection branch exposes the same `id`, parent, `relationTo`, and sort\n * columns before the branches are combined. A missing sort field resolves to SQL NULL so targets\n * with different schemas can still share one ordered union.\n *\n * `field.collection` must contain at least one configured collection. Each mapped table must have\n * an `id` column and the column named by `field.on`. The supplied `limit` is used as-is; callers can\n * include an extra look-ahead row when they calculate pagination.\n *\n * @returns The stable projection name, the document projection, and the count projection when\n * `shouldCount` is true.\n * @throws If the join definition, target collection, mapped table, required columns, or sort shape\n * cannot be represented by the polymorphic query.\n */\nexport const buildPolymorphicJoinQuery = ({\n adapter,\n currentTableName,\n field,\n limit,\n locale,\n page,\n path,\n shouldCount,\n sort,\n where,\n}: BuildPolymorphicJoinQueryArgs): PolymorphicJoinQuery => {\n if (!Array.isArray(field.collection)) {\n throw new Error('A polymorphic join requires a collection array')\n }\n\n if (field.collection.length === 0) {\n throw new Error('A polymorphic join requires at least one collection')\n }\n\n if (Array.isArray(sort)) {\n throw new Error('Polymorphic joins do not support multiple sort fields')\n }\n\n const collections = field.collection\n const columnName = `${path.replaceAll('.', '_')}${field.name}`\n const db = adapter.drizzle as LibSQLDatabase\n const onPath = field.on.split('.').join('_')\n const collectionTables = collections.map((collection) => {\n if (!adapter.payload.collections[collection]) {\n throw new Error(`Unknown polymorphic join collection \"${collection}\"`)\n }\n\n const tableName = adapter.tableNameMap.get(toSnakeCase(collection))\n const table = tableName ? (adapter.tables[tableName] as GenericTable | undefined) : undefined\n\n if (!table) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no database table`)\n }\n\n if (!table['id']) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no \"id\" column`)\n }\n\n if (!table[onPath]) {\n throw new Error(`Polymorphic join collection \"${collection}\" has no \"${onPath}\" column`)\n }\n\n return { collection, table }\n })\n const sortField = getSortField({ adapter, collections, sort })\n const sortOrder = sortField.startsWith('-') ? desc : asc\n const sortPath = sortField.replace('-', '').split('.').join('_')\n const wherePlan: PolymorphicJoinWherePlan = where\n ? createPolymorphicJoinWherePlan({ adapter, collections, where })\n : new Map()\n let unionQuery: null | SQLiteSelect = null\n\n for (const { collection, table } of collectionTables) {\n const sortColumn = table[sortPath]\n const selectFields = {\n id: table['id'],\n parent: sql`${table[onPath]}`.as(onPath),\n relationTo: sql`${collection}`.as('relationTo'),\n sortPath: sql`${sortColumn ?? null}`.as('sortPath'),\n }\n const collectionWhere =\n where && Object.keys(where).length > 0\n ? buildPolymorphicJoinWhere({\n adapter,\n collection,\n locale,\n table,\n where,\n wherePlan,\n })\n : undefined\n let collectionQuery = db.select(selectFields).from(table).$dynamic()\n\n if (collectionWhere) {\n collectionQuery = collectionQuery.where(collectionWhere)\n }\n\n if (unionQuery === null) {\n unionQuery = collectionQuery\n } else {\n unionQuery = unionQuery.unionAll(collectionQuery)\n }\n }\n\n const subQueryAlias = `${columnName}_subquery`\n const parentConstraint = eq(\n sql.raw(`\"${currentTableName}\".\"id\"`),\n sql.raw(`\"${subQueryAlias}\".\"${onPath}\"`),\n )\n const countExpression = shouldCount\n ? sql`${db\n .select({ count: count() })\n .from(sql`${unionQuery.as(subQueryAlias)}`)\n .where(parentConstraint)}`.as(`${columnName}_count`)\n : undefined\n\n unionQuery = unionQuery.orderBy(sortOrder(sql`\"sortPath\"`))\n\n const sortedUnionAlias = `${columnName}_sorted`\n let limitOffsetSQL = sql.empty()\n\n if (limit) {\n limitOffsetSQL = sql` LIMIT ${limit}`\n }\n\n if (page && limit !== 0) {\n const offset = (page - 1) * limit\n\n if (offset > 0) {\n limitOffsetSQL = sql`${limitOffsetSQL} OFFSET ${offset}`\n }\n }\n\n const parentWhere = sql.raw(`\"${sortedUnionAlias}\".\"${onPath}\" = \"${currentTableName}\".\"id\"`)\n const documents = sql`(\n SELECT ${jsonAggBuildObject(adapter, {\n id: sql.raw(`\"${subQueryAlias}\".\"id\"`),\n relationTo: sql.raw(`\"${subQueryAlias}\".\"relationTo\"`),\n })}\n FROM (\n SELECT * FROM ${sql`${unionQuery.as(sortedUnionAlias)}`}\n WHERE ${parentWhere}${limitOffsetSQL}\n ) AS ${sql.raw(`\"${subQueryAlias}\"`)}\n )`.as(columnName)\n\n return {\n columnName,\n count: countExpression,\n documents,\n }\n}\n\nconst getSortField = ({\n adapter,\n collections,\n sort,\n}: {\n adapter: DrizzleAdapter\n collections: string[]\n sort?: string\n}): string => {\n if (sort) {\n return sort\n }\n\n const hasCreatedAt = collections.some((collection) =>\n adapter.payload.collections[collection].config.fields.some(\n (field) => field.type === 'date' && field.name === 'createdAt',\n ),\n )\n\n return hasCreatedAt ? '-createdAt' : 'id'\n}\n"],"names":["asc","count","desc","eq","sql","toSnakeCase","jsonAggBuildObject","buildPolymorphicJoinWhere","createPolymorphicJoinWherePlan","buildPolymorphicJoinQuery","adapter","currentTableName","field","limit","locale","page","path","shouldCount","sort","where","Array","isArray","collection","Error","length","collections","columnName","replaceAll","name","db","drizzle","onPath","on","split","join","collectionTables","map","payload","tableName","tableNameMap","get","table","tables","undefined","sortField","getSortField","sortOrder","startsWith","sortPath","replace","wherePlan","Map","unionQuery","sortColumn","selectFields","id","parent","as","relationTo","collectionWhere","Object","keys","collectionQuery","select","from","$dynamic","unionAll","subQueryAlias","parentConstraint","raw","countExpression","orderBy","sortedUnionAlias","limitOffsetSQL","empty","offset","parentWhere","documents","hasCreatedAt","some","config","fields","type"],"mappings":"AAIA,SAASA,GAAG,EAAEC,KAAK,EAAEC,IAAI,EAAEC,EAAE,EAAEC,GAAG,QAAQ,cAAa;AAEvD,OAAOC,iBAAiB,gBAAe;AAKvC,SAASC,kBAAkB,QAAQ,uBAAsB;AACzD,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,8BAA8B,QAAQ,sCAAqC;AAqBpF;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,4BAA4B,CAAC,EACxCC,OAAO,EACPC,gBAAgB,EAChBC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,IAAI,EACJC,WAAW,EACXC,IAAI,EACJC,KAAK,EACyB;IAC9B,IAAI,CAACC,MAAMC,OAAO,CAACT,MAAMU,UAAU,GAAG;QACpC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIX,MAAMU,UAAU,CAACE,MAAM,KAAK,GAAG;QACjC,MAAM,IAAID,MAAM;IAClB;IAEA,IAAIH,MAAMC,OAAO,CAACH,OAAO;QACvB,MAAM,IAAIK,MAAM;IAClB;IAEA,MAAME,cAAcb,MAAMU,UAAU;IACpC,MAAMI,aAAa,GAAGV,KAAKW,UAAU,CAAC,KAAK,OAAOf,MAAMgB,IAAI,EAAE;IAC9D,MAAMC,KAAKnB,QAAQoB,OAAO;IAC1B,MAAMC,SAASnB,MAAMoB,EAAE,CAACC,KAAK,CAAC,KAAKC,IAAI,CAAC;IACxC,MAAMC,mBAAmBV,YAAYW,GAAG,CAAC,CAACd;QACxC,IAAI,CAACZ,QAAQ2B,OAAO,CAACZ,WAAW,CAACH,WAAW,EAAE;YAC5C,MAAM,IAAIC,MAAM,CAAC,qCAAqC,EAAED,WAAW,CAAC,CAAC;QACvE;QAEA,MAAMgB,YAAY5B,QAAQ6B,YAAY,CAACC,GAAG,CAACnC,YAAYiB;QACvD,MAAMmB,Q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IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEG,iBAAiB,GAAG,EAAEzC,OAAO,KAAK,EAAEpB,iBAAiB,MAAM,CAAC;IAC5F,MAAMkE,YAAYzE,GAAG,CAAC;WACb,EAAEE,mBAAmBI,SAAS;QACnC6C,IAAInD,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,MAAM,CAAC;QACrCT,YAAYtD,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,cAAc,CAAC;IACvD,GAAG;;oBAEa,EAAE/D,GAAG,CAAC,EAAEgD,WAAWK,EAAE,CAACe,kBAAkB,CAAC,CAAC;YAClD,EAAEI,YAAY,EAAEH,eAAe;SAClC,EAAErE,IAAIiE,GAAG,CAAC,CAAC,CAAC,EAAEF,cAAc,CAAC,CAAC,EAAE;GACtC,CAAC,CAACV,EAAE,CAAC/B;IAEN,OAAO;QACLA;QACAzB,OAAOqE;QACPO;IACF;AACF,EAAC;AAED,MAAMhC,eAAe,CAAC,EACpBnC,OAAO,EACPe,WAAW,EACXP,IAAI,EAKL;IACC,IAAIA,MAAM;QACR,OAAOA;IACT;IAEA,MAAM4D,eAAerD,YAAYsD,IAAI,CAAC,CAACzD,aACrCZ,QAAQ2B,OAAO,CAACZ,WAAW,CAACH,WAAW,CAAC0D,MAAM,CAACC,MAAM,CAACF,IAAI,CACxD,CAACnE,QAAUA,MAAMsE,IAAI,KAAK,UAAUtE,MAAMgB,IAAI,KAAK;IAIvD,OAAOkD,eAAe,eAAe;AACvC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export { upsert } from './upsert.js';
|
|
|
44
44
|
export { upsertRow } from './upsertRow/index.js';
|
|
45
45
|
export { buildDynamicPredefinedBlocksToJsonMigration, createBlocksToJsonMigrator, getBlocksToJsonMigrator, } from './utilities/blocksToJsonMigrator.js';
|
|
46
46
|
export { buildCreateMigration } from './utilities/buildCreateMigration.js';
|
|
47
|
+
export { buildDynamicPredefinedSizesToVariantsMigration } from './utilities/buildDynamicPredefinedSizesToVariantsMigration.js';
|
|
47
48
|
export { buildIndexName } from './utilities/buildIndexName.js';
|
|
48
49
|
export { createSchemaGenerator } from './utilities/createSchemaGenerator.js';
|
|
49
50
|
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
@@ -51,12 +52,4 @@ export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
|
51
52
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
52
53
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
53
54
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated remove in 4.0
|
|
56
|
-
* use
|
|
57
|
-
* ```ts
|
|
58
|
-
* import { findMigrationDir } from 'payload'
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare const findMigrationDir: (migrationDir?: string) => string;
|
|
62
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,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,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AAM,iDAAiD,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export { upsert } from './upsert.js';
|
|
|
42
42
|
export { upsertRow } from './upsertRow/index.js';
|
|
43
43
|
export { buildDynamicPredefinedBlocksToJsonMigration, createBlocksToJsonMigrator, getBlocksToJsonMigrator } from './utilities/blocksToJsonMigrator.js';
|
|
44
44
|
export { buildCreateMigration } from './utilities/buildCreateMigration.js';
|
|
45
|
+
export { buildDynamicPredefinedSizesToVariantsMigration } from './utilities/buildDynamicPredefinedSizesToVariantsMigration.js';
|
|
45
46
|
export { buildIndexName } from './utilities/buildIndexName.js';
|
|
46
47
|
export { createSchemaGenerator } from './utilities/createSchemaGenerator.js';
|
|
47
48
|
export { executeSchemaHooks } from './utilities/executeSchemaHooks.js';
|
|
@@ -49,13 +50,5 @@ export { extendDrizzleTable } from './utilities/extendDrizzleTable.js';
|
|
|
49
50
|
export { hasLocalesTable } from './utilities/hasLocalesTable.js';
|
|
50
51
|
export { pushDevSchema } from './utilities/pushDevSchema.js';
|
|
51
52
|
export { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js';
|
|
52
|
-
import { findMigrationDir as payloadFindMigrationDir } from 'payload';
|
|
53
|
-
/**
|
|
54
|
-
* @deprecated remove in 4.0
|
|
55
|
-
* use
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { findMigrationDir } from 'payload'
|
|
58
|
-
* ```
|
|
59
|
-
*/ export const findMigrationDir = payloadFindMigrationDir;
|
|
60
53
|
|
|
61
54
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { countGlobalVersions } from './countGlobalVersions.js'\nexport { countVersions } from './countVersions.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 { findDistinct } from './findDistinct.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.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 { buildQuery } from './queries/buildQuery.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { DrizzleResolvedOperator, Operators } from './queries/operatorMap.js'\nexport { parseParams } from './queries/parseParams.js'\nexport { validateOperatorHandlers } from './queries/validateOperatorHandlers.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { buildDrizzleRelations } from './schema/buildDrizzleRelations.js'\nexport { buildRawSchema } from './schema/buildRawSchema.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport type {\n BaseRawColumn,\n BlocksToJsonMigrator,\n BuildDrizzleTable,\n BuildQueryJoinAliases,\n ColumnToCodeConverter,\n CountDistinct,\n CreateJSONQueryArgs,\n DeleteWhere,\n DrizzleAdapter,\n DrizzleOperandTransformHandler,\n DrizzleOperatorHandler,\n DrizzleOperatorHandlerContext,\n DrizzleOperatorReplacementHandler,\n DrizzleQueryConfig,\n DrizzleTransaction,\n DropDatabase,\n EnumRawColumn,\n Execute,\n GenericColumn,\n GenericColumns,\n GenericPgColumn,\n GenericRelation,\n GenericTable,\n IDType,\n Insert,\n IntegerRawColumn,\n Migration,\n PostgresDB,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n RequireDrizzleKit,\n SetColumnID,\n SQLiteDB,\n TimestampRawColumn,\n TransactionPg,\n TransactionSQLite,\n UUIDRawColumn,\n VectorRawColumn,\n} from './types.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateJobs } from './updateJobs.js'\nexport { updateMany } from './updateMany.js'\nexport { updateOne } from './updateOne.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsert } from './upsert.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport {\n buildDynamicPredefinedBlocksToJsonMigration,\n createBlocksToJsonMigrator,\n getBlocksToJsonMigrator,\n} from './utilities/blocksToJsonMigrator.js'\nexport { buildCreateMigration } from './utilities/buildCreateMigration.js'\nexport { buildIndexName } from './utilities/buildIndexName.js'\nexport { createSchemaGenerator } from './utilities/createSchemaGenerator.js'\nexport { executeSchemaHooks } from './utilities/executeSchemaHooks.js'\nexport { extendDrizzleTable } from './utilities/extendDrizzleTable.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { count } from './count.js'\nexport { countGlobalVersions } from './countGlobalVersions.js'\nexport { countVersions } from './countVersions.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 { findDistinct } from './findDistinct.js'\nexport { findGlobal } from './findGlobal.js'\nexport { findGlobalVersions } from './findGlobalVersions.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 { buildQuery } from './queries/buildQuery.js'\nexport { operatorMap } from './queries/operatorMap.js'\nexport type { DrizzleResolvedOperator, Operators } from './queries/operatorMap.js'\nexport { parseParams } from './queries/parseParams.js'\nexport { validateOperatorHandlers } from './queries/validateOperatorHandlers.js'\nexport { queryDrafts } from './queryDrafts.js'\nexport { buildDrizzleRelations } from './schema/buildDrizzleRelations.js'\nexport { buildRawSchema } from './schema/buildRawSchema.js'\nexport { beginTransaction } from './transactions/beginTransaction.js'\nexport { commitTransaction } from './transactions/commitTransaction.js'\nexport { rollbackTransaction } from './transactions/rollbackTransaction.js'\nexport type {\n BaseRawColumn,\n BlocksToJsonMigrator,\n BuildDrizzleTable,\n BuildQueryJoinAliases,\n ColumnToCodeConverter,\n CountDistinct,\n CreateJSONQueryArgs,\n DeleteWhere,\n DrizzleAdapter,\n DrizzleOperandTransformHandler,\n DrizzleOperatorHandler,\n DrizzleOperatorHandlerContext,\n DrizzleOperatorReplacementHandler,\n DrizzleQueryConfig,\n DrizzleTransaction,\n DropDatabase,\n EnumRawColumn,\n Execute,\n GenericColumn,\n GenericColumns,\n GenericPgColumn,\n GenericRelation,\n GenericTable,\n IDType,\n Insert,\n IntegerRawColumn,\n Migration,\n PostgresDB,\n RawColumn,\n RawForeignKey,\n RawIndex,\n RawRelation,\n RawTable,\n RelationMap,\n RequireDrizzleKit,\n SetColumnID,\n SQLiteDB,\n TimestampRawColumn,\n TransactionPg,\n TransactionSQLite,\n UUIDRawColumn,\n VectorRawColumn,\n} from './types.js'\nexport { updateGlobal } from './updateGlobal.js'\nexport { updateGlobalVersion } from './updateGlobalVersion.js'\nexport { updateJobs } from './updateJobs.js'\nexport { updateMany } from './updateMany.js'\nexport { updateOne } from './updateOne.js'\nexport { updateVersion } from './updateVersion.js'\nexport { upsert } from './upsert.js'\nexport { upsertRow } from './upsertRow/index.js'\nexport {\n buildDynamicPredefinedBlocksToJsonMigration,\n createBlocksToJsonMigrator,\n getBlocksToJsonMigrator,\n} from './utilities/blocksToJsonMigrator.js'\nexport { buildCreateMigration } from './utilities/buildCreateMigration.js'\nexport { buildDynamicPredefinedSizesToVariantsMigration } from './utilities/buildDynamicPredefinedSizesToVariantsMigration.js'\nexport { buildIndexName } from './utilities/buildIndexName.js'\nexport { createSchemaGenerator } from './utilities/createSchemaGenerator.js'\nexport { executeSchemaHooks } from './utilities/executeSchemaHooks.js'\nexport { extendDrizzleTable } from './utilities/extendDrizzleTable.js'\nexport { hasLocalesTable } from './utilities/hasLocalesTable.js'\nexport { pushDevSchema } from './utilities/pushDevSchema.js'\nexport { validateExistingBlockIsIdentical } from './utilities/validateExistingBlockIsIdentical.js'\n"],"names":["count","countGlobalVersions","countVersions","create","createGlobal","createGlobalVersion","createTableName","createVersion","deleteMany","deleteOne","deleteVersions","destroy","find","findDistinct","findGlobal","findGlobalVersions","findOne","findVersions","migrate","migrateDown","migrateFresh","migrateRefresh","migrateReset","migrateStatus","buildQuery","operatorMap","parseParams","validateOperatorHandlers","queryDrafts","buildDrizzleRelations","buildRawSchema","beginTransaction","commitTransaction","rollbackTransaction","updateGlobal","updateGlobalVersion","updateJobs","updateMany","updateOne","updateVersion","upsert","upsertRow","buildDynamicPredefinedBlocksToJsonMigration","createBlocksToJsonMigrator","getBlocksToJsonMigrator","buildCreateMigration","buildDynamicPredefinedSizesToVariantsMigration","buildIndexName","createSchemaGenerator","executeSchemaHooks","extendDrizzleTable","hasLocalesTable","pushDevSchema","validateExistingBlockIsIdentical"],"mappings":"AAAA,SAASA,KAAK,QAAQ,aAAY;AAClC,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,MAAM,QAAQ,cAAa;AACpC,SAASC,YAAY,QAAQ,oBAAmB;AAChD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;AACpC,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SACEC,2CAA2C,EAC3CC,0BAA0B,EAC1BC,uBAAuB,QAClB,sCAAqC;AAC5C,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,8CAA8C,QAAQ,gEAA+D;AAC9H,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,qBAAqB,QAAQ,uCAAsC;AAC5E,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,kBAAkB,QAAQ,oCAAmC;AACtE,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SAASC,gCAAgC,QAAQ,kDAAiD"}
|
package/dist/migrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,YAAY,CAAA;AAM3D,eAAO,MAAM,OAAO,EAAE,cAAc,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAa,MAAM,YAAY,CAAA;AAM3D,eAAO,MAAM,OAAO,EAAE,cAAc,CAAC,SAAS,CA+E7C,CAAA"}
|
package/dist/migrate.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
@@ -29,6 +29,7 @@ export const migrate = async function migrate(args) {
|
|
|
29
29
|
({ docs: migrationsInDB } = await payload.find({
|
|
30
30
|
collection: 'payload-migrations',
|
|
31
31
|
limit: 0,
|
|
32
|
+
overrideAccess: true,
|
|
32
33
|
sort: '-name'
|
|
33
34
|
}));
|
|
34
35
|
if (migrationsInDB.find((m)=>m.batch === -1)) {
|
|
@@ -83,7 +84,9 @@ export const migrate = async function migrate(args) {
|
|
|
83
84
|
};
|
|
84
85
|
async function runMigrationFile(payload, migration, batch) {
|
|
85
86
|
const start = Date.now();
|
|
86
|
-
const req = await
|
|
87
|
+
const req = await createPayloadRequest({
|
|
88
|
+
payload
|
|
89
|
+
});
|
|
87
90
|
payload.logger.info({
|
|
88
91
|
msg: `Migrating: ${migration.name}`
|
|
89
92
|
});
|
|
@@ -104,6 +107,7 @@ async function runMigrationFile(payload, migration, batch) {
|
|
|
104
107
|
name: migration.name,
|
|
105
108
|
batch
|
|
106
109
|
},
|
|
110
|
+
overrideAccess: true,
|
|
107
111
|
req
|
|
108
112
|
});
|
|
109
113
|
await commitTransaction(req);
|
package/dist/migrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["import type { MigrationResult, Payload } from 'payload'\n\nimport {\n commitTransaction,\n
|
|
1
|
+
{"version":3,"sources":["../src/migrate.ts"],"sourcesContent":["import type { MigrationResult, Payload } 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, Migration } from './types.js'\n\nimport { getTransaction } from './utilities/getTransaction.js'\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) {\n const { payload } = this\n const { forceAcceptWarning = false, shouldPrompt = true } = args ?? {}\n const migrationFiles = args?.migrations || (await readMigrationFiles({ payload }))\n\n if (!migrationFiles.length) {\n payload.logger.info({ msg: 'No migrations to run.' })\n return { migrated: [], rolledBack: [] }\n }\n\n if ('createExtensions' in this && typeof this.createExtensions === 'function') {\n await this.createExtensions()\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 overrideAccess: true,\n sort: '-name',\n }))\n\n if (migrationsInDB.find((m) => m.batch === -1)) {\n if (!forceAcceptWarning) {\n if (!shouldPrompt) {\n return { cancelled: true, migrated: [], rolledBack: [] }\n }\n\n const { confirm: runMigrations } = await prompts({\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 if (!runMigrations) {\n return { cancelled: true, migrated: [], rolledBack: [] }\n }\n }\n // ignore the dev migration so that the latest batch number increments correctly\n migrationsInDB = migrationsInDB.filter((m) => m.batch !== -1)\n }\n\n if (Number(migrationsInDB?.[0]?.batch) > 0) {\n latestBatch = Number(migrationsInDB[0]?.batch)\n }\n }\n\n const newBatch = latestBatch + 1\n const migrated: string[] = []\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 migrated.push(migration.name)\n }\n\n return {\n ...(migrated.length ? { batch: newBatch } : {}),\n migrated,\n rolledBack: [],\n } satisfies MigrationResult\n}\n\nasync function runMigrationFile(payload: Payload, migration: Migration, batch: number) {\n const start = Date.now()\n const req = await createPayloadRequest({ payload })\n\n payload.logger.info({ msg: `Migrating: ${migration.name}` })\n\n try {\n await initTransaction(req)\n const db = await getTransaction(payload.db as DrizzleAdapter, req)\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 overrideAccess: true,\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 throw err\n }\n}\n"],"names":["commitTransaction","createPayloadRequest","initTransaction","killTransaction","readMigrationFiles","prompts","getTransaction","migrationTableExists","parseError","migrate","args","payload","forceAcceptWarning","shouldPrompt","migrationFiles","migrations","length","logger","info","msg","migrated","rolledBack","createExtensions","latestBatch","migrationsInDB","hasMigrationTable","docs","find","collection","limit","overrideAccess","sort","m","batch","cancelled","confirm","runMigrations","name","type","initial","message","filter","Number","newBatch","migration","alreadyRan","existing","runMigrationFile","push","start","Date","now","req","db","up","create","data","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,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,UAAqC,eAAeA,QAE/DC,IAAI;IAEJ,MAAM,EAAEC,OAAO,EAAE,GAAG,IAAI;IACxB,MAAM,EAAEC,qBAAqB,KAAK,EAAEC,eAAe,IAAI,EAAE,GAAGH,QAAQ,CAAC;IACrE,MAAMI,iBAAiBJ,MAAMK,cAAe,MAAMX,mBAAmB;QAAEO;IAAQ;IAE/E,IAAI,CAACG,eAAeE,MAAM,EAAE;QAC1BL,QAAQM,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAAwB;QACnD,OAAO;YAAEC,UAAU,EAAE;YAAEC,YAAY,EAAE;QAAC;IACxC;IAEA,IAAI,sBAAsB,IAAI,IAAI,OAAO,IAAI,CAACC,gBAAgB,KAAK,YAAY;QAC7E,MAAM,IAAI,CAACA,gBAAgB;IAC7B;IAEA,IAAIC,cAAc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,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"migrateDown.d.ts","sourceRoot":"","sources":["../src/migrateDown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAW9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAMhD,wBAAsB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CA+DhF"}
|
package/dist/migrateDown.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';
|
|
@@ -30,7 +30,9 @@ export async function migrateDown() {
|
|
|
30
30
|
throw new Error(`Migration ${migration.name} not found locally.`);
|
|
31
31
|
}
|
|
32
32
|
const start = Date.now();
|
|
33
|
-
const req = await
|
|
33
|
+
const req = await createPayloadRequest({
|
|
34
|
+
payload
|
|
35
|
+
});
|
|
34
36
|
try {
|
|
35
37
|
payload.logger.info({
|
|
36
38
|
msg: `Migrating down: ${migrationFile.name}`
|
|
@@ -50,6 +52,7 @@ export async function migrateDown() {
|
|
|
50
52
|
await payload.delete({
|
|
51
53
|
id: migration.id,
|
|
52
54
|
collection: 'payload-migrations',
|
|
55
|
+
overrideAccess: true,
|
|
53
56
|
req
|
|
54
57
|
});
|
|
55
58
|
}
|
package/dist/migrateDown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateDown.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\n commitTransaction,\n
|
|
1
|
+
{"version":3,"sources":["../src/migrateDown.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\nexport async function migrateDown(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 latestBatchMigrations = existingMigrations.filter(({ batch }) => batch === latestBatch)\n const rolledBack: string[] = []\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 = await createPayloadRequest({ payload })\n\n try {\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\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 await killTransaction(req)\n\n payload.logger.error({\n err,\n msg: parseError(err, `Error migrating down ${migrationFile.name}. Rolling back.`),\n })\n throw err\n }\n }\n\n return { batch: latestBatch, migrated: [], rolledBack }\n}\n"],"names":["commitTransaction","createPayloadRequest","getMigrations","initTransaction","killTransaction","readMigrationFiles","getTransaction","migrationTableExists","parseError","migrateDown","payload","migrationFiles","existingMigrations","latestBatch","length","logger","info","msg","migrated","rolledBack","latestBatchMigrations","filter","batch","migration","migrationFile","find","m","name","Error","start","Date","now","req","db","down","tableExists","delete","id","collection","overrideAccess","push","err","error"],"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,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/BJ,QAAQK,MAAM,CAACC,IAAI,CAAC;YAAEC,KAAK;QAA6B;QACxD,OAAO;YAAEC,UAAU,EAAE;YAAEC,YAAY,EAAE;QAAC;IACxC;IAEAT,QAAQK,MAAM,CAACC,IAAI,CAAC;QAClBC,KAAK,CAAC,mBAAmB,EAAEJ,YAAY,eAAe,EAAED,mBAAmBE,MAAM,CAAC,cAAc,CAAC;IACnG;IAEA,MAAMM,wBAAwBR,mBAAmBS,MAAM,CAAC,CAAC,EAAEC,KAAK,EAAE,GAAKA,UAAUT;IACjF,MAAMM,aAAuB,EAAE;IAE/B,KAAK,MAAMI,aAAaH,sBAAuB;QAC7C,MAAMI,gBAAgBb,eAAec,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKJ,UAAUI,IAAI;QAC1E,IAAI,CAACH,eAAe;YAClB,MAAM,IAAII,MAAM,CAAC,UAA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C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAKhD;;GAEG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,cAAc,EACpB,EAAE,kBAA0B,EAAE,YAAmB,EAAE;;;CAAA,GAClD,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"migrateFresh.d.ts","sourceRoot":"","sources":["../src/migrateFresh.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,CAChC,IAAI,EAAE,cAAc,EACpB,EAAE,kBAA0B,EAAE,YAAmB,EAAE;;;CAAA,GAClD,OAAO,CAAC,eAAe,CAAC,CAsE1B"}
|
package/dist/migrateFresh.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
@@ -40,7 +40,9 @@ import { parseError } from './utilities/parseError.js';
|
|
|
40
40
|
payload.logger.debug({
|
|
41
41
|
msg: `Found ${migrationFiles.length} migration files.`
|
|
42
42
|
});
|
|
43
|
-
const req = await
|
|
43
|
+
const req = await createPayloadRequest({
|
|
44
|
+
payload
|
|
45
|
+
});
|
|
44
46
|
const migrated = [];
|
|
45
47
|
if ('createExtensions' in this && typeof this.createExtensions === 'function') {
|
|
46
48
|
await this.createExtensions();
|
|
@@ -65,6 +67,7 @@ import { parseError } from './utilities/parseError.js';
|
|
|
65
67
|
name: migration.name,
|
|
66
68
|
batch: 1
|
|
67
69
|
},
|
|
70
|
+
overrideAccess: true,
|
|
68
71
|
req
|
|
69
72
|
});
|
|
70
73
|
await commitTransaction(req);
|
package/dist/migrateFresh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateFresh.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\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;IAE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K,CAAC,wBAAwB,EAAEZ,UAAUd,IAAI,CAAC,cAAc,CAAC;YAChF;YACA,MAAM0B;QACR;IACF;IAEA,OAAO;QAAEH,OAAO;QAAG3B;QAAUC,YAAY,EAAE;IAAC;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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';
|
|
@@ -24,7 +24,9 @@ import { parseError } from './utilities/parseError.js';
|
|
|
24
24
|
payload.logger.info({
|
|
25
25
|
msg: `Rolling back batch ${latestBatch} consisting of ${existingMigrations.length} migration(s).`
|
|
26
26
|
});
|
|
27
|
-
const req = await
|
|
27
|
+
const req = await createPayloadRequest({
|
|
28
|
+
payload
|
|
29
|
+
});
|
|
28
30
|
const migrated = [];
|
|
29
31
|
const rolledBack = [];
|
|
30
32
|
// Reverse order of migrations to rollback
|
|
@@ -53,6 +55,7 @@ import { parseError } from './utilities/parseError.js';
|
|
|
53
55
|
if (tableExists) {
|
|
54
56
|
await payload.delete({
|
|
55
57
|
collection: 'payload-migrations',
|
|
58
|
+
overrideAccess: true,
|
|
56
59
|
req,
|
|
57
60
|
where: {
|
|
58
61
|
name: {
|
|
@@ -90,6 +93,7 @@ import { parseError } from './utilities/parseError.js';
|
|
|
90
93
|
name: migration.name,
|
|
91
94
|
executed: true
|
|
92
95
|
},
|
|
96
|
+
overrideAccess: true,
|
|
93
97
|
req
|
|
94
98
|
});
|
|
95
99
|
await commitTransaction(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrateRefresh.ts"],"sourcesContent":["import type { MigrationResult } from 'payload'\n\nimport {\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,E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jB,UAAUI,IAAI;YAE5BhB,QAAQK,MAAM,CAACC,IAAI,CAAC;gBAAEC,KAAK,CAAC,WAAW,EAAEK,UAAUI,IAAI,CAAC,EAAE,EAAEG,KAAKC,GAAG,KAAKF,MAAM,GAAG,CAAC;YAAC;QACtF,EAAE,OAAOY,KAAc;YACrB,MAAMpC,gBAAgBgB;YACtBV,QAAQK,MAAM,CAAC0B,KAAK,CAAC;gBACnBD;gBACAvB,KAAKT,WAAWgC,KAAK,CAAC,wBAAwB,EAAElB,UAAUI,IAAI,CAAC,eAAe,CAAC;YACjF;YACA,MAAMc;QACR;IACF;IAEA,OAAO;QAAEtB;QAAUC;IAAW;AAChC"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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
|
/**
|
|
@@ -20,7 +20,9 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
20
20
|
rolledBack: []
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
const req = await
|
|
23
|
+
const req = await createPayloadRequest({
|
|
24
|
+
payload
|
|
25
|
+
});
|
|
24
26
|
existingMigrations.reverse();
|
|
25
27
|
const rolledBack = [];
|
|
26
28
|
// Rollback all migrations in order
|
|
@@ -49,6 +51,7 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
49
51
|
await payload.delete({
|
|
50
52
|
id: migration.id,
|
|
51
53
|
collection: 'payload-migrations',
|
|
54
|
+
overrideAccess: true,
|
|
52
55
|
req
|
|
53
56
|
});
|
|
54
57
|
}
|
|
@@ -73,6 +76,7 @@ import { migrationTableExists } from './utilities/migrationTableExists.js';
|
|
|
73
76
|
try {
|
|
74
77
|
await payload.delete({
|
|
75
78
|
collection: 'payload-migrations',
|
|
79
|
+
overrideAccess: true,
|
|
76
80
|
where: {
|
|
77
81
|
batch: {
|
|
78
82
|
equals: -1
|