Skip to content

Commit

Permalink
Add db indexes (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Jul 2, 2024
1 parent e26f500 commit e28fbd5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions srv/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,43 @@ export async function createIndexes() {
await db('chat-member').createIndex({ chatId: 1 }, { name: 'chat-messages_chatId' }) // This index name is a typo, but can't be changed due to already being shipped
await db('chat-member').createIndex({ userId: 1 }, { name: 'chat-members_userId' })
await db('profile').createIndex({ userId: 1 }, { name: 'profiles_userId' })

await db('character').createIndex({ userId: 1 }, { name: 'characters_userId' })

await db('chat').createIndex({ userId: 1 }, { name: 'chats_userId' })
await db('chat').createIndex({ characterId: 1, userId: 1 }, { name: 'chats_characterId_userId' })

await db('memory').createIndex({ userId: 1 }, { name: 'memory_userId' })

await db('gen-setting').createIndex({ userId: 1 }, { name: 'gen-setting_userId' })

await db('chat-message').createIndex({ chatId: 1 }, { name: 'chatmessages_chatId' })
await db('chat-message').createIndex(
{ chatId: 1, kind: 1, createdAt: -1 },
{ name: 'chatmessages_chatId_kind_createdAt' }
)

await db('scenario').createIndex({ userId: 1 }, { name: 'scenario_userId' })

await db('apikey').createIndex({ userId: 1 }, { name: 'apikey_userId' })
await db('apikey').createIndex({ apikey: 1 }, { name: 'apikey_apikey' })
await db('apikey').createIndex({ code: 1 }, { name: 'apikey_code' })

await db('prompt-template').createIndex({ userId: 1 }, { name: 'prompt-templates_userId' })
await db('configuration').createIndex(
{ kind: 1 },
{ unique: true, name: 'configuration_unique_kind' }
)

await db('user').createIndex({ username: 1 }, { name: 'user_username' })
await db('user').createIndex({ kind: 1, username: 1 }, { name: 'user_kind_username' })
await db('user').createIndex({ apiKey: 1 }, { name: 'user_apiKey' })
await db('user').createIndex({ patreonUserId: 1 }, { name: 'user_patreonUserId' })
await db('user').createIndex(
{ 'patreon.user.attributes.email': 1 },
{ name: 'user_patreonEmail' }
)

await db('saga-template').createIndex({ userId: 1 }, { name: 'saga-template_userId' })
await db('saga-session').createIndex({ userId: 1 }, { name: 'saga-session_userId' })
await db('saga-session').createIndex({ templateId: 1 }, { name: 'saga-session_templateId' })
Expand Down

0 comments on commit e28fbd5

Please sign in to comment.