数据库初始化脚本 #648
gradytvhooopuy-wq
started this conversation in
General
数据库初始化脚本
#648
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
// 先在 mongosh 中 use 到目标库:use chatgpt,然后粘贴并执行本脚本
function ensureCollection(name) {
const names = db.getCollectionInfos().map(i => i.name)
if (!names.includes(name)) db.createCollection(name)
}
function ensureIndex(col, keys, options) {
db.getCollection(col).createIndex(keys, options || {})
}
ensureCollection('user')
ensureIndex('user', { email: 1 }, { unique: true, name: 'uniq_email' })
ensureIndex('user', { status: 1 }, { name: 'idx_user_status' })
ensureIndex('user', { roles: 1 }, { name: 'idx_user_roles' })
ensureCollection('chat_room')
ensureIndex('chat_room', { userId: 1, roomId: 1 }, { unique: true, name: 'uniq_user_room' })
ensureIndex('chat_room', { status: 1 }, { name: 'idx_room_status' })
ensureCollection('chat')
ensureIndex('chat', { roomId: 1, uuid: 1 }, { unique: true, name: 'uniq_room_uuid' })
ensureIndex('chat', { 'options.messageId': 1 }, { name: 'idx_message_id' })
ensureIndex('chat', { dateTime: -1 }, { name: 'idx_chat_datetime' })
ensureIndex('chat', { status: 1 }, { name: 'idx_chat_status' })
ensureCollection('chat_usage')
ensureIndex('chat_usage', { userId: 1, dateTime: 1 }, { name: 'idx_usage_user_datetime' })
ensureIndex('chat_usage', { chatId: 1 }, { name: 'idx_usage_chat' })
ensureIndex('chat_usage', { messageId: 1 }, { name: 'idx_usage_message' })
ensureCollection('config')
ensureCollection('key_config')
ensureIndex('key_config', { key: 1 }, { unique: true, name: 'uniq_api_key' })
ensureIndex('key_config', { status: 1 }, { name: 'idx_key_status' })
ensureIndex('key_config', { keyModel: 1 }, { name: 'idx_key_model' })
ensureCollection('built_in_prompt')
ensureIndex('built_in_prompt', { title: 1 }, { name: 'idx_built_in_title' })
ensureCollection('user_prompt')
ensureIndex('user_prompt', { userId: 1 }, { name: 'idx_user_prompt_user' })
ensureIndex('user_prompt', { title: 1 }, { name: 'idx_user_prompt_title' })
ensureCollection('giftcards')
ensureIndex('giftcards', { cardno: 1 }, { unique: true, name: 'uniq_cardno' })
ensureIndex('giftcards', { redeemed: 1 }, { name: 'idx_redeemed' })
ensureIndex('giftcards', { redeemed_by: 1 }, { name: 'idx_redeemed_by' })
const cfgCol = db.getCollection('config')
if (cfgCol.countDocuments() === 0) {
cfgCol.insertOne({
_id: ObjectId(),
timeoutMs: 60000,
apiKey: '',
apiDisableDebug: false,
accessToken: '',
apiBaseUrl: '',
reverseProxy: '',
socksProxy: '',
socksAuth: '',
httpsProxy: '',
siteConfig: {
siteTitle: 'ChatGPT Web',
loginEnabled: true,
authProxyEnabled: false,
loginSalt: '',
registerEnabled: true,
registerReview: false,
registerMails: '',
siteDomain: '',
chatModels: 'gpt-3.5-turbo',
globalAmount: 10,
usageCountLimit: true,
showWatermark: false
},
mailConfig: null,
auditConfig: {
enabled: false,
provider: 'baidu',
options: { apiKey: '', apiSecret: '', label: '' },
textType: 0,
customizeEnabled: false,
sensitiveWords: ''
},
searchConfig: {
enabled: false,
provider: 'tavily',
options: { apiKey: '', maxResults: 5, includeRawContent: false },
systemMessageWithSearchResult: '',
systemMessageGetSearchQuery: ''
},
advancedConfig: {
systemMessage: '',
temperature: 0.7,
top_p: 1
},
announceConfig: {
enabled: false,
announceWords: ''
}
})
}
Beta Was this translation helpful? Give feedback.
All reactions