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

[OTE-751] create affiliate referred users table #2177

Merged
merged 5 commits into from
Aug 30, 2024

Conversation

jerryfan01234
Copy link
Contributor

@jerryfan01234 jerryfan01234 commented Aug 30, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Introduced a new table for managing affiliate referred users, enhancing referral tracking.
    • Added a comprehensive suite of unit tests for the affiliate referral system to ensure reliability.
    • Expanded query capabilities for affiliate addresses, allowing for more detailed searches.
  • Bug Fixes

    • Improved data integrity checks to prevent duplicate entries in the affiliate referral system.
  • Documentation

    • Updated type definitions and interfaces for better clarity and type safety in affiliate referral management.

@jerryfan01234 jerryfan01234 requested a review from a team as a code owner August 30, 2024 18:43
Copy link

linear bot commented Aug 30, 2024

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes introduce a new affiliate referral system within the application, including a dedicated table for affiliate referred users, a model to interact with this table, and corresponding types and interfaces. Unit tests are added to validate the functionality of this system, ensuring data integrity and proper handling of affiliate referrals. Additionally, database migration scripts are provided to create and manage the new table structure.

Changes

Files Change Summary
indexer/packages/postgres/__tests__/helpers/constants.ts Added a new constant defaultAffiliateReferredUser for managing affiliate referred users.
indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts Introduced a test suite for the AffiliateReferredUsersTable module, covering creation, retrieval, and duplicate prevention of affiliate referrals.
indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts Created a migration script for the affiliate_referred_users table with defined schema and indexing.
indexer/packages/postgres/src/helpers/db-helpers.ts Added 'affiliate_referred_users' to the layer1Tables array for database operations.
indexer/packages/postgres/src/models/affiliate-referred-users-model.ts Defined AffiliateReferredUsersModel class for interacting with the affiliate_referred_users table, including data structure and JSON mapping.
indexer/packages/postgres/src/stores/affiliate-referred-users-table.ts Implemented functions for managing affiliate referred users, including retrieval and creation methods.
indexer/packages/postgres/src/stores/persistent-cache-table.ts Minor formatting change in the upsert function (added a blank line).
indexer/packages/postgres/src/types/affiliate-referred-users-types.ts Introduced AffiliateReferredUsersCreateObject interface and AffiliateReferredUsersColumns enum for structured data handling.
indexer/packages/postgres/src/types/db-model-types.ts Added AffiliateReferredUserFromDatabase interface for database interactions related to affiliate referrals.
indexer/packages/postgres/src/types/index.ts Exported types from affiliate-referred-users-types for broader accessibility.
indexer/packages/postgres/src/types/query-types.ts Expanded QueryableField enum with AFFILIATE_ADDRESS and REFEREE_ADDRESS, and introduced AffiliateReferredUsersQueryConfig interface for query configurations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AffiliateReferredUsersTable
    participant Database

    User->>AffiliateReferredUsersTable: Create Affiliate Referred User
    AffiliateReferredUsersTable->>Database: Insert User Entry
    Database-->>AffiliateReferredUsersTable: Confirmation
    AffiliateReferredUsersTable-->>User: Success Response

    User->>AffiliateReferredUsersTable: Retrieve Affiliate Referred Users
    AffiliateReferredUsersTable->>Database: Query Users
    Database-->>AffiliateReferredUsersTable: Return User Entries
    AffiliateReferredUsersTable-->>User: User Entries
Loading

🐰 "In fields of green, I hop with glee,
New friends to find, oh what a spree!
With addresses shared, and blocks to track,
Affiliate joy, we’ll never look back!
So let’s celebrate, with a joyful cheer,
For every referral, brings us near!" 🌼


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>.
    • 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 show all the console.log statements in this repository.
    • @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
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: 2

Outside diff range, codebase verification and nitpick comments (1)
indexer/packages/postgres/__tests__/helpers/constants.ts (1)

946-951: Review of defaultAffiliateReferredUser constant.

The new constant defaultAffiliateReferredUser is well-defined and aligns with the intended enhancements to the affiliate referral system. However, the use of referredAtBlock set to 1 might be a placeholder. It would be beneficial to add a comment explaining whether this is a default value or if it should be dynamically set during runtime.

Consider adding a comment about the referredAtBlock field to clarify its usage.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between abfec2a and 9f89228.

Files selected for processing (11)
  • indexer/packages/postgres/tests/helpers/constants.ts (2 hunks)
  • indexer/packages/postgres/tests/stores/affiliate-referred-users-table.test.ts (1 hunks)
  • indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts (1 hunks)
  • indexer/packages/postgres/src/helpers/db-helpers.ts (1 hunks)
  • indexer/packages/postgres/src/models/affiliate-referred-users-model.ts (1 hunks)
  • indexer/packages/postgres/src/stores/affiliate-referred-users-table.ts (1 hunks)
  • indexer/packages/postgres/src/stores/persistent-cache-table.ts (1 hunks)
  • indexer/packages/postgres/src/types/affiliate-referred-users-types.ts (1 hunks)
  • indexer/packages/postgres/src/types/db-model-types.ts (1 hunks)
  • indexer/packages/postgres/src/types/index.ts (1 hunks)
  • indexer/packages/postgres/src/types/query-types.ts (2 hunks)
Files not reviewed due to server errors (3)
  • indexer/packages/postgres/src/types/affiliate-referred-users-types.ts
  • indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts
  • indexer/packages/postgres/src/models/affiliate-referred-users-model.ts
Files skipped from review due to trivial changes (1)
  • indexer/packages/postgres/src/stores/persistent-cache-table.ts
Additional comments not posted (5)
indexer/packages/postgres/src/types/index.ts (1)

31-31: LGTM! But verify the usage of new types.

The addition of the export statement for affiliate-referred-users-types is approved. However, ensure that the new types are being used correctly in the project.

Run the following script to verify the usage of the new types:

Verification successful

New types are being used correctly in the project. The types from affiliate-referred-users-types are utilized in various parts of the codebase, including implementation and test files, confirming their integration.

  • indexer/packages/postgres/src/stores/affiliate-referred-users-table.ts
  • indexer/packages/postgres/src/models/affiliate-referred-users-model.ts
  • indexer/packages/postgres/__tests__/stores/affiliate-referred-users-table.test.ts
  • indexer/packages/postgres/__tests__/helpers/constants.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of types from `affiliate-referred-users-types` in the project.

# Test: Search for the usage of types from the new module. Expect: At least one occurrence.
rg --type typescript -A 5 $'AffiliateReferredUsers'

Length of output: 85


Script:

#!/bin/bash
# Description: Verify the usage of types from `affiliate-referred-users-types` in the project.

# Test: Search for the usage of types from the new module. Expect: At least one occurrence.
rg -A 5 'AffiliateReferredUsers'

Length of output: 20347

indexer/packages/postgres/src/helpers/db-helpers.ts (1)

31-31: Addition of 'affiliate_referred_users' to layer1Tables

The addition of the 'affiliate_referred_users' table to the layer1Tables array is correctly implemented. Ensure that the database schema includes this table and that all necessary migrations are in place.

Run the following script to verify the table's presence in the database schema:

Verification successful

Verification of 'affiliate_referred_users' Table Integration

The affiliate_referred_users table is correctly integrated into the database schema. It is referenced in the layer1Tables array, and a migration file exists to create the table. Additionally, a model file is present, indicating structured interaction with the table.

  • Migration File: indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts
  • Model File: indexer/packages/postgres/src/models/affiliate-referred-users-model.ts

The integration appears complete and well-structured.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of the 'affiliate_referred_users' table in the database schema.

# Test: Check if the table exists in the schema. Expect: Table exists.
knexPrimary.schema.hasTable('affiliate_referred_users').then(exists => {
  if (exists) {
    console.log('Table exists.');
  } else {
    console.log('Table does not exist.');
  }
});

Length of output: 234


Script:

#!/bin/bash
# Search for migration files or schema definitions related to the 'affiliate_referred_users' table.
rg 'affiliate_referred_users' --glob '*migrations*' -A 5

Length of output: 56


Script:

#!/bin/bash
# Search for any references to the 'affiliate_referred_users' table across the entire codebase.
rg 'affiliate_referred_users' -A 5

Length of output: 2322

indexer/packages/postgres/src/types/db-model-types.ts (1)

281-285: New Interface: AffiliateReferredUserFromDatabase

The interface AffiliateReferredUserFromDatabase is well-defined with appropriate types for its properties. Ensure that these properties align with the corresponding columns in the database table.

Run the following script to verify the alignment of interface properties with the database columns:

Verification successful

Interface Properties Match Database Columns

The AffiliateReferredUserFromDatabase interface is correctly aligned with the affiliate_referred_users table schema. The properties affiliateAddress, refereeAddress, and referredAtBlock match the corresponding database columns in both name and type. No changes are needed.

  • refereeAddress: string, primary key, not nullable
  • affiliateAddress: string, indexed, not nullable
  • referredAtBlock: integer, not nullable
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the alignment of interface properties with the database columns.

# Test: Check if the columns match the interface properties. Expect: Columns match.
knexPrimary('affiliate_referred_users').columnInfo().then(info => {
  console.log(info);
});

Length of output: 229


Script:

#!/bin/bash
# Locate migration or schema files that might define the `affiliate_referred_users` table.
fd '.*\.(sql|js|ts|json|yml|yaml|migration)$'

Length of output: 73277


Script:

#!/bin/bash
# Search for the `affiliate_referred_users` table definition in the located files.
rg 'affiliate_referred_users' --type-add 'migration:*.{sql,js,ts,json,yml,yaml}'

Length of output: 638


Script:

#!/bin/bash
# Extract the table schema definition from the migration file for `affiliate_referred_users`.
rg 'createTable.*affiliate_referred_users' -A 10 indexer/packages/postgres/src/db/migrations/migration_files/20240830154741_create_affiliate_referred_users_table.ts

Length of output: 561

indexer/packages/postgres/src/types/query-types.ts (2)

91-92: Addition of New Enum Values: AFFILIATE_ADDRESS and REFEREE_ADDRESS

The addition of AFFILIATE_ADDRESS and REFEREE_ADDRESS to the QueryableField enum is correctly implemented. Ensure that the query processing logic supports these new fields.

Run the following script to verify the support for these fields in the query processing logic:

Verification successful

Successful Integration of New Enum Values into Query Processing Logic

The new enum values AFFILIATE_ADDRESS and REFEREE_ADDRESS are successfully integrated into the query processing logic. They are used in the findAll function within affiliate-referred-users-table.ts, confirming their support in query operations.

  • affiliate-referred-users-table.ts: findAll function uses AffiliateReferredUsersQueryConfig with affiliateAddress and refereeAddress.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the support for new query fields in the query processing logic.

# Test: Check if the query processing logic supports the new fields. Expect: Fields are supported.
# Placeholder for actual verification logic.
echo "Verify the query processing logic for new fields."

Length of output: 108


Script:

#!/bin/bash
# Search for the usage of AFFILIATE_ADDRESS and REFEREE_ADDRESS in the codebase
rg 'AFFILIATE_ADDRESS|REFEREE_ADDRESS' --context 5

Length of output: 2046


Script:

#!/bin/bash
# Search for the usage of AffiliateReferredUsersQueryConfig in the codebase
rg 'AffiliateReferredUsersQueryConfig' --context 5

Length of output: 2871


324-327: New Interface: AffiliateReferredUsersQueryConfig

The interface AffiliateReferredUsersQueryConfig is well-defined and extends the existing QueryConfig system appropriately. Ensure that this interface is correctly utilized in the query building process.

Run the following script to verify the utilization of this interface in the query building process:

Verification successful

Correct Utilization of AffiliateReferredUsersQueryConfig

The AffiliateReferredUsersQueryConfig interface is correctly utilized in the findAll function within affiliate-referred-users-table.ts. It is used to pass query parameters and is integrated with the existing query verification system, confirming its intended use.

  • File: indexer/packages/postgres/src/stores/affiliate-referred-users-table.ts
  • Function: findAll
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the utilization of the `AffiliateReferredUsersQueryConfig` interface in the query building process.

# Test: Check if the interface is utilized correctly. Expect: Interface is utilized.
# Placeholder for actual verification logic.
echo "Verify the utilization of the AffiliateReferredUsersQueryConfig interface."

Length of output: 158


Script:

#!/bin/bash
# Search for references to the AffiliateReferredUsersQueryConfig interface in the codebase
ast-grep --lang typescript --pattern 'AffiliateReferredUsersQueryConfig'

Length of output: 183


Script:

#!/bin/bash
# Extract lines around the reference to AffiliateReferredUsersQueryConfig in affiliate-referred-users-table.ts
rg 'AffiliateReferredUsersQueryConfig' -A 10 -B 10 indexer/packages/postgres/src/stores/affiliate-referred-users-table.ts

Length of output: 880

@jerryfan01234 jerryfan01234 merged commit ffde811 into main Aug 30, 2024
16 checks passed
@jerryfan01234 jerryfan01234 deleted the affiliates-new-affiliate-referred-useres-table branch August 30, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants