Files
FastGPT/projects/app/src/pages/api/admin/initv481.ts
Archer a259d034b8 4.8.3 (#1654)
* Milvus (#1644)

* feat: support regx

* 4.8.3 test and fix (#1648)

* perf: version tip

* feat: sandbox support log

* fix: debug component render

* fix: share page header

* fix: input guide auth

* fix: iso viewport

* remove file

* fix: route url

* feat: add debug timout

* perf: reference select support trigger

* perf: session code

* perf: theme

* perf: load milvus
2024-06-01 09:26:11 +08:00

203 lines
7.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
import { NextAPI } from '@/service/middleware/entry';
import { connectionMongo } from '@fastgpt/service/common/mongo';
/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
async function handler(req: NextApiRequest, res: NextApiResponse) {
await authCert({ req, authRoot: true });
// 重命名 dataset.trainigns -> dataset_trainings
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'dataset.trainings' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('dataset.trainings');
const targetCol = connectionMongo.connection.db.collection('dataset_trainings');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'dataset_trainings 中有数据,无法自动将 dataset.trainings 迁移到 dataset_trainings请手动操作'
);
} else {
await sourceCol.rename('dataset_trainings', { dropTarget: true });
console.log('success rename dataset.trainings -> dataset_trainings');
}
}
} catch (error) {
console.log('error rename dataset.trainings -> dataset_trainings', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'dataset.collections' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('dataset.collections');
const targetCol = connectionMongo.connection.db.collection('dataset_collections');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'dataset_collections 中有数据,无法自动将 dataset.collections 迁移到 dataset_collections请手动操作'
);
} else {
await sourceCol.rename('dataset_collections', { dropTarget: true });
console.log('success rename dataset.collections -> dataset_collections');
}
}
} catch (error) {
console.log('error rename dataset.collections -> dataset_collections', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'dataset.datas' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('dataset.datas');
const targetCol = connectionMongo.connection.db.collection('dataset_datas');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'dataset_datas 中有数据,无法自动将 dataset.datas 迁移到 dataset_datas请手动操作'
);
} else {
await sourceCol.rename('dataset_datas', { dropTarget: true });
console.log('success rename dataset.datas -> dataset_datas');
}
}
} catch (error) {
console.log('error rename dataset.datas -> dataset_datas', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'app.versions' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('app.versions');
const targetCol = connectionMongo.connection.db.collection('app_versions');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'app_versions 中有数据,无法自动将 app.versions 迁移到 app_versions请手动操作'
);
} else {
await sourceCol.rename('app_versions', { dropTarget: true });
console.log('success rename app.versions -> app_versions');
}
}
} catch (error) {
console.log('error rename app.versions -> app_versions', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'buffer.rawtexts' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('buffer.rawtexts');
const targetCol = connectionMongo.connection.db.collection('buffer_rawtexts');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'buffer_rawtexts 中有数据,无法自动将 buffer.rawtexts 迁移到 buffer_rawtexts请手动操作'
);
} else {
await sourceCol.rename('buffer_rawtexts', { dropTarget: true });
console.log('success rename buffer.rawtexts -> buffer_rawtexts');
}
}
} catch (error) {
console.log('error rename buffer.rawtext -> buffer_rawtext', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'buffer.tts' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('buffer.tts');
const targetCol = connectionMongo.connection.db.collection('buffer_tts');
if ((await targetCol.countDocuments()) > 0) {
console.log('buffer_tts 中有数据,无法自动将 buffer.tts 迁移到 buffer_tts请手动操作');
} else {
await sourceCol.rename('buffer_tts', { dropTarget: true });
console.log('success rename buffer.tts -> buffer_tts');
}
}
} catch (error) {
console.log('error rename buffer.tts -> buffer_tts', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'team.members' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('team.members');
const targetCol = connectionMongo.connection.db.collection('team_members');
if ((await targetCol.countDocuments()) > 1) {
// 除了root
console.log('team_members 中有数据,无法自动将 team.tts 迁移到 team_members请手动操作');
} else {
await sourceCol.rename('team_members', { dropTarget: true });
console.log('success rename team.members -> team_members');
}
}
} catch (error) {
console.log('error rename team.members -> team_members', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'team.tags' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('team.tags');
const targetCol = connectionMongo.connection.db.collection('team_tags');
if ((await targetCol.countDocuments()) > 0) {
console.log('team_tags 中有数据,无法自动将 team.tags 迁移到 team_tags请手动操作');
} else {
await sourceCol.rename('team_tags', { dropTarget: true });
console.log('success rename team.tags -> team_tags');
}
}
} catch (error) {
console.log('error rename team.tags -> team_tags', error);
}
try {
const collections = await connectionMongo.connection.db
.listCollections({ name: 'team.subscriptions' })
.toArray();
if (collections.length > 0) {
const sourceCol = connectionMongo.connection.db.collection('team.subscriptions');
const targetCol = connectionMongo.connection.db.collection('team_subscriptions');
if ((await targetCol.countDocuments()) > 0) {
console.log(
'team_subscriptions 中有数据,无法自动将 team.subscriptions 迁移到 team_subscriptions请手动操作'
);
} else {
await sourceCol.rename('team_subscriptions', { dropTarget: true });
console.log('success rename team.subscriptions -> team_subscriptions');
}
}
} catch (error) {
console.log('error rename team.subscriptions -> team_subscriptions', error);
}
jsonRes(res, {
message: 'success'
});
}
export default NextAPI(handler);