Skip to content

Fix #66: Auto-create database file if it doesn't exist #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2025

Conversation

sumitvekariya
Copy link
Contributor

Auto-create database file if it doesn't exist

Description

This PR fixes issue #66 where the node crashes if the database file hasn't been created before launch.

Changes

  • Added directory creation logic to ensure the database parent directory exists
  • Added automatic migration execution when connecting to the database
  • Added proper error handling and logging for the database initialization process

Impact

With these changes, the node will automatically create the database file and directory structure if they don't exist, then apply the required migrations to set up the database schema. This improves the user experience by eliminating the need for manual database file creation.

Testing

  • Tested with non-existing database file and directory
  • Verified migrations are properly applied to new database
  • Ensured existing database files continue to work as before

Fixes #66

Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution!

Your solution works but I think we should handle this slightly differently following the suggestion here SeaQL/sea-orm#283 (comment). I would propose that you revert the current changes and instead we modify this line to be:

            let path = ctx.config().datadir().db().join("scroll.db?mode=rwc");

This allows for custom database backends to be used via custom config.database_path and provides desired behaviour for default case. Would be great if you can test this out please.

@sumitvekariya
Copy link
Contributor Author

Thank you very much for your contribution!

Your solution works but I think we should handle this slightly differently following the suggestion here SeaQL/sea-orm#283 (comment). I would propose that you revert the current changes and instead we modify this line to be:

            let path = ctx.config().datadir().db().join("scroll.db?mode=rwc");

This allows for custom database backends to be used via custom config.database_path and provides desired behaviour for default case. Would be great if you can test this out please.

Hey udnerstood the (rwc) Read, Write & Create mode for sqlite file creation, reverted my changes and updated with your suggestion, Thanks

Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@frisitano frisitano merged commit f57f3c6 into scroll-tech:main Apr 24, 2025
12 checks passed
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.

[DB] Automatically Create Database File
2 participants