Skip to content

Commit

Permalink
Update old migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Jan 15, 2024
1 parent d874f78 commit 1fc6329
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 63 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MigrateUpArgs, MigrateDownArgs } from "@payloadcms/db-mongodb";

export async function up({ payload }: MigrateUpArgs): Promise<void> {
const { db } = payload;
const collection = db.collections["pages"];
const result = await collection.updateMany(
{ "blocks.collection": { $exists: true } },
{
$set: {
"blocks.$.items": "$blocks.$.collection",
},
$unset: {
"blocks.$.collection": "",
},
},
);

console.log(`${result.modifiedCount} documents updated.`);
}

export async function down({ payload }: MigrateDownArgs): Promise<void> {
const { db } = payload;
const collection = db.collections["pages"];
const result = await collection.updateMany(
{ "blocks.items": { $exists: true } },
{
$set: {
"blocks.$.collection": "$blocks.$.items",
},
$unset: {
"blocks.$.items": "",
},
},
);
console.log(`${result.modifiedCount} documents updated.`);
}

0 comments on commit 1fc6329

Please sign in to comment.