Skip to content

feat: Exit on database integrity failure - #3740

Merged
exaby73 merged 4 commits into
serverpod:mainfrom
exaby73:feat/exit-on-migrations-not-applied
Jul 11, 2025
Merged

exaby73 merged 4 commits into
serverpod:mainfrom
exaby73:feat/exit-on-migrations-not-applied

Conversation

@exaby73

@exaby73 exaby73 commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

This PR changes the code flow to exit early when encountering a database integity failure to clean up the error messages logged to the user

Closes #3683

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of database integrity verification failures during migrations, providing clearer error logging and proper exit behavior.

@coderabbitai

coderabbitai Bot commented Jul 1, 2025 •

Copy link
Copy Markdown
Contributor

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.

📝 Walkthrough

Walkthrough

The _applyMigrations method in serverpod.dart is updated to check the result of verifyDatabaseIntegrity. If the database integrity check fails, a log message is generated and an ExitException is thrown to terminate the process. The catch block is updated to immediately rethrow ExitException instances.

Changes

File(s) Change Summary
packages/serverpod/lib/src/server/serverpod.dart Enhanced _applyMigrations to check database integrity result, log on failure, and throw ExitException; updated exception handling to rethrow ExitException immediately.

Sequence Diagram(s)

sequenceDiagram
    participant Serverpod
    participant Database

    Serverpod->>Database: verifyDatabaseIntegrity()
    Database-->>Serverpod: true/false

    alt Integrity check passes
        Serverpod->>Serverpod: Continue normal startup
    else Integrity check fails
        Serverpod->>Serverpod: Log failure
        Serverpod->>Serverpod: Throw ExitException
        Serverpod-->>System: Terminate process
    end

    Note over Serverpod: ExitException is rethrown immediately in catch block
Loading

Assessment against linked issues

Objective Addressed Explanation
Stop the server in development mode if database is out of sync, clean up messaging, abort on integrity fail (#3683) ✅

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.


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

@exaby73
exaby73 requested a review from tp July 1, 2025 11:13
@exaby73

exaby73 commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 1, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

1 similar comment
@coderabbitai

coderabbitai Bot commented Jul 1, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@tp
tp requested a review from Isakdl July 1, 2025 13:30
@tp

tp commented Jul 1, 2025

Copy link
Copy Markdown
Contributor

@Isakdl Would value your input here, as I am not that familiar with the migrations and especially the "shut down" / error handling.

Since I've seen the ExitException already in quite a few place already, I suppose there's a pattern behind it, but I could not explain it 😅

or maybe @christerswahn who might also be familiar with it through the shutdown tests etc. :)

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

Had a couple of questions! 👍

@christerswahn

Copy link
Copy Markdown
Contributor

@Isakdl Would value your input here, as I am not that familiar with the migrations and especially the "shut down" / error handling.

Since I've seen the ExitException already in quite a few place already, I suppose there's a pattern behind it, but I could not explain it 😅

or maybe @christerswahn who might also be familiar with it through the shutdown tests etc. :)

It is thrown when it is determined the process should exit immediately, but with orderly cleanup, and with a given exit code. It is assumed the throwing code has produced appropriate output to the user via the terminal, log, or similar.

@exaby73
exaby73 requested review from christerswahn and tp July 8, 2025 06:13

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

Just had one more comment!

@exaby73
exaby73 requested a review from christerswahn July 10, 2025 09:37
@exaby73
exaby73 merged commit 52bf9f2 into serverpod:main Jul 11, 2025
@exaby73
exaby73 deleted the feat/exit-on-migrations-not-applied branch July 11, 2025 08:03
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Starting a new server without applying database tables gives messy output

3 participants