-
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.
Browse files
Browse the repository at this point in the history
#173 프로필 이미지 업데이트 profileImageUpdatedAt 속성으로 관리
- Loading branch information
Showing
5 changed files
with
83 additions
and
19 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
// Issue #173을 해결하기 위한 DB 마이그레이션 스크립트입니다. | ||
// https://github.com/sparcs-kaist/taxi-back/issues/173 | ||
|
||
const { MongoClient } = require("mongodb"); | ||
const { mongo: mongoUrl, aws: awsEnv } = require("../loadenv"); | ||
|
||
const time = Date.now(); | ||
|
||
const client = new MongoClient(mongoUrl); | ||
const db = client.db("taxi"); | ||
const users = db.collection("users"); | ||
|
||
async function run() { | ||
try { | ||
for await (const doc of users.find()) { | ||
// 이미 변환이 완료된 경우에는 Pass합니다. | ||
if (doc.profileImageUrl.startsWith(awsEnv.s3Url)) continue; | ||
|
||
await users.findOneAndUpdate( | ||
{ _id: doc._id }, | ||
{ | ||
$set: { | ||
profileImageUrl: `${awsEnv.s3Url}/profile-img/${doc.profileImageUrl}?token=${time}`, | ||
}, | ||
} | ||
); | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} finally { | ||
await client.close(); | ||
} | ||
} | ||
run().then(() => { | ||
console.log("Done!"); | ||
}); |
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