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

fix: missing features migrations for existing ledgers #601

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Dec 5, 2024

No description provided.

@gfyrag gfyrag requested a review from a team as a code owner December 5, 2024 13:45
Copy link

coderabbitai bot commented Dec 5, 2024

Warning

Rate limit exceeded

@gfyrag has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3a78184 and 83c2fe8.

Walkthrough

The changes involve modifications to the migration logic in the internal/storage/system/migrations.go file. A new migration for configuring features in old ledgers is introduced, updating the features column in the _system.ledgers table. The configuration table is removed, and several columns in the _system.ledgers table are created or altered, including the addition of a sequential ID column and a metadata column of type jsonb. The migration logic is enhanced to ensure data integrity and accommodate new features.

Changes

File Path Change Summary
internal/storage/system/migrations.go - Added import for features package.
- Introduced new migration "Configure features for old ledgers."
- Removed configuration table.
- Created _system.ledgers table with new columns and constraints.
- Added and later removed state column.
- Generated added_at column with default timestamp.
- Created sequence for ledger IDs.
- Updated method signature for GetMigrator.
internal/storage/system/migrations_test.go - Added new migration hook addDefaultFeatures to TestMigrations.
- Hook includes an After function to validate default features in _system.ledgers table.

Poem

🐇 In the land of code where ledgers play,
New features bloom, brightening the day.
Tables restructured, old ones set free,
With migrations dancing, as happy as can be!
A hop and a skip, the data's in line,
Cheers to the changes, all perfectly fine! 🌼


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

@gfyrag gfyrag enabled auto-merge December 5, 2024 13:51
@gfyrag gfyrag force-pushed the fix/features-migrations branch 5 times, most recently from e76a66a to 3a78184 Compare December 5, 2024 14:15
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: 0

🧹 Outside diff range and nitpick comments (1)
internal/storage/system/migrations_test.go (1)

86-101: Consider enhancing test coverage.

While the current test verifies that features are set to DefaultFeatures after migration, it would be beneficial to also test:

  1. Pre-existing non-null features are preserved
  2. Edge cases like empty JSON objects

Here's a suggested enhancement:

 var addDefaultFeatures = migrations.Hook{
+    Before: func(ctx context.Context, t *testing.T, db bun.IDB) error {
+        // Insert test ledgers with various feature states
+        _, err := db.NewInsert().
+            Model(&map[string]any{
+                "name": "ledger_null_features",
+                "features": nil,
+            }).
+            TableExpr("_system.ledgers").
+            Exec(ctx)
+        require.NoError(t, err)
+
+        // Insert ledger with custom features
+        customFeatures := map[string]string{"custom": "value"}
+        _, err = db.NewInsert().
+            Model(&map[string]any{
+                "name": "ledger_custom_features",
+                "features": customFeatures,
+            }).
+            TableExpr("_system.ledgers").
+            Exec(ctx)
+        require.NoError(t, err)
+        return nil
+    },
     After: func(ctx context.Context, t *testing.T, db bun.IDB) {
         type x struct {
+            Name     string             `bun:"name"`
             Features map[string]string `bun:"features"`
         }
         model := make([]x, 0)
         err := db.NewSelect().
             ModelTableExpr("_system.ledgers").
             Scan(ctx, &model)
         require.NoError(t, err)
 
         for _, m := range model {
-            require.EqualValues(t, features.DefaultFeatures, m.Features)
+            if m.Name == "ledger_null_features" {
+                require.EqualValues(t, features.DefaultFeatures, m.Features)
+            } else if m.Name == "ledger_custom_features" {
+                require.EqualValues(t, map[string]string{"custom": "value"}, m.Features)
+            }
         }
     },
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4b5e40 and 3a78184.

📒 Files selected for processing (2)
  • internal/storage/system/migrations.go (2 hunks)
  • internal/storage/system/migrations_test.go (3 hunks)
🔇 Additional comments (2)
internal/storage/system/migrations.go (1)

205-217: LGTM! Migration looks safe and well-implemented.

The migration correctly:

  • Uses transaction wrapper
  • Uses parameterized query to prevent SQL injection
  • Only updates null features, preserving existing configurations
  • Handles errors appropriately

Let's verify the default features configuration:

✅ Verification successful

Default features configuration verified and properly used

The verification confirms that:

  • DefaultFeatures is defined in pkg/features/features.go with appropriate feature flags:
    • MovesHistory: "ON"
    • MovesHistoryPostCommitEffectiveVolumes: "SYNC"
    • HashLogs: "SYNC"
    • AccountMetadataHistory: "SYNC"
    • TransactionMetadataHistory: "SYNC"

The migration correctly uses this configuration to set default features for ledgers where features are null, ensuring consistent behavior across the system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the default features configuration and its usage
# Expected: Should find references to DefaultFeatures in the codebase

# Check the DefaultFeatures definition
rg -A 5 "DefaultFeatures.*=" pkg/features/

# Check where these features are used
ast-grep --pattern 'features.DefaultFeatures'

Length of output: 40654

internal/storage/system/migrations_test.go (1)

41-41: LGTM! Test hook properly registered.

The hook is correctly appended to the migration test sequence.

@gfyrag gfyrag force-pushed the fix/features-migrations branch from 3a78184 to 83c2fe8 Compare December 5, 2024 14:24
@gfyrag gfyrag added this pull request to the merge queue Dec 5, 2024
Merged via the queue into main with commit a7263c1 Dec 5, 2024
8 of 9 checks passed
@gfyrag gfyrag deleted the fix/features-migrations branch December 5, 2024 14:38
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.

3 participants