Skip to content

👷 build(database): add document history schema#13789

Merged
Innei merged 5 commits into
mainfrom
feat/document-history-db
Apr 16, 2026
Merged

👷 build(database): add document history schema#13789
Innei merged 5 commits into
mainfrom
feat/document-history-db

Conversation

@Innei

@Innei Innei commented Apr 13, 2026

Copy link
Copy Markdown
Member

💻 Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 👷 build
  • ⚡️ perf
  • ✅ test
  • 📝 docs
  • 🔨 chore

🔗 Related Issue

  • None

🔀 Description of Change

  • Extract the document history database changes from the feature branch onto a branch based on main.
  • Add the document history migration, schema, relations, model, and database tests only.
  • Exclude UI, router, and service-layer changes so the PR stays focused on the database layer.

🧪 How to Test

  • Run: cd packages/database && bunx vitest run --silent=passed-only src/models/tests/document.test.ts src/models/tests/documentHistory.test.ts
  • Tested locally
  • Added or updated tests
  • No tests needed

📸 Screenshots / Videos

Before After
N/A N/A

📝 Additional Information

  • This PR intentionally targets main because the database migration needs to land on the release branch first.

Copilot AI review requested due to automatic review settings April 13, 2026 16:07
@vercel

vercel Bot commented Apr 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 16, 2026 9:12am

Request Review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3eef044ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/database/src/models/documentHistory.ts
Comment thread packages/database/src/models/documentHistory.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the database-layer foundation for document versioning and per-document history tracking, including the schema/migration, Drizzle relations, model access layer, and accompanying database tests.

Changes:

  • Adds a new document_histories table (schema + relations) and a corresponding DocumentHistoryModel.
  • Adds a version column to documents (schema + migration) and threads it through DocumentModel reads.
  • Adds Vitest coverage for document history CRUD/pagination behavior and document version defaults.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/database/src/schemas/relations.ts Wires documentsdocument_histories relations for ORM querying.
packages/database/src/schemas/index.ts Exposes the new documentHistory schema from the schemas barrel export.
packages/database/src/schemas/file.ts Adds documents.version with a default of 1.
packages/database/src/schemas/documentHistory.ts Defines the document_histories table + indexes and inferred types.
packages/database/src/models/documentHistory.ts Implements DB operations for creating/querying/deleting document history rows.
packages/database/src/models/document.ts Includes version in list/query mapping for documents.
packages/database/src/models/tests/documentHistory.test.ts Adds tests for history creation, uniqueness, ordering/pagination, and user scoping.
packages/database/src/models/tests/document.test.ts Extends document tests to assert the new version default and adjusts cleanup.
packages/database/migrations/meta/_journal.json Registers the new migration in Drizzle’s migration journal.
packages/database/migrations/0098_add_document_history.sql Creates document_histories and adds documents.version with defaults/constraints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/database/src/models/documentHistory.ts Outdated
Comment thread packages/database/migrations/meta/_journal.json
@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.56%. Comparing base (9088a07) to head (7c8f721).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13789      +/-   ##
==========================================
+ Coverage   66.55%   66.56%   +0.01%     
==========================================
  Files        2023     2024       +1     
  Lines      170857   170947      +90     
  Branches    20591    20602      +11     
==========================================
+ Hits       113708   113788      +80     
- Misses      57025    57035      +10     
  Partials      124      124              
Flag Coverage Δ
app 58.55% <ø> (-0.01%) ⬇️
database 92.66% <93.33%> (+<0.01%) ⬆️
packages/agent-runtime 79.72% <ø> (ø)
packages/context-engine 83.33% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.86% <ø> (ø)
packages/model-runtime 84.29% <ø> (ø)
packages/prompts 70.05% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.14% <ø> (ø)
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 65.79% <ø> (ø)
Services 52.12% <ø> (ø)
Server 66.34% <ø> (-0.01%) ⬇️
Libs 52.82% <ø> (ø)
Utils 91.01% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Introduced a new `document_histories` table to track changes made to documents, including fields for `editor_data`, `save_source`, and `saved_at`.
- Updated foreign key relationships to link `document_histories` with `documents` and `users`.
- Modified existing models and tests to accommodate the new document history functionality, including changes to pagination and retrieval methods.
- Removed the versioning system from documents in favor of a more flexible history tracking approach.

Signed-off-by: Innei <tukon479@gmail.com>
…-pdf/svg

Picked from canary commit 9f61b58.
- Bump @react-pdf/renderer from ^4.3.2 to 4.4.1
- Pin @react-pdf/image to 3.0.4 via pnpm.overrides
Comment thread packages/database/src/schemas/documentHistory.ts Outdated
Comment thread packages/database/src/schemas/documentHistory.ts Outdated
@Innei Innei merged commit c1174d3 into main Apr 16, 2026
31 checks passed
@Innei Innei deleted the feat/document-history-db branch April 16, 2026 11:26
canisminor1990 added a commit that referenced this pull request Apr 16, 2026
# 🚀 LobeHub v2.1.50 (20260416)

**Release Date:** April 16, 2026\
**Since v2.1.49:** 107 commits · 101 merged PRs · 13 contributors

> This weekly release focuses on improving runtime stability and gateway
execution consistency, while making Home/Recents workflows faster to
navigate and easier to manage in daily use.

---

## ✨ Highlights

- **Server-side Human Approval Flow** — Agent runtime now supports more
reliable approve/reject/reject-continue handling in gateway mode,
reducing stalled execution paths in long-running tasks. (#13829, #13863,
#13873)

- **Message Gateway End-to-End Hardening** — Gateway message flow, queue
handling, tool callback routing, and stop interruption behavior were
strengthened for better execution continuity. (#13761, #13816, #13820,
#13815)

- **Client Tool Execution in Gateway Mode** — Client-executor tools now
run more predictably across gateway and desktop callers, with improved
executor dispatch behavior. (#13792, #13790)

- **Home / Recents / Sidebar Upgrade** — Sidebar layout, custom sort,
recents operations, and profile actions were improved to reduce
navigation friction in active sessions. (#13719, #13812, #13723, #13739,
#13878, #13734)

- **Agent Workspace and Documents Expansion** — Working panel and agent
document workflows were expanded and polished for better day-to-day
agent operations. (#13766, #13857)

- **Provider and Model Compatibility Improvements** — Added GLM-5.1
support and refined model/provider edge-case handling, including schema
and error-path fixes. (#13757, #13806, #13736, #13740)

---

## 🏗️ Core Agent & Architecture

### Agent runtime and intervention lifecycle

- Added server-side human approval and improved runtime coordination
across approve/reject decision paths. (#13829, #13863)
- Improved interrupted-task handling and operation lifecycle consistency
to reduce half-finished runtime states. (#13714)
- Refined error classification and payload propagation so downstream
surfaces receive clearer actionable errors. (#13736, #13740)

### Execution model and dispatch behavior

- Introduced executor-aware runtime behavior to better separate
client/server tool execution semantics. (#13758)
- Improved tool/plugin resolution and manifest handling to avoid runtime
failures on malformed inputs. (#13856, #13840, #13807)

---

## 📱 Gateway & Platform Integrations

- Added message gateway support and strengthened queue/error behavior
for more stable cross-channel execution. (#13761, #13816, #13820)
- Improved gateway callback pipeline with protocol and API additions for
`tool_execute` / `tool_result`. (#13762, #13764, #13765)
- Improved bot/channel reliability and DM/slash handling in
Discord-related paths. (#13805, #13724)

---

## 🖥️ CLI & User Experience

- Improved CLI reliability across message/topic operations and
build/minify-related paths. (#13731, #13888)
- Added image-to-video options and improved command behavior for
generation workflows. (#13788)
- Improved desktop runtime behavior for remote fetch and Linux
notification urgency handling. (#13789, #13782)

---

## 🔧 Tooling

- Extracted gateway stream client into `@lobechat/agent-gateway-client`
to centralize protocol usage and reduce duplication. (#13866)
- Improved built-in tool coverage and runtime support, including GTD
server runtime and missing lobe-kb tools. (#13854, #13876)
- Updated skill and frontmatter consistency in workflow tooling.
(#13730)

---

## 🔒 Security & Reliability

- **Security:** Strengthened API key WS auth behavior and safer
serverUrl forwarding in gateway-related auth paths. (#13824)
- **Reliability:** Reduced runtime stalls by improving gateway
stop/interrupt and approval-state routing behavior. (#13815, #13863,
#13873)
- **Reliability:** Added defensive guards for malformed tool manifests
and non-string content edge cases. (#13856, #13753)

---

## 👥 Contributors

**101 merged PRs** from **13 contributors** across **107 commits**.

### Community Contributors

- @arvinxx - Runtime, gateway, and execution reliability improvements
- @Innei - Navigation, workflow UX, and desktop/CLI refinements
- @rdmclin2 - Sidebar, recents, and channel behavior updates
- @ONLY-yours - Tooling/runtime fixes and model execution compatibility
- @tjx666 - Model support and release/tooling maintenance
- @nekomeowww - Memory and search-path stability fixes
- @cy948 - CLI indexing and command flow fixes
- @octo-patch - Local system runtime edge-case fixes
- @djthread - Desktop runtime request reliability improvements
- @rivertwilight - Documentation and changelog updates
- @sudongyuer - Subscription/mobile support improvements
- @Zhouguanyang - Provider/model configuration correctness fixes
- @lobehubbot - Translation and maintenance automation support

---

**Full Changelog**: v2.1.49...v2.1.50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants