-
Notifications
You must be signed in to change notification settings - Fork 129
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
[OTE-751] create affiliate referred users table #2177
Conversation
WalkthroughThe 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
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 ofdefaultAffiliateReferredUser
constant.The new constant
defaultAffiliateReferredUser
is well-defined and aligns with the intended enhancements to the affiliate referral system. However, the use ofreferredAtBlock
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
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 layer1TablesThe addition of the
'affiliate_referred_users'
table to thelayer1Tables
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 thelayer1Tables
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 5Length 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 5Length of output: 2322
indexer/packages/postgres/src/types/db-model-types.ts (1)
281-285
: New Interface: AffiliateReferredUserFromDatabaseThe 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 theaffiliate_referred_users
table schema. The propertiesaffiliateAddress
,refereeAddress
, andreferredAtBlock
match the corresponding database columns in both name and type. No changes are needed.
refereeAddress
: string, primary key, not nullableaffiliateAddress
: string, indexed, not nullablereferredAtBlock
: integer, not nullableScripts 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.tsLength of output: 561
indexer/packages/postgres/src/types/query-types.ts (2)
91-92
: Addition of New Enum Values: AFFILIATE_ADDRESS and REFEREE_ADDRESSThe addition of
AFFILIATE_ADDRESS
andREFEREE_ADDRESS
to theQueryableField
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
andREFEREE_ADDRESS
are successfully integrated into the query processing logic. They are used in thefindAll
function withinaffiliate-referred-users-table.ts
, confirming their support in query operations.
affiliate-referred-users-table.ts
:findAll
function usesAffiliateReferredUsersQueryConfig
withaffiliateAddress
andrefereeAddress
.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 5Length of output: 2046
Script:
#!/bin/bash # Search for the usage of AffiliateReferredUsersQueryConfig in the codebase rg 'AffiliateReferredUsersQueryConfig' --context 5Length of output: 2871
324-327
: New Interface: AffiliateReferredUsersQueryConfigThe interface
AffiliateReferredUsersQueryConfig
is well-defined and extends the existingQueryConfig
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 thefindAll
function withinaffiliate-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.tsLength of output: 880
Changelist
[Describe or list the changes made in this PR]
Test Plan
[Describe how this PR was tested (if applicable)]
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit
New Features
Bug Fixes
Documentation