Skip to content

Conversation

@bealers
Copy link
Contributor

@bealers bealers commented Jun 25, 2025

fix(plugin-sql): Fix database schema type mismatch for server_agents foreign key constraint

  • Change serverAgent.serverId from uuid to text type
  • Fixes foreign key constraint error preventing database initialization
  • Resolves issue where server_agents table could not be created
  • Maintains backward compatibility with existing UUID values

Relates to

Fixes critical database initialization bug affecting all fresh ElizaOS deployments

Risks

Low risk - This is a targeted schema fix with minimal impact:

  • Only changes data type definition in schema file
  • Maintains backward compatibility (UUID strings work as TEXT)
  • No breaking changes to existing APIs
  • Extensively tested with fresh database initialization

Background

What does this PR do?

Fixes a critical database schema type mismatch that prevents the server_agents table from being created during fresh ElizaOS installations. Changes the serverId field type from uuid to text to match the referenced message_servers.id field type.

What kind of change is this?

Bug fixes (non-breaking change which fixes an issue)

Documentation changes needed?

My changes do not require a change to the project documentation.

Testing

Where should a reviewer start?

Review the single file change in packages/plugin-sql/src/schema/serverAgent.ts - it's a simple type change from uuid to text.

Detailed testing steps

  • Built ElizaOS from source with bun install && bun run build
  • Created fresh test project with elizaos create test-schema-fix -y
  • Removed existing database: rm -rf .eliza/.elizadb
  • Started ElizaOS with fresh database initialization
  • Verified successful table creation in logs:
    [2025-06-25 15:03:10] INFO: Created table: server_agents
    [2025-06-25 15:03:10] INFO: All plugin migrations completed.
    
  • Confirmed agent initialization and server startup successful
  • Verified foreign key constraint now works without errors

Screenshots

Before

Database initialization would fail with:

ERROR: foreign key constraint "server_agents_server_id_fkey" cannot be implemented
DETAIL: Key columns "server_id" and "id" are of incompatible types: uuid and text.

After

[2025-06-25 15:03:10] INFO: Created table: server_agents
[2025-06-25 15:03:10] INFO: All plugin migrations completed.
[2025-06-25 15:03:11] INFO: AgentServer is listening on port 3001

Database changes

Schema change only - no data migration required:

  • packages/plugin-sql/src/schema/serverAgent.ts: Changed serverId field from uuid('server_id') to text('server_id')
  • This aligns with messageServerTable.id which is defined as text
  • Existing UUID values continue to work seamlessly as text values

Discord username

bealers

…foreign key constraint

- Change serverAgent.serverId from uuid to text type
- Fixes foreign key constraint error preventing database initialization
- Resolves issue where server_agents table could not be created
- Maintains backward compatibility with existing UUID values
@graphite-app
Copy link

graphite-app bot commented Jun 25, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • merge-queue-hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@0xbbjoker
Copy link
Collaborator

@bealers can you please elaborate what is the issue with using UUID?

@bealers
Copy link
Contributor Author

bealers commented Jun 26, 2025

@0xbbjoker I noticed a sql error on database creation when I was debugging some of my own work. This fix just allows the database to create OK. UUID seems the better option tbh. but seemed a larger fix

@0xbbjoker
Copy link
Collaborator

@bealers text for ids not so good and as we use pg databases ids should be uuid.

@0xbbjoker
Copy link
Collaborator

0xbbjoker commented Jun 26, 2025

@bealers can you give steps to reproduce this? Might be that other tables need change from text to uuid actually.

@bealers
Copy link
Contributor Author

bealers commented Jun 26, 2025

Hi, fair re: UUID, and you're right, the better option is prob fix the relationship the other direction.

I've been playing with docker-compose deployments using postgres, and kept getting database errors in the logs. To reproduce basically, elizaos startand when the database is created, there's a broken relationship.

serverAgent.server_id is UUID
messageServerTable.id is TEXT

Ah, one other thing. You only notice this in PROD (which is what I was testing), in dev the error is suppressed

@bealers
Copy link
Contributor Author

bealers commented Jun 26, 2025

@0xbbjoker maybe I should have just reported a bug next time, I got carried away trying to fix my stuff

@0xbbjoker
Copy link
Collaborator

@bealers no no, all good. Just trying to figure out what's the exact issue.

Can you change messageServerTable.id is TEXT to uuid and PR this?

I guess it's much better to have uuid for postgres. What do you say about that?

@bealers
Copy link
Contributor Author

bealers commented Jun 26, 2025

Sure, NP. I'll do that and re-submit

@bealers bealers force-pushed the fix/database-schema-server-agents-foreign-key branch from f42b099 to 2303399 Compare June 26, 2025 13:04
@bealers bealers force-pushed the fix/database-schema-server-agents-foreign-key branch from cee005b to 084400d Compare June 26, 2025 13:23
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.

3 participants