Skip to content

Commit

Permalink
Merge pull request #1052 from AletheiaFact/stage
Browse files Browse the repository at this point in the history
Production Hotfix: Create source migration which moves extra properties to the props field #1051
  • Loading branch information
thesocialdev authored Oct 15, 2023
2 parents 80440ca + fa4f6e7 commit 87e45ee
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions migrations/20231013183353-move-source-extra-properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Db } from "mongodb";

export async function up(db: Db) {
const sourcesCursor = await db.collection("sources").find();

while (await sourcesCursor.hasNext()) {
const source = await sourcesCursor.next();
const { _id, user, href, targetId } = source;

const updateData: any = {
_id,
targetId,
href,
user,
props: {},
};

const copyPropsIfExist = (key) => {
if (source[key] || source.props?.[key]) {
updateData.props[key] = source[key] || source.props[key];
}
};

copyPropsIfExist("targetReference");
copyPropsIfExist("targetText");
copyPropsIfExist("textRange");

await db.collection("sources").update({ _id: source._id }, updateData);
}
}

0 comments on commit 87e45ee

Please sign in to comment.