-
Notifications
You must be signed in to change notification settings - Fork 135
refactor(l2): improve SQL store initialization #5479
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the SQL store initialization to make it idempotent by adding IF NOT EXISTS clauses to all CREATE TABLE statements and ON CONFLICT DO NOTHING clauses to INSERT statements. This allows the schema setup to be executed on every startup without requiring manual migrations when new tables are added.
Key changes:
- All
CREATE TABLEstatements now useIF NOT EXISTSto prevent errors on re-execution - Initial
INSERTstatements foroperation_countandlatest_senttables now useON CONFLICT DO NOTHINGto avoid duplicate key errors - Removed the check for existing tables before running schema setup, allowing the idempotent schema statements to run unconditionally
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // "readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently" | ||
| // https://sqlite.org/wal.html#concurrency | ||
| // still a limit of only 1 writer is imposed by sqlite databases | ||
| self.query("PRAGMA journal_mode=WAL;", ()).await?; |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRAGMA journal_mode=WAL is a write operation that modifies the database configuration, but it's being executed using self.query() which uses the read-only connection (read_conn). This should use self.execute() instead, which uses the write_conn connection. While this may work in some SQLite implementations, it could lead to "database is locked" errors or permission issues as mentioned in the comment on line 19.
| self.query("PRAGMA journal_mode=WAL;", ()).await?; | |
| self.execute("PRAGMA journal_mode=WAL;", ()).await?; |
Lines of code reportTotal lines added: Detailed view |
Motivation
Migrations of SQL schema are tricky. If new tables were added, it has to be migrated manually.
Description
Make SQL schema setup sentences idempotent so they can be executed on every start up.