-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f0d54c
commit 2e8fdd1
Showing
8 changed files
with
204 additions
and
66 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
server/src/db/migrations/20230905150329-organisation_person_sources.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Db, MongoClient } from "mongodb"; | ||
|
||
export const up = async (db: Db, _client: MongoClient) => { | ||
await db.collection("organisations").updateMany( | ||
{ | ||
"_meta.source": { $exists: true, $ne: "" }, | ||
}, | ||
[ | ||
{ | ||
$set: { | ||
"_meta.sources": ["$_meta.source"], | ||
}, | ||
}, | ||
{ | ||
$unset: "_meta.source", | ||
}, | ||
] | ||
); | ||
|
||
await db.collection("persons").updateMany( | ||
{ | ||
"_meta.source": { $exists: true, $ne: "" }, | ||
}, | ||
[ | ||
{ | ||
$set: { | ||
"_meta.sources": ["$_meta.source"], | ||
}, | ||
}, | ||
{ | ||
$unset: "_meta.source", | ||
}, | ||
] | ||
); | ||
}; | ||
|
||
export const down = async (db: Db, _client: MongoClient) => { | ||
db.collection("organisations").updateMany( | ||
{ | ||
"_meta.sources": { $exists: true }, | ||
}, | ||
[ | ||
{ | ||
$set: { | ||
"_meta.source": { $arrayElemAt: ["$_meta.sources", 0] }, | ||
}, | ||
}, | ||
{ | ||
$unset: "_meta.sources", | ||
}, | ||
] | ||
); | ||
|
||
db.collection("persons").updateMany( | ||
{ | ||
"_meta.sources": { $exists: true }, | ||
}, | ||
[ | ||
{ | ||
$set: { | ||
"_meta.source": { $arrayElemAt: ["$_meta.sources", 0] }, | ||
}, | ||
}, | ||
{ | ||
$unset: "_meta.sources", | ||
}, | ||
] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters