mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-26 13:19:34 +07:00
🔨 chore: add batch query methods for UserModel and MessageModel (#13060)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: db-migrations
|
||||
description: Database migration guide. Use when generating migrations, writing migration SQL, or modifying database schemas. Triggers on migration generation, schema changes, or idempotent SQL questions.
|
||||
description: Database migration guide (Drizzle ORM + PostgreSQL). MUST USE when any of these occur: (1) generating or regenerating migration files (drizzle-kit generate), (2) adding/removing/modifying columns or tables in database schema, (3) resolving migration sequence conflicts after rebase, (4) writing or reviewing migration SQL (idempotent patterns), (5) renaming migration files. Triggers on keywords: migration, db:generate, ALTER TABLE, ADD COLUMN, CREATE TABLE, schema change, migration conflict.
|
||||
---
|
||||
|
||||
# Database Migrations Guide
|
||||
|
||||
@@ -69,6 +69,5 @@ Use `.github/PULL_REQUEST_TEMPLATE.md` as the body structure. Key sections:
|
||||
|
||||
## Notes
|
||||
|
||||
- **Release impact**: PR titles with `✨ feat/` or `🐛 fix` trigger releases — use carefully
|
||||
- **Language**: All PR content must be in English
|
||||
- If a PR already exists for the branch, inform the user instead of creating a duplicate
|
||||
|
||||
3
.github/CODEOWNERS
vendored
Normal file
3
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Database migrations require approval from core maintainers
|
||||
|
||||
/packages/database/migrations/ @arvinxx @nekomeowww @tjx666
|
||||
@@ -47,7 +47,6 @@ lobehub/
|
||||
- Git commit messages should prefix with gitmoji
|
||||
- Git branch name format: `username/feat/feature-name`
|
||||
- Use `.github/PULL_REQUEST_TEMPLATE.md` for PR descriptions
|
||||
- PR titles with `✨ feat/` or `🐛 fix` trigger releases
|
||||
|
||||
### Package Management
|
||||
|
||||
|
||||
@@ -90,7 +90,6 @@ Open this URL to develop locally against the production backend (app.lobehub.com
|
||||
- Use rebase for `git pull`
|
||||
- Commit messages: prefix with gitmoji
|
||||
- Branch format: `<type>/<feature-name>`
|
||||
- PR titles with `✨ feat/` or `🐛 fix` trigger releases
|
||||
|
||||
### Package Management
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ lobehub/
|
||||
- Use rebase for `git pull`
|
||||
- Commit messages: prefix with gitmoji
|
||||
- Branch format: `<type>/<feature-name>`
|
||||
- PR titles with `✨ feat/` or `🐛 fix` trigger releases
|
||||
|
||||
### Package Management
|
||||
|
||||
|
||||
@@ -1841,4 +1841,20 @@ export class MessageModel {
|
||||
if (!!threadId) return eq(messages.threadId, threadId);
|
||||
return isNull(messages.threadId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check which user IDs from the given list have at least one message.
|
||||
*/
|
||||
static checkUsersHaveMessages = async (
|
||||
db: LobeChatDatabase,
|
||||
userIds: string[],
|
||||
): Promise<Set<string>> => {
|
||||
if (userIds.length === 0) return new Set();
|
||||
const result = await db
|
||||
.select({ userId: messages.userId })
|
||||
.from(messages)
|
||||
.where(inArray(messages.userId, userIds))
|
||||
.groupBy(messages.userId);
|
||||
return new Set(result.map((r) => r.userId));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -294,6 +294,11 @@ export class UserModel {
|
||||
return db.query.users.findFirst({ where: eq(users.email, email) });
|
||||
};
|
||||
|
||||
static findByIds = async (db: LobeChatDatabase, ids: string[]) => {
|
||||
if (ids.length === 0) return [];
|
||||
return db.query.users.findMany({ where: inArray(users.id, ids) });
|
||||
};
|
||||
|
||||
static getUserApiKeys = async (
|
||||
db: LobeChatDatabase,
|
||||
id: string,
|
||||
|
||||
Reference in New Issue
Block a user