✨ feat(db): add agent share schema and model#15430
Conversation
- New `agent_shares` table: one share record per agent, stores visibility, guestEnabled, tipSplitRatio, and file-permission config - Extend `topics` with shareId / guestToken / visitorUserId columns to support guest-originated conversations owned by the creator - Add AgentShareModel with create/update/delete and public findByShareId helpers (mirrors TopicShareModel pattern) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…op userId/pageViewCount - Remove userId (derivable via agent.userId), guestEnabled, tipSplitRatio, filePermissionConfig, pageViewCount from agent_shares - Add shareConfig jsonb with AgentShareConfig interface covering all share settings (guestEnabled, maxGuestTopics, tipSplitRatio, etc.) - Update AgentShareModel: ownership checks via agents join, findByShareId now returns creatorId from agents.userId, remove incrementPageViewCount - Regenerate 0105 migration (clean diff against 0104 baseline) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26d66585d9
ℹ️ 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".
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## canary #15430 +/- ##
==========================================
- Coverage 71.02% 64.18% -6.84%
==========================================
Files 3212 2679 -533
Lines 321285 241619 -79666
Branches 29240 23781 -5459
==========================================
- Hits 228179 155086 -73093
+ Misses 92931 86415 -6516
+ Partials 175 118 -57
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
… drop legacy share columns - agent_shares: add userViewCount (UV), remove tipSplitRatio from AgentShareConfig - topics: replace shareId/guestToken/visitorUserId with single senderId column; guest=UUID, post-login=userId, app layer overwrites on bind - AgentShareModel: add incrementUserViewCount, expose userViewCount in findByShareId - Regenerate 0105_add_agent_share migration (clean diff vs 0104) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wrap CREATE TABLE with IF NOT EXISTS, ALTER TABLE ADD COLUMN with IF NOT EXISTS, FK constraints with DO $$ BEGIN...EXCEPTION WHEN duplicate_object THEN NULL; END $$, and indexes with IF NOT EXISTS. Mirrors pattern used in 0069_add_topic_shares_table.sql. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bring the agent-share schema layer over from #15430: new `agent_shares` table + `topics.sender_id` column/index, schema relations and barrel export. Migration renumbered to 0106 to sit after the usage column. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bring the agent-share schema layer over from #15430: new `agent_shares` table + `topics.sender_id` column/index, schema relations and barrel export. Migration renumbered to 0106 to sit after the usage column. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* ✨ feat(db): add usage column to messages table Promote token usage/cost out of `metadata.usage` into a dedicated `messages.usage` jsonb column, with btree expression indexes on `usage.cost` and `usage.totalTokens`. Additive only — no data backfill; `metadata.usage` stays the source of truth during the transition. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * ✨ feat(db): add agent share schema (picked from #15430) Bring the agent-share schema layer over from #15430: new `agent_shares` table + `topics.sender_id` column/index, schema relations and barrel export. Migration renumbered to 0106 to sit after the usage column. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * ✨ feat(db): add workspace schema (picked from #15414) Bring over only the standalone `workspace.ts` schema from #15414 — the workspaces / workspace_members / workspace_invitations / workspace_audit_logs tables (self-contained, FK to users only). None of #15414's workspaceId column additions across other tables are included. Migration is 0108-safe, renumbered to 0107. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * 🗃️ chore(db): squash usage/agent-share/workspace into one migration Collapse the three stacked migrations (0105 usage, 0106 agent_share, 0107 workspace) into a single idempotent 0105_add_usage_agent_share_workspace. Schema source is unchanged; only the migration files/snapshot/journal are consolidated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * ✅ test(db): add senderId to expected topic shape in create test The picked agent-share schema added topics.senderId, so the created row now returns it; update the two toEqual assertions accordingly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Summary
agent_sharestable: one share per agent,shareConfig jsonbfor all share settings (guestEnabled, maxGuestTopics, tipSplitRatio, filePermissionConfig, etc.)topicstable with 3 columns:shareId,guestToken,visitorUserIdAgentShareModelwith ownership-via-agents-join pattern;findByShareIdreturnscreatorIdfromagents.userIdtopics WHERE share_id=$x AND guest_token=$y AND trigger='share'— no dedicated table neededDesign decisions
No
userIdinagent_shares: creator identity derivable viaagents.userId, no redundancy needed.shareConfig jsonbnot multiple columns: share config is extensible (upcoming: maxGuestTopics, allowReadMemory, accessControl). jsonb avoids repeated ALTER TABLE.No FK on
shareIdintopics: share deletion must not cascade-delete conversations.Test plan
AgentShareModel.create()— idempotent (unique constraint onagentId)AgentShareModel.findByShareIdWithAccessCheck()— throws FORBIDDEN for private shares0105_add_agent_share.sqlapplies cleanlyLinear: LOBE-9941
🤖 Generated with Claude Code