Skip to content

Commit

Permalink
chore: init scripts move user avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
FinleyGe committed Jan 10, 2025
1 parent cdbf982 commit fc973d4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions projects/app/src/pages/api/admin/initv4818.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
import { MongoDatasetDataText } from '@fastgpt/service/core/dataset/data/dataTextSchema';
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
import { MongoUser } from '@fastgpt/service/support/user/schema';
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
import { NextApiRequest, NextApiResponse } from 'next';

/*
Expand All @@ -13,6 +15,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
2. 执行升级脚本,不要删除 MongoDatasetData 里的数据。
3. 切换正式版镜像,让 MongoDatasetDataText 生效。
4. 删除 MongoDatasetData 里的索引和多余字段。(4819 再删
5. 移动 User 表中的 avatar 字段到 TeamMember 表中。
*/
let success = 0;
async function handler(req: NextApiRequest, res: NextApiResponse) {
Expand All @@ -28,6 +31,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
success = 0;
// await batchUpdateFields();

await moveUserAvatar();
return { success: true };
}

Expand Down Expand Up @@ -102,3 +106,22 @@ const initData = async (batchSize: number) => {
// console.log('Delete success:', success);
// await batchUpdateFields(batchSize);
// };

const moveUserAvatar = async () => {
try {
const users = await MongoUser.find({});
for await (const user of users) {
await MongoTeamMember.updateOne(
{
_id: user._id
},
{
avatar: (user as any).avatar // 删除 avatar 字段, 因为 Type 改了,所以这里不能直接写 user.avatar
}
);
}
console.log('Move avatar success:', users.length);
} catch (error) {
console.error(error);
}
};

0 comments on commit fc973d4

Please sign in to comment.