Skip to content

πŸ—ƒοΈ build(database): add workspace_id FK constraints#15465

Merged
arvinxx merged 3 commits into
canaryfrom
lobe-9960-phase-2-add-workspace-id-fk
Jun 4, 2026
Merged

πŸ—ƒοΈ build(database): add workspace_id FK constraints#15465
arvinxx merged 3 commits into
canaryfrom
lobe-9960-phase-2-add-workspace-id-fk

Conversation

@arvinxx

@arvinxx arvinxx commented Jun 4, 2026

Copy link
Copy Markdown
Member

πŸ’» Change Type

  • πŸ—ƒοΈ db / migration

πŸ”— Related Issue

Part of LOBE-9957 Β· Closes LOBE-9960 (Phase 2)

πŸ”€ Description of Change

Phase 2 of the workspace_id rollout. Phase 1 (0106) added bare nullable workspace_id columns to 70 tables; this PR adds the foreign-key constraint referencing workspaces(id) ON DELETE CASCADE.

Schema β€” added .references(() => workspaces.id, { onDelete: 'cascade' }) to all 70 nullable workspace_id columns (the 3 workspace_* tables that already own a notNull FK are untouched).

Two migration artifacts (intentionally split):

File Role Form
0107_add_workspace_id_fk.sql In journal; runs via drizzle in CI / dev / self-host Idempotent: DROP CONSTRAINT IF EXISTS + ADD CONSTRAINT Γ—70
0107_concurrent.sql Not in journal; manual production runbook NOT VALID (fast, brief lock) + VALIDATE (no DML block) Γ—70

Why two files: drizzle runs every migration inside a single transaction, where the value of NOT VALID + out-of-transaction VALIDATE is lost (locks held until COMMIT, no low-peak phasing). So the online-safe path is run by hand, out of band, on production. 0107_concurrent.sql carries a full operating runbook in its header, including marking 0107 as already-applied in drizzle.__drizzle_migrations afterwards so the drizzle migrator skips the heavy DDL.

πŸ’‘ Follow-up (not in this PR): a config-driven EXTERNAL_MIGRATIONS registry + generic seeder in scripts/migrateServerDB to automate the "mark-as-applied" bookkeeping for out-of-band migrations.

πŸ§ͺ How to Test

  • bun run db:generate reports No schema changes (schema ↔ snapshot in sync)
  • tsc on packages/database schemas passes
  • Migration contains exactly 70 idempotent FK additions, no unrelated DDL

πŸ“ Additional Information

workspace_id is 100% NULL today, so VALIDATE is effectively a no-op scan; the online path is a safeguard for the large tables (messages, message_chunks, generations, files) at production scale.

Phase 2 of workspace_id rollout: add the FK constraint on the 70 tables
that gained a bare `workspace_id` column in Phase 1 (0106), referencing
workspaces(id) ON DELETE CASCADE.

- schema: add `.references(() => workspaces.id, { onDelete: 'cascade' })`
  to all 70 nullable workspace_id columns
- 0107_add_workspace_id_fk.sql: idempotent drizzle migration
  (DROP CONSTRAINT IF EXISTS + ADD), runs in CI / dev / self-host
- 0107_concurrent.sql: production-safe out-of-band runbook
  (NOT VALID + VALIDATE) to avoid write-blocking locks on large tables;
  NOT run by drizzle

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arvinxx arvinxx requested review from nekomeowww and tjx666 as code owners June 4, 2026 07:32
@vercel

vercel Bot commented Jun 4, 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 Jun 4, 2026 8:20am

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.

Sorry @arvinxx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jun 4, 2026
@arvinxx arvinxx changed the title πŸ—ƒοΈ db(database): add workspace_id FK constraints (migration 0107) πŸ—ƒοΈ db(database): add workspace_id FK constraints Jun 4, 2026
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 70.85%. Comparing base (475f391) to head (376053e).

Additional details and impacted files
@@           Coverage Diff            @@
##           canary   #15465    +/-   ##
========================================
  Coverage   70.84%   70.85%            
========================================
  Files        3253     3253            
  Lines      320646   320646            
  Branches    34000    34949   +949     
========================================
+ Hits       227177   227184     +7     
+ Misses      93288    93281     -7     
  Partials      181      181            
Flag Coverage Ξ”
app 61.50% <ΓΈ> (ΓΈ)
database 92.50% <ΓΈ> (ΓΈ)
packages/agent-manager-runtime 49.69% <ΓΈ> (ΓΈ)
packages/agent-runtime 80.48% <ΓΈ> (ΓΈ)
packages/builtin-tool-lobe-agent 18.52% <ΓΈ> (ΓΈ)
packages/context-engine 84.17% <ΓΈ> (ΓΈ)
packages/conversation-flow 91.29% <ΓΈ> (ΓΈ)
packages/device-gateway-client 89.68% <ΓΈ> (ΓΈ)
packages/eval-dataset-parser 95.15% <ΓΈ> (ΓΈ)
packages/eval-rubric 76.11% <ΓΈ> (ΓΈ)
packages/fetch-sse 87.28% <ΓΈ> (+1.71%) ⬆️
packages/file-loaders 87.89% <ΓΈ> (ΓΈ)
packages/memory-user-memory 74.99% <ΓΈ> (ΓΈ)
packages/model-bank 99.99% <ΓΈ> (ΓΈ)
packages/model-runtime 84.51% <ΓΈ> (ΓΈ)
packages/prompts 72.51% <ΓΈ> (ΓΈ)
packages/python-interpreter 92.90% <ΓΈ> (ΓΈ)
packages/ssrf-safe-fetch 0.00% <ΓΈ> (ΓΈ)
packages/types 35.34% <ΓΈ> (ΓΈ)
packages/utils 88.77% <ΓΈ> (ΓΈ)
packages/web-crawler 88.08% <ΓΈ> (ΓΈ)

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

Components Coverage Ξ”
Store 68.47% <ΓΈ> (ΓΈ)
Services 54.57% <ΓΈ> (ΓΈ)
Server 71.84% <ΓΈ> (ΓΈ)
Libs 57.01% <ΓΈ> (ΓΈ)
Utils 81.44% <ΓΈ> (ΓΈ)
πŸš€ 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.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 4, 2026
Move userInstalledPlugins from user.ts into connector.ts to break the
user.ts <-> workspace.ts import cycle flagged by dpdm. connector.ts
already imports both users and workspaces, and consumers import the
table from the schemas barrel, so no call sites change.
@arvinxx arvinxx changed the title πŸ—ƒοΈ db(database): add workspace_id FK constraints πŸ—ƒοΈ build(database): add workspace_id FK constraints Jun 4, 2026
@arvinxx arvinxx merged commit 1e2c1aa into canary Jun 4, 2026
35 checks passed
@arvinxx arvinxx deleted the lobe-9960-phase-2-add-workspace-id-fk branch June 4, 2026 08:23
arvinxx added a commit that referenced this pull request Jun 10, 2026
# πŸš€ LobeHub Release (20260610)

**Release Date:** June 10, 2026  
**Since v2.2.2:** 131 merged PRs Β· 13 contributors

> This weekly release strengthens agent collaboration across cloud,
desktop, CLI, and workspace flows, with steadier runtime behavior and a
broader foundation for workspace-scoped data.

---

## ✨ Highlights

- **Agent execution across devices** β€” Unifies per-device working
directories, project skill discovery, and sub-agent suspend/resume
behavior across server, QStash, and device RPC flows. (#15543, #15566,
#15481, #15620, #15591)
- **Connector and sandbox platform** β€” Expands connector permissions,
custom OAuth MCP connector onboarding, sandbox provider support, and
user-uploaded file sync into cloud sandbox runs. (#15463, #15546,
#15184, #15550)
- **Desktop and CLI reliability** β€” Fixes desktop cold-start,
auto-update, Windows build, CLI skill discovery, and `lh connect` agent
dispatch paths. (#15547, #15525, #15527, #15562, #15632, #15634)
- **Pages and sharing** β€” Refreshes topic sharing, improves Page Editor
layout behavior, and routes Page Agent tool execution through the
server-side editor path. (#15581, #15556, #15588, #15023, #15610)
- **Model availability and provider updates** β€” Adds user-scoped LobeHub
model availability, Claude Fable 5, Qwen thinking preservation, and
MiniMax M3 updates. (#15590, #15639, #13494, #15376)

---

## πŸ—οΈ Core Product & Architecture

### Agent Runtime & Heterogeneous Agents

- Improves sub-agent lifecycle handling, including async suspend/resume,
queue-mode QStash resume delivery, and blocking nested sub-agent calls.
(#15481, #15620, #15575)
- Stabilizes heterogeneous agent ingestion and streaming with raw stream
dumps, per-turn usage, image forwarding on regenerate, and
duplicate-text fixes. (#15602, #15577, #15592, #15585)
- Adds execution-device and working-directory controls across device
RPC, legacy defaults, and remote-spawned Claude Code sessions. (#15543,
#15566, #15591, #15572)
- Improves runtime diagnostics and compatibility, including Gemini
multimodal output capture, abort stream semantics, and trace quality
analysis. (#15535, #13677, #15508)

---

## πŸ“± Platforms, Integrations & UX

### Connectors, Sandbox & Tools

- Ships API-level connector tool permissions, custom OAuth MCP connector
onboarding, and connector-first runtime execution. (#15463, #15546)
- Adds sandbox provider support, cloud sandbox file sync, and safer
external URL file input handling with SSRF validation. (#15184, #15550,
#12657)
- Improves tool visibility and execution with pinned app-fixed tools,
ANSI output rendering, gateway-tunneled MCP calls, and automatic
headless tool runs. (#15509, #15516, #15469, #15492)

### Desktop, CLI & Web UX

- Restores desktop startup and reload behavior, preserves IPC error
causes, and keeps the tab bar new-tab action visible across routes.
(#15547, #15597, #15638)
- Fixes desktop update and build stability for browser quit guards,
macOS update signing, and Windows Visual Studio detection. (#15525,
#15527, #15562)
- Shows the plan-limit upgrade UI on desktop builds. (#15628)
- Adds the Agent Run delivery checker and fixes CLI device dispatch plus
skill list/search output. (#15489, #15634, #15632)
- Refreshes onboarding, auth source preservation, topic UI states,
referral/Fable campaign copy, and chat-input control bar behavior.
(#15629, #15544, #15573, #15614, #15616, #15617, #15622, #15643)

---

## πŸ”’ Security, Reliability & Rollout Notes

- External URL file input now includes SSRF validation for safer Google
file handling. (#12657)
- Database workspace-scope migrations are part of this release;
self-hosted operators should run the normal migration path before
serving the updated app. (#15446, #15465, #15468, #15472)
- The release branch was re-cut from `canary` and includes the latest
`main` release-version commit so `v2.2.2` is the verified compare base.

---

## πŸ‘₯ Contributors

@ONLY-yours, @sxjeru, @hardy-one, @xujingli, @hezhijie0327, @Coooolfan,
@arvinxx, @tjx666, @Innei, @rivertwilight, @rdmclin2, @cy948,
@AmAzing129

**Full Changelog**:
v2.2.2...release/weekly-20260610-recut-3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant