Skip to content

👷 build(database): improve user memory schema#9822

Merged
arvinxx merged 1 commit into
lobehub:mainfrom
nekomeowww:dev/memory-database-update
Oct 28, 2025
Merged

👷 build(database): improve user memory schema#9822
arvinxx merged 1 commit into
lobehub:mainfrom
nekomeowww:dev/memory-database-update

Conversation

@nekomeowww

@nekomeowww nekomeowww commented Oct 21, 2025

Copy link
Copy Markdown
Member

💻 Change Type

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

🔀 Description of Change

  • We need episodic date related columns for user_memories_identity.
  • We need labels and extracted_labels for base user_memories.
  • context_id, experience, and current_focuses wasn't needed.

📝 Additional Information

Summary by Sourcery

Refactor the database schema for user memories by introducing new metadata fields and removing obsolete columns and constraints.

Enhancements:

  • Add JSONB columns labels and extracted_labels to the user_memories table
  • Add episodic_date timestamp column to the user_memories_identities table
  • Remove context_id column and its foreign key constraint from user_memories_preferences
  • Remove current_focuses and experience columns from the user_memories_identities table

@vercel

vercel Bot commented Oct 21, 2025

Copy link
Copy Markdown

@nekomeowww is attempting to deploy a commit to the LobeHub Community Team on Vercel.

A member of the Team first needs to authorize it.

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2025

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors the user memories schema by introducing JSONB label fields, adding an episodic date to identities, removing obsolete context and focus columns, and synchronizing migrations and documentation.

Entity Relationship diagram for updated user memories schema

erDiagram
  USERS ||--o{ USER_MEMORIES : "has"
  USER_MEMORIES ||--o{ USER_MEMORIES_IDENTITIES : "has"
  USER_MEMORIES ||--o{ USER_MEMORIES_PREFERENCES : "has"

  USER_MEMORIES {
    text userId
    jsonb labels
    jsonb extractedLabels
    varchar255 memoryCategory
    varchar255 memoryLayer
    varchar255 memoryType
  }

  USER_MEMORIES_IDENTITIES {
    varchar255 id
    text userMemoryId
    jsonb labels
    jsonb extractedLabels
    varchar255 type
    text description
    vector descriptionVector
    timestamptz episodicDate
    text relationship
    text role
  }

  USER_MEMORIES_PREFERENCES {
    varchar255 id
    text userMemoryId
  }
Loading

Class diagram for updated user memories schema types

classDiagram
  class UserMemories {
    +text userId
    +jsonb labels
    +jsonb extractedLabels
    +varchar255 memoryCategory
    +varchar255 memoryLayer
    +varchar255 memoryType
    // ...
  }

  class UserMemoriesIdentities {
    +varchar255 id
    +text userMemoryId
    +jsonb labels
    +jsonb extractedLabels
    +varchar255 type
    +text description
    +vector descriptionVector
    +timestamptz episodicDate
    +text relationship
    +text role
    // ...
  }

  class UserMemoriesPreferences {
    +varchar255 id
    +text userMemoryId
    // ...
  }

  UserMemories "1" --o "*" UserMemoriesIdentities : has
  UserMemories "1" --o "*" UserMemoriesPreferences : has
Loading

File-Level Changes

Change Details Files
Add labels and extracted_labels columns to user_memories
  • Introduce jsonb fields labels and extractedLabels in schema
  • Update migration to add these columns
  • Sync DBML to reflect new columns
packages/database/src/schemas/userMemories.ts
packages/database/migrations/0039_goofy_unicorn.sql
docs/development/database-schema.dbml
Remove context_id from user_memories_preferences
  • Drop foreign key constraint on context_id
  • Remove context_id column from schema
  • Update migration to drop this column
packages/database/src/schemas/userMemories.ts
packages/database/migrations/0039_goofy_unicorn.sql
Refactor user_memories_identities to add episodic_date and labels
  • Remove current_focuses and experience fields
  • Add labels, extractedLabels, and episodicDate columns
  • Reorder fields for clarity and consistency
packages/database/src/schemas/userMemories.ts
packages/database/migrations/0039_goofy_unicorn.sql
Update migration metadata and snapshots
  • Add new SQL migration script to journal
  • Update core migrations manifest
  • Generate updated migration snapshot
packages/database/migrations/meta/_journal.json
packages/database/src/core/migrations.json
packages/database/migrations/meta/0039_snapshot.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gru-agent

gru-agent Bot commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

TestGru Assignment

Summary

Link CommitId Status Reason
Detail c9e5b538c14809b7fb8069cfb3033cea92dfab9b 🚫 Skipped No files need to be tested {".vscode/settings.json":"File path does not match include patterns.","docs/development/database-schema.dbml":"File path does not match include patterns.","packages/database/migrations/0039_goofy_unicorn.sql":"File path does not match include patterns.","packages/database/migrations/meta/0039_snapshot.json":"File path does not match include patterns.","packages/database/migrations/meta/_journal.json":"File path does not match include patterns.","packages/database/src/core/migrations.json":"The code does not contain any functions or classes.","packages/database/src/schemas/userMemories.ts":"Can not find valuable test target.\nuserMemories: Out of scope - This export is a database table definition with no logic or exported functions/classes; it is not suitable for unit testing.\nuserMemoriesContexts: Out of scope - This export is a database table definition with no logic or exported functions/classes; it is not suitable fo…"}

History Assignment

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 21, 2025
@lobehubbot

Copy link
Copy Markdown
Member

👍 @nekomeowww

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.

@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.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `packages/database/src/schemas/userMemories.ts:16-19` </location>
<code_context>

     userId: text('user_id').references(() => users.id, { onDelete: 'cascade' }),

+    labels: jsonb('labels'),
+    extractedLabels: jsonb('extracted_labels'),
+
     memoryCategory: varchar255('memory_category'),
</code_context>

<issue_to_address>
**suggestion:** Consider clarifying the distinction between 'labels' and 'extractedLabels'.

Since both columns store label data, please clarify their distinct roles in code and documentation to prevent confusion and potential data integrity issues.

```suggestion
    /**
     * 'labels' stores user-assigned labels for the memory.
     * These are manually added or edited by the user to categorize or tag the memory.
     */
    labels: jsonb('labels'),

    /**
     * 'extractedLabels' stores labels automatically extracted from the memory content.
     * These are generated by the system (e.g., via NLP or ML) and may differ from user-assigned labels.
     */
    extractedLabels: jsonb('extracted_labels'),

```
</issue_to_address>

### Comment 2
<location> `packages/database/migrations/0039_goofy_unicorn.sql:1` </location>
<code_context>
+ALTER TABLE "user_memories_preferences" DROP CONSTRAINT "user_memories_preferences_context_id_user_memories_contexts_id_fk";
+--> statement-breakpoint
+ALTER TABLE "user_memories" ADD COLUMN "labels" jsonb;--> statement-breakpoint
</code_context>

<issue_to_address>
**issue (bug_risk):** Dropping foreign key constraints can lead to orphaned records.

If this change is intentional, please ensure there are mechanisms in place to prevent or clean up orphaned 'user_memories_preferences' records.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread packages/database/src/schemas/userMemories.ts
@codecov

codecov Bot commented Oct 21, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.51%. Comparing base (4684ee7) to head (c709a03).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #9822     +/-   ##
=========================================
  Coverage   84.51%   84.51%             
=========================================
  Files         945      945             
  Lines       64967    64967             
  Branches     7974     9673   +1699     
=========================================
  Hits        54905    54905             
  Misses      10062    10062             
Flag Coverage Δ
app 80.08% <ø> (ø)
database 98.40% <ø> (ø)
packages/agent-runtime 98.37% <ø> (ø)
packages/context-engine 93.58% <ø> (ø)
packages/electron-server-ipc 93.76% <ø> (ø)
packages/file-loaders 92.21% <ø> (ø)
packages/model-bank 100.00% <ø> (ø)
packages/model-runtime 92.18% <ø> (ø)
packages/prompts 77.29% <ø> (ø)
packages/python-interpreter 96.50% <ø> (ø)
packages/utils 94.50% <ø> (ø)
packages/web-crawler 97.07% <ø> (ø)

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

Components Coverage Δ
Store 74.41% <ø> (ø)
Services 61.69% <ø> (ø)
Server 77.39% <ø> (ø)
Libs 50.82% <ø> (ø)
Utils 83.03% <ø> (ø)
🚀 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.

@vercel

vercel Bot commented Oct 22, 2025

Copy link
Copy Markdown

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

Project Deployment Preview Comments Updated (UTC)
lobehub-database Ready Ready Preview Comment Oct 28, 2025 6:11am
lobehub-lite Ready Ready Preview Comment Oct 28, 2025 6:11am

Comment thread packages/database/src/schemas/userMemories.ts Outdated
Comment thread packages/database/src/schemas/userMemories.ts
Comment thread .vscode/settings.json
Comment thread packages/database/src/schemas/userMemories.ts Outdated
@arvinxx arvinxx changed the title chore(database): improve user memory schema 👷 build(database): improve user memory schema Oct 27, 2025

@arvinxx arvinxx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

另外得 rebase 下 main,知识库那边有个 PR 先合了

Comment thread packages/database/src/schemas/userMemories.ts Outdated
Comment thread packages/database/migrations/0040_improve_user_memory_field.sql Outdated
Comment thread packages/database/migrations/0040_improve_user_memory_field.sql Outdated

@arvinxx arvinxx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm now

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Oct 28, 2025
@arvinxx arvinxx merged commit 6c5caf9 into lobehub:main Oct 28, 2025
69 of 70 checks passed
@lobehubbot

Copy link
Copy Markdown
Member

❤️ Great PR @nekomeowww ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.

@lobehubbot

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.142.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

fleetof pushed a commit to fleetof/diggo-chat-x that referenced this pull request May 13, 2026
chore(database): improve user memory schema
arvinxx added a commit that referenced this pull request Jun 7, 2026
…pdate signing (#15527)

electron-builder was floating on `^26.8.1` and the repo commits no lockfile,
so each CI build resolved a fresh version. The canary.12 build (2026-06-07)
picked up 26.15.0, which regressed macOS .app bundle signing: codesign reports
"bundle format is ambiguous (could be app or framework)" and Squirrel.Mac
rejects the update during code-signature validation, so the app never quits
to install — surfacing as "auto-update does nothing".

26.15.0 introduced the two suspect changes (mac signing rework #9822 and the
full app-builder-bin Go→TS replacement #9829). 26.14.0 predates both and does
not touch macOS app-bundle signing/layout. Pinning the exact version cascades
to app-builder-lib / dmg-builder / builder-util (electron-builder pins those
exactly), stopping the toolchain from floating across CI installs.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer released size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants