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

Migrate from GRDB 5 to GRDB 6 #36

Merged
merged 3 commits into from
Sep 19, 2024
Merged

Conversation

iammajid
Copy link
Contributor

Migrate the project from GRDB 5 to GRDB 6, addressing issue #35 by updating database interactions and error handling to align with the latest GRDB changes.

Copy link

coderabbitai bot commented Sep 18, 2024

Walkthrough

This pull request introduces significant updates to the GRDB.swift dependency, upgrading it from version 5.26.1 to 6.29.3 in both Package.resolved and Package.swift. Additionally, several classes within the Cryptomator cloud access module have been modified to implement error handling during the initialization of DatabaseQueue, enhancing robustness. The changes also affect the test suite, ensuring that database initialization errors are properly managed.

Changes

File Change Summary
Package.resolved Updated GRDB.swift dependency version from 5.26.1 to 6.29.3.
Package.swift Updated GRDB.swift version constraint from 5.26.0 to 6.29.1.
Sources/CryptomatorCloudAccess/Box/BoxIdentifierCache.swift Modified init() to include error handling for DatabaseQueue initialization.
Sources/CryptomatorCloudAccess/Crypto/DirectoryIdCache.swift Modified init() to include error handling for DatabaseQueue initialization.
Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift Modified inMemoryDB initialization to include error handling.
Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift Modified inMemoryDB initialization to include error handling.
Sources/CryptomatorCloudAccess/OneDrive/OneDriveIdentifierCache.swift Modified init() to include error handling for DatabaseQueue initialization.
Sources/CryptomatorCloudAccess/PCloud/PCloudIdentifierCache.swift Modified init() to include error handling for DatabaseQueue initialization.
Tests/CryptomatorCloudAccessTests/Common/DirectoryContentCacheTests.swift Modified setUpWithError to initialize inMemoryDB with error handling.

Possibly related issues

  • Migrate GRDB 5 to GRDB 6 #35: This PR addresses the need to migrate from GRDB 5 to GRDB 6, resolving build issues with Xcode 16, which aligns with the dependency updates made in this PR.

Possibly related PRs

  • Added Box support #34: This PR integrates the Box cloud provider and includes modifications to classes that handle database interactions, relevant to the error handling updates in this PR.

Suggested reviewers

  • (No specific reviewers suggested in the provided content)

Poem

In the garden bright and fair,
A rabbit hops with nary a care.
With GRDB now upgraded high,
We handle errors, oh my, oh my!
Robust and ready, we leap and play,
In code's embrace, we frolic all day! 🐇✨


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 generate interesting stats about this repository and render them as a table.
    -- @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 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

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e08e0f2 and 85ff0b9.

Files selected for processing (10)
  • Package.resolved (1 hunks)
  • Package.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/Box/BoxIdentifierCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/DirectoryIdCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveIdentifierCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/OneDrive/OneDriveIdentifierCache.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/PCloud/PCloudIdentifierCache.swift (1 hunks)
  • Tests/CryptomatorCloudAccessTests/Common/DirectoryContentCacheTests.swift (1 hunks)
Additional comments not posted (9)
Sources/CryptomatorCloudAccess/Box/BoxIdentifierCache.swift (1)

16-16: Excellent improvement in error handling!

The changes in the init method declaration and the initialization of inMemoryDB using try DatabaseQueue() are great improvements in terms of error handling. By adding throws to the method declaration and using try when initializing inMemoryDB, you ensure that any errors encountered during the creation of the DatabaseQueue are properly propagated and can be handled by the callers of init.

This enhances the robustness of the code and makes it clear to the callers that they need to handle any potential errors that may occur during initialization.

Consider adding a do-catch block or using try? when calling init to handle any errors that may be thrown. For example:

do {
    let cache = try BoxIdentifierCache()
    // Use the cache
} catch {
    // Handle the error
}

or

let cache = try? BoxIdentifierCache()
if let cache = cache {
    // Use the cache
} else {
    // Handle the error
}
Sources/CryptomatorCloudAccess/PCloud/PCloudIdentifierCache.swift (1)

17-17: Improved error handling during initialization. LGTM!

The addition of try during DatabaseQueue instantiation and marking the init() method with throws enhances the robustness of the code. It ensures that any errors encountered during initialization are properly propagated and handled by the caller.

This change aligns with best practices of explicit error handling and improves the overall reliability of the PCloudIdentifierCache class.

Sources/CryptomatorCloudAccess/OneDrive/OneDriveIdentifierCache.swift (1)

16-16: Excellent improvement in error handling!

The change to include error handling during the initialization of DatabaseQueue is a great enhancement. It ensures that any errors that may occur during the setup of the database connection are properly propagated and can be handled by the caller of the init() method.

This aligns with the PR objective of updating error handling mechanisms and improves the overall reliability and robustness of the code.

Sources/CryptomatorCloudAccess/GoogleDrive/GoogleDriveIdentifierCache.swift (1)

16-16: Improved error handling during initialization.

The change introduces explicit error handling when initializing the inMemoryDB property using try DatabaseQueue(). This is a good practice as it ensures that any errors encountered during the initialization are propagated to the caller, allowing them to handle the error appropriately.

By using try, the code acknowledges that the initialization can fail and provides a clear indication to the caller that they need to handle the potential error. This improves the robustness and reliability of the code by preventing the creation of an invalid GoogleDriveIdentifierCache instance if the database initialization fails.

Great job on enhancing the error handling! 👍

Sources/CryptomatorCloudAccess/Crypto/DirectoryIdCache.swift (1)

32-32: Improved error handling for DatabaseQueue initialization.

The change to include error handling for DatabaseQueue initialization using the try keyword is a positive improvement. It ensures that any errors encountered during the initialization are appropriately managed, enhancing the robustness of the code.

This aligns with the PR objective of updating error handling mechanisms and follows best practices for error management.

Package.swift (1)

40-40: Ensure compatibility with GRDB 6.x.

Updating to a new major version of GRDB is a significant change that may introduce breaking changes or require code modifications.

Please ensure the following:

  1. Thoroughly test the application to verify compatibility with GRDB 6.x and identify any issues that may arise due to the version upgrade.

  2. Review the GRDB 6.x migration guide and release notes to understand the changes, potential code modifications required, and new features that can be leveraged.

  3. Make necessary code changes to align with the new version and address any deprecations or breaking changes.

  4. Consider updating the project's README or documentation to reflect the new GRDB version requirement and any notable changes or improvements it brings.

Let me know if you need any assistance with the migration process or have any specific concerns!

Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift (1)

51-51: Improved error handling during database queue initialization.

The change from DatabaseQueue() to try DatabaseQueue() enhances the robustness of the code by explicitly handling potential errors during the database queue initialization. If the initialization fails, the error will be propagated and can be caught and handled by the caller of the init method.

This change aligns with the error handling approach used in the rest of the init method, ensuring consistency and improving the overall reliability of the code.

Tests/CryptomatorCloudAccessTests/Common/DirectoryContentCacheTests.swift (1)

32-32: LGTM! The change aligns with the migration to GRDB 6.

The modification to the inMemoryDB initialization handles the new error-throwing behavior of the DatabaseQueue initializer introduced in GRDB 6. The use of try ensures proper error propagation and handling within the test setup.

Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift (1)

109-109: Excellent addition of error handling!

The introduction of the try keyword for DatabaseQueue() initialization ensures that any potential errors during the database queue creation are properly propagated and handled. This change improves the robustness and reliability of the code by explicitly managing initialization failures.

Furthermore, the addition of the throws keyword to the initializer signature correctly propagates the error to the caller, ensuring comprehensive error handling throughout the codebase.

Package.resolved Show resolved Hide resolved
Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a62f83 and b864495.

Files selected for processing (6)
  • Sources/CryptomatorCloudAccess/Box/BoxItem.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/DirectoryIdCache.swift (2 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift (2 hunks)
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift (2 hunks)
  • Sources/CryptomatorCloudAccess/OneDrive/OneDriveItem.swift (1 hunks)
  • Sources/CryptomatorCloudAccess/PCloud/PCloudItem.swift (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • Sources/CryptomatorCloudAccess/Crypto/DirectoryIdCache.swift
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat6/VaultFormat6ShortenedNameCache.swift
  • Sources/CryptomatorCloudAccess/Crypto/VaultFormat7/VaultFormat7ShortenedNameCache.swift
Additional comments not posted (2)
Sources/CryptomatorCloudAccess/Box/BoxItem.swift (1)

Line range hint 39-43: LGTM! Verify the impact of the function signature change.

The addition of the throws keyword to the encode(to:) function is a good change that enhances the error handling capabilities of the function. However, this is a breaking change for existing callers of this function.

Please ensure that all callers of this function have been updated to handle the potential errors thrown by this function. You can use the following script to verify the impact of this change:

Verification successful

LGTM, but ensure thorough testing of persistence-related functionality

The addition of throws to the encode(to:) method in BoxItem is consistent with other encode(to:) implementations in the codebase. However, given the widespread use of BoxItem throughout the project, particularly in BoxCloudProvider.swift, this change could have a significant impact.

While direct calls to encode(to:) on BoxItem instances are not visible in the provided code, the method is likely used implicitly through the PersistableRecord protocol. To ensure the change doesn't introduce any unexpected behavior:

  • Thoroughly test all persistence-related functionality, especially in BoxCloudProvider.
  • Update any documentation for the PersistableRecord protocol to reflect that conforming types should implement a throwing encode(to:) method.
  • Review and update error handling in any code that indirectly uses BoxItem's encode(to:) method through the PersistableRecord protocol.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all callers of the `encode(to:)` function have been updated to handle errors.

# Test: Search for the function usage. Expect: All occurrences to use `try` or handle errors.
rg --type swift -A 5 $'BoxItem\(\)\.encode\(to:'

Length of output: 49


Script:

#!/bin/bash
# Description: Gather more information about BoxItem and encode(to:) usage

# Search for BoxItem class declaration
echo "BoxItem class declaration:"
ast-grep --lang swift --pattern 'class BoxItem'

# Search for encode(to:) usage on BoxItem instances
echo "\nBoxItem encode(to:) usage:"
rg --type swift -A 5 '\.encode\(to:' | grep -i 'boxitem'

# Search for other encode(to:) implementations
echo "\nOther encode(to:) implementations:"
ast-grep --lang swift --pattern 'func encode(to $_: inout $_) $_'

Length of output: 1186


Script:

#!/bin/bash
# Description: Further investigation of BoxItem and encode(to:) usage

# Search for BoxItem definition
echo "BoxItem definition:"
rg --type swift -i 'class BoxItem|struct BoxItem|protocol BoxItem'

# Search for any mention of BoxItem
echo "\nBoxItem mentions:"
rg --type swift -i 'BoxItem'

# Search for encode(to:) implementations with adjusted pattern
echo "\nencode(to:) implementations:"
rg --type swift 'func encode\(to .+: inout .+\)'

# Search for Encodable conformance
echo "\nEncodable conformance:"
rg --type swift ': Encodable'

Length of output: 8869

Sources/CryptomatorCloudAccess/PCloud/PCloudItem.swift (1)

Line range hint 49-53: LGTM!

The change to the encode(to:) function signature to include the throws keyword is a good practice for error handling. It allows the function to propagate errors to its callers, which can help with better error management in the codebase.

The function body remains unchanged, and there are no apparent issues with the logic or syntax.

@tobihagemann tobihagemann linked an issue Sep 19, 2024 that may be closed by this pull request
@tobihagemann tobihagemann merged commit db2bfa4 into develop Sep 19, 2024
5 checks passed
@tobihagemann tobihagemann deleted the feature/migrate-grdb-5-to-6 branch September 19, 2024 08:49
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.

Migrate GRDB 5 to GRDB 6
2 participants