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

example: update cli example #131

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

jaipaljadeja
Copy link
Member

No description provided.

@jaipaljadeja jaipaljadeja requested a review from fracek January 1, 2025 16:00
Copy link

coderabbitai bot commented Jan 1, 2025

📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the Apibara CLI example project, focusing on database schema and indexer configuration. The modifications involve updating the Drizzle ORM table definitions, removing the checkpoints table, adding a new _id UUID column to transfer tables, and replacing the previous persistence mechanism with a new Drizzle storage plugin. The changes streamline the indexer's data handling, update import statements, and adjust the starting cursor positions for both Ethereum and Starknet indexers.

Changes

File Change Summary
examples/cli/docker-compose.yml Removed volumes section for PostgreSQL data storage
examples/cli/drizzle/0000_great_hobgoblin.sql Deleted SQL file with table definitions for checkpoints, transfers, and filters
examples/cli/drizzle/0000_plain_omega_red.sql Added new table definitions for ethereum_usdc_transfers and starknet_usdc_transfers with UUID primary key
examples/cli/drizzle/meta/0000_snapshot.json Updated metadata with new table structures, removed checkpoints table
examples/cli/indexers/1-evm.indexer.ts Updated imports, changed storage plugin, modified transform function
examples/cli/indexers/2-starknet.indexer.ts Similar changes to EVM indexer, updated imports and storage mechanism
examples/cli/lib/schema.ts Replaced pgIndexerTable with pgTable, added UUID primary key
examples/cli/package.json Added @apibara/plugin-drizzle dependency
pnpm-workspace.yaml Removed exclusion for examples/cli directory

Sequence Diagram

sequenceDiagram
    participant Indexer
    participant DrizzleStorage
    participant Database
    
    Indexer->>DrizzleStorage: Initialize with new configuration
    DrizzleStorage->>Database: Connect with UUID primary key
    Indexer->>Database: Transform and store data
    Database-->>Indexer: Confirm storage with new schema
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Ode to Schema Delight

Tables dance with UUIDs so bright,
Indexers leap with newfound might,
Drizzle's magic, clean and tight,
Persistence reimagined, pure delight!

🚀 Code hops forward, schema refined! 🌟


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

@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 (6)
examples/cli/indexers/2-starknet.indexer.ts (1)

61-66: Nitpick: Consider condensing log statements.
Using multiple arguments across multiple lines is fine, but a single template string might be more readable:

-logger.info(
-  "Transforming block | orderKey: ",
-  endCursor?.orderKey,
-  " | finality: ",
-  finality,
-);
+logger.info(`Transforming block | orderKey: ${endCursor?.orderKey} | finality: ${finality}`);
examples/cli/lib/schema.ts (2)

3-4: Adding _id UUID primary key to starknet_usdc_transfers.
Using a random UUID might be sufficient for uniqueness, but if you expect rows to be inherently unique by block/orderKey + transaction hash, consider adding a unique index on those columns.


9-10: Adding _id UUID primary key to ethereum_usdc_transfers.
Same note applies here regarding the potential need for a unique index on existing fields.

examples/cli/indexers/1-evm.indexer.ts (1)

70-75: Nitpick: Consolidate multiline log messages.
Consider using one template string for clarity, similar to the suggestion in 2-starknet.indexer.ts.

pnpm-workspace.yaml (1)

3-3: Include examples/** in the workspace + missing newline.
Great to have the CLI examples included in the workspace. Also, fix the missing newline at the end of the file to satisfy yamllint:

3   - "examples/**"
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 3-3: no new line character at the end of file

(new-line-at-end-of-file)

examples/cli/drizzle/meta/0000_snapshot.json (1)

11-17: Consider adding indexes for query performance

While the UUID primary key provides uniqueness, consider adding indexes on (number, hash) columns if these fields are frequently used in queries. This would improve query performance for block number and transaction hash lookups.

Also applies to: 43-49

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eda239d and 4aabdcf.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • examples/cli/docker-compose.yml (1 hunks)
  • examples/cli/drizzle/0000_great_hobgoblin.sql (0 hunks)
  • examples/cli/drizzle/0000_plain_omega_red.sql (1 hunks)
  • examples/cli/drizzle/meta/0000_snapshot.json (2 hunks)
  • examples/cli/drizzle/meta/_journal.json (1 hunks)
  • examples/cli/indexers/1-evm.indexer.ts (4 hunks)
  • examples/cli/indexers/2-starknet.indexer.ts (4 hunks)
  • examples/cli/indexers/3-starknet-factory.indexer.ts (1 hunks)
  • examples/cli/lib/schema.ts (1 hunks)
  • examples/cli/package.json (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • examples/cli/drizzle/0000_great_hobgoblin.sql
✅ Files skipped from review due to trivial changes (2)
  • examples/cli/drizzle/meta/_journal.json
  • examples/cli/drizzle/0000_plain_omega_red.sql
🧰 Additional context used
🪛 yamllint (1.35.1)
pnpm-workspace.yaml

[error] 3-3: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (17)
examples/cli/indexers/2-starknet.indexer.ts (6)

1-2: No issues with the new defineIndexer import.
These lines appear to introduce or reorganize imports without changing functionality.


15-16: Clean import of logging and Drizzle plugins.
Switching to these imports is consistent with the new plugin approach.


37-37: Verify the updated orderKey.
Please confirm that 10_30_000n is the intended starting cursor for your Starknet indexer.


40-45: Properly configured Drizzle storage plugin.
This appears correct for persisting indexing state with _id as the primary key and custom indexer name.


56-56: Updated transform signature with finality.
Including finality is useful for advanced indexer logic if you need to handle reorgs or partial finality states.


58-58: Retrieving the database from Drizzle storage.
Looks good. Ensure the Drizzle storage usage aligns with other indexers for consistency.

examples/cli/lib/schema.ts (1)

1-1: All necessary imports for Drizzle schema definitions.
This change looks good.

examples/cli/indexers/3-starknet-factory.indexer.ts (1)

2-2: Refactored useLogger import path.
No issues. This change aligns with the import style used throughout the indexers.

examples/cli/indexers/1-evm.indexer.ts (6)

2-3: Drizzle plugin imports look correct.
This facilitates the move from older persistence mechanisms to Drizzle-based storage.


15-15: Refactored logger import path.
Change appears consistent with other indexers.


42-42: Verify the updated starting cursor.
Confirm that 215_30_000n is the correct block range for your Ethereum indexer.


58-63: Drizzle storage configuration.
Looks properly set up with persistState, _id, and a meaningful indexerName.


65-65: Enhanced transform signature.
Adding the finality parameter is a useful addition for decisions based on chain finality.


67-67: Retrieve database via useDrizzleStorage.
Implementation matches the new approach used in 2-starknet.indexer.ts.

examples/cli/docker-compose.yml (1)

9-9: Verify the intentional removal of volume persistence

The removal of the named volume means that database data will not persist between container restarts. While this might be acceptable for an example project, please confirm if this is intentional.

Run this script to check for volume definitions in other compose files:

✅ Verification successful

Removal of volume persistence is appropriate for this example setup

The docker-compose.yml file is located in the examples/cli directory, which indicates this is an example setup meant for demonstration or quick-start purposes. For such cases, it's common and acceptable to omit persistence to:

  • Keep the setup simple and minimal
  • Allow users to start with a clean state each time
  • Avoid cluttering the user's system with persistent volumes

The other compose file found (packages/plugin-mongo/docker-compose.orbstack.yaml) is unrelated as it's for a different database (MongoDB) and serves a different purpose in the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for volume definitions in other compose files
# to ensure this wasn't accidentally removed

fd -e yml -e yaml docker-compose --exec grep -l "volumes:"

Length of output: 111


Script:

#!/bin/bash
# Let's check the content of both compose files to understand the context better
echo "=== Content of examples/cli/docker-compose.yml ==="
cat examples/cli/docker-compose.yml

echo -e "\n=== Content of packages/plugin-mongo/docker-compose.orbstack.yaml ==="
cat packages/plugin-mongo/docker-compose.orbstack.yaml

Length of output: 1286


Script:

#!/bin/bash
# Let's check if there are any README files in the examples/cli directory
# that might explain the intended setup
echo "=== Checking for README in examples/cli ==="
fd README -e md --max-depth 2 examples/cli --exec cat {}

Length of output: 157

examples/cli/package.json (1)

32-32: LGTM! Dependency addition aligns with storage plugin migration

The addition of @apibara/plugin-drizzle is consistent with the broader changes to migrate to the Drizzle storage plugin and the removal of the checkpoints table.

examples/cli/drizzle/meta/0000_snapshot.json (1)

2-2: Verify data migration strategy

The schema changes (new migration ID: 9d645b77-7634-42a6-9849-92477d936c41) introduce significant changes:

  1. Removal of _cursor columns
  2. Addition of UUID primary keys
  3. Removal of checkpoints table

Please ensure there's a data migration strategy in place for existing data.

Run this script to check for migration files:

Also applies to: 11-17, 43-49

@fracek fracek merged commit 4e5e99a into apibara:main Jan 3, 2025
2 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.

2 participants