Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ”¨ chore: add batch query methods for UserModel and MessageModel (#13060)

YuTengjing3207d1440388
diff --git a/.agents/skills/db-migrations/SKILL.md b/.agents/skills/db-migrations/SKILL.md
index 55b4ef8b71c..ee3589fb6aa 100644
--- a/.agents/skills/db-migrations/SKILL.md
+++ b/.agents/skills/db-migrations/SKILL.md
@@ -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
diff --git a/.agents/skills/pr/SKILL.md b/.agents/skills/pr/SKILL.md
index 41e98a13cca..07f9d452af9 100644
--- a/.agents/skills/pr/SKILL.md
+++ b/.agents/skills/pr/SKILL.md
@@ -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
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 00000000000..4e415e22ee8
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,3 @@
+# Database migrations require approval from core maintainers
+
+/packages/database/migrations/ @arvinxx @nekomeowww @tjx666
diff --git a/AGENTS.md b/AGENTS.md
index 11eda18068d..64b0ced6195 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -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
diff --git a/CLAUDE.md b/CLAUDE.md
index 025c2711b36..aea2d0e54ad 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -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
diff --git a/GEMINI.md b/GEMINI.md
index 7cdcffae2a7..191f16e013b 100644
--- a/GEMINI.md
+++ b/GEMINI.md
@@ -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
diff --git a/packages/database/src/models/message.ts b/packages/database/src/models/message.ts
index 5b69278905d..85d3249a628 100644
--- a/packages/database/src/models/message.ts
+++ b/packages/database/src/models/message.ts
@@ -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));
+ };
}
diff --git a/packages/database/src/models/user.ts b/packages/database/src/models/user.ts
index 9915458ea31..6be739e3f41 100644
--- a/packages/database/src/models/user.ts
+++ b/packages/database/src/models/user.ts
@@ -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,