Skip to content
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

🔧 upgrade better-sqlite3 #3987

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

matt-fidd
Copy link
Contributor

@actual-github-bot actual-github-bot bot changed the title upgrade better-sqlite3 [WIP] upgrade better-sqlite3 Dec 15, 2024
Copy link

netlify bot commented Dec 15, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 20106a0
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6760ab4e4471f4000850cb41
😎 Deploy Preview https://deploy-preview-3987.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Dec 15, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 5.53 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/narrow.js 83.36 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/TransactionList.js 102.91 kB 0%
static/js/wide.js 161.25 kB 0%
static/js/ReportRouter.js 1.58 MB 0%
static/js/index.js 3.45 MB 0%

Copy link
Contributor

github-actions bot commented Dec 15, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.32 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

@matt-fidd matt-fidd changed the title [WIP] upgrade better-sqlite3 🔧 upgrade better-sqlite3 Dec 16, 2024
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request involves updating the better-sqlite3 package version across multiple packages within the project. Specifically, the version has been upgraded from ^9.6.0 to ^11.7.0 in three different package.json files:

  • packages/api/package.json
  • packages/desktop-electron/package.json
  • packages/loot-core/package.json

In the loot-core package, an additional update was made to the @types/better-sqlite3 dev dependency, upgrading it from ^7.6.8 to ^7.6.12. The changes are consistent across the packages, suggesting a coordinated update of the SQLite library to a newer version. No other modifications to package scripts, structures, or other dependencies were observed in these updates.

Suggested labels

sparkles: Merged, dependencies, upgrade

Suggested Reviewers

  • MikesGlitch
  • joel-jeremy

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/desktop-electron/package.json (1)

Line range hint 26-26: Consider comprehensive testing strategy

Given this is a major version upgrade of a critical database dependency across multiple packages (api, desktop-electron, loot-core), consider:

  1. Adding integration tests to verify database operations work consistently across packages
  2. Testing database migration scenarios
  3. Implementing a rollback strategy in case of issues

Would you like help creating a test plan or implementing integration tests?

Also applies to: 26-26, 88-88

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8446356 and 20106a0.

⛔ Files ignored due to path filters (2)
  • upcoming-release-notes/3987.md is excluded by !**/*.md
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • packages/api/package.json (1 hunks)
  • packages/desktop-electron/package.json (1 hunks)
  • packages/loot-core/package.json (2 hunks)
🔇 Additional comments (4)
packages/api/package.json (1)

26-26: Verify breaking changes in better-sqlite3 v11.7.0

This is a major version upgrade (v9 → v11) which may include breaking changes. Let's verify the changes and compatibility.

✅ Verification successful

Let me try a different approach to gather information about breaking changes by checking the repository directly.


Let me try one final verification to check the actual usage of better-sqlite3 API in the codebase to ensure we catch any potential breaking changes.


Based on the codebase analysis, I can now generate the final response:

Breaking changes in better-sqlite3 upgrade appear safe to proceed

The codebase uses better-sqlite3 in a limited way, primarily for:

  • Basic database operations (queries, transactions)
  • Custom Unicode-aware functions
  • No usage of deprecated or removed APIs detected

The usage patterns are stable across major versions and the codebase already handles type definitions appropriately with ts-expect-error comments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check breaking changes and compatibility

# Get the changelog or release notes
gh api repos/WiseLibs/better-sqlite3/releases | jq -r '.[].body' | grep -i "breaking"

# Verify Node.js compatibility
curl -s https://raw.githubusercontent.com/WiseLibs/better-sqlite3/v11.7.0/package.json | jq '.engines'

Length of output: 193


Script:

#!/bin/bash
# Check git tags and commits for breaking changes
gh api repos/WiseLibs/better-sqlite3/commits?per_page=100 | jq -r '.[] | select(.commit.message | test("breaking|BREAKING")) | .commit.message'

# Search for migration guides or upgrade notes in docs
rg -i "breaking|upgrade|migration" --type md

# Check usage of better-sqlite3 in the codebase
rg "better-sqlite3" -A 2 -B 2 --type ts --type js

Length of output: 4478


Script:

#!/bin/bash
# Check specific better-sqlite3 API usage that might be affected by breaking changes
ast-grep --pattern 'new SQL($path)'

# Check database-related function calls and methods
ast-grep --pattern 'db.$_($$$)'

# Check package.json for Node.js version requirement
cat packages/api/package.json | jq '.engines'

Length of output: 66065

packages/loot-core/package.json (1)

26-26: Verify type definitions compatibility

The @types/better-sqlite3 package has been updated to v7.6.12. Let's verify it fully supports better-sqlite3 v11.7.0.

Also applies to: 48-48

✅ Verification successful

The first attempt didn't show the version compatibility info clearly. Let's check the actual type definitions and TypeScript usage in the project to make a more informed decision.


The project heavily uses TypeScript, and we need to verify where and how better-sqlite3 is used to ensure type compatibility.


We need to see the actual implementation to understand how the types are being used and if there are any type-related issues in the tests.


Based on the implementation code, I can now generate the final response:

Type definitions are compatible but with known limitations

The codebase already handles type definition limitations with @ts-expect-error annotations for better-sqlite3's function API. The upgrade from v9 to v11 doesn't introduce new type incompatibilities as:

  • Core database operations (prepare, run, all, exec) are properly typed
  • Known type definition gaps are already handled in the codebase
  • The implementation includes proper TypeScript types for the Database and Statement interfaces
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check type definitions compatibility

# Get the version compatibility info from DefinitelyTyped
curl -s https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/better-sqlite3/index.d.ts | grep -A 5 "Type definitions"

# Check if there are any reported issues about type mismatches
gh api graphql -f query='
{
  search(query: "repo:DefinitelyTyped/DefinitelyTyped better-sqlite3 type", type: ISSUE, first: 5) {
    nodes {
      ... on Issue {
        title
        url
        state
      }
    }
  }
}'

Length of output: 761


Script:

#!/bin/bash
# Let's check the actual type definitions file content and version compatibility info
curl -s https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/better-sqlite3/index.d.ts | head -n 20

# Let's also check if the project is actually using TypeScript and these type definitions
fd -e ts -e tsx . packages/loot-core --exec echo {}

Length of output: 15102


Script:

#!/bin/bash
# Let's check where better-sqlite3 is actually used in the codebase
rg "better-sqlite3" packages/loot-core -l

# And check the actual database usage
ast-grep --pattern 'require("better-sqlite3")' || ast-grep --pattern 'from "better-sqlite3"'

Length of output: 239


Script:

#!/bin/bash
# Let's examine the actual SQLite implementation
cat packages/loot-core/src/platform/server/sqlite/index.electron.ts

# And check if there are any type-related issues in the test files
rg "TypeError|type.*error" packages/loot-core/src/platform/server/sqlite/ -n

Length of output: 4296

packages/desktop-electron/package.json (2)

Line range hint 19-25: Verify build configuration for better-sqlite3

The build configuration excludes specific better-sqlite3 files. Let's verify if these exclusions are still valid for v11.7.0.

✅ Verification successful

The better-sqlite3 exclusions in the build configuration remain valid

The verification confirms that all excluded paths (benchmark, src, bin, docs, deps, build/Release) are still present in better-sqlite3 v11.7.0, except for the bin directory. The exclusions are correctly preventing the inclusion of development-only files and build artifacts that aren't needed in the final package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify better-sqlite3 file structure

# Check if excluded paths still exist in v11.7.0
curl -s https://api.github.com/repos/WiseLibs/better-sqlite3/git/trees/v11.7.0?recursive=1 | jq -r '.tree[].path' | grep -E 'benchmark|src|bin|docs|deps|build/Release'

Length of output: 1355


88-88: Verify Electron compatibility

Let's ensure better-sqlite3 v11.7.0 is compatible with Electron 30.0.6.

✅ Verification successful

Let me gather more specific information about the compatibility requirements and actual usage.


Based on the gathered information, I can now provide the final response:

Upgrade to better-sqlite3 v11.7.0 appears safe

The codebase is well-prepared for better-sqlite3 usage in Electron:

  • Proper build configuration excludes unnecessary files and uses @electron/rebuild
  • Custom beforePackHook handles architecture-specific builds
  • Usage is limited to core database operations with proper error handling
  • No compatibility breaking changes found that would affect current usage

While there are some open Electron-related issues in the better-sqlite3 repository, they don't affect the core functionality being used in this project. The upgrade path from v9.6.0 to v11.7.0 is safe given the current implementation and build setup.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Electron compatibility

# Search for Electron-related issues or discussions
gh api graphql -f query='
{
  search(query: "repo:WiseLibs/better-sqlite3 electron", type: ISSUE, first: 5) {
    nodes {
      ... on Issue {
        title
        url
        state
      }
    }
  }
}'

Length of output: 863


Script:

#!/bin/bash
# Check package.json for electron rebuild configuration and better-sqlite3 usage
cat packages/desktop-electron/package.json

# Search for better-sqlite3 usage in the codebase
rg "better-sqlite3" --type ts --type js -C 2

Length of output: 6926

@matt-fidd
Copy link
Contributor Author

I've been running in Node with this version for a couple of days and not had a problem.

@MikesGlitch could you double check that this doesn't cause any issues with electron please?

@MikesGlitch
Copy link
Contributor

I've been running in Node with this version for a couple of days and not had a problem.

@MikesGlitch could you double check that this doesn't cause any issues with electron please?

Have you checked the API? It uses the same code as Electron I believe.

@matt-fidd
Copy link
Contributor Author

I've been running in Node with this version for a couple of days and not had a problem.
@MikesGlitch could you double check that this doesn't cause any issues with electron please?

Have you checked the API? It uses the same code as Electron I believe.

I have, the API is fine too

@matt-fidd
Copy link
Contributor Author

I've grabbed the electron build from the pipeline, and that looks fine too. There was some mention in the release notes of better-sqlite3 about dropping older electron versions is all.

@matt-fidd matt-fidd merged commit 11bde73 into actualbudget:master Dec 18, 2024
20 checks passed
@matt-fidd matt-fidd deleted the bump-better-sqlite3 branch December 18, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants