-
Notifications
You must be signed in to change notification settings - Fork 19
migration-script to push user data to kafka #789
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
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughA new migration utility for pushing user data to Kafka has been introduced. This includes a standalone Node.js script that queries users updated within a date range, enriches their location metadata, and publishes events to a Kafka topic. Documentation and a new dependency for argument parsing are also added. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI_User as CLI User
participant Script as pushUserDataToKafka.js
participant PG as PostgreSQL
participant ExtAPI as Location Enrichment Service
participant Kafka as Kafka Broker
CLI_User->>Script: Run script with --from and --to dates
Script->>PG: Connect and query users updated in date range
loop For each user
Script->>PG: Fetch user, orgs, roles
Script->>ExtAPI: Enrich location metadata (HTTP request)
ExtAPI-->>Script: Return enriched data or error
Script->>Kafka: Publish user event (create/update/delete)
end
Script-->>CLI_User: Log summary and exit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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: 7
🧹 Nitpick comments (4)
src/migrations/pushDataToKafka/pushUserDataToKafka.js (2)
27-27: Consider handling all PostgreSQL SSL modesThe current implementation only checks for
sslmode=require, but PostgreSQL supports other modes like 'prefer', 'allow', 'disable', 'verify-ca', and 'verify-full'. Consider a more comprehensive SSL configuration.- ssl: dbUrl.searchParams.get('sslmode') === 'require', + ssl: dbUrl.searchParams.get('sslmode') === 'require' ? { rejectUnauthorized: false } : false,
279-302: Consider batch processing and rate limitingProcessing users sequentially might be slow for large datasets. Consider:
- Processing in batches with controlled concurrency
- Adding rate limiting for external API calls to avoid overwhelming the entity management service
Would you like me to provide an implementation with batch processing and rate limiting using p-limit (already in your dependencies)?
src/migrations/pushDataToKafka/README.md (2)
32-35: Clarify database URL configurationThe example uses
DEV_DATABASE_URLwhich suggests development use only. Consider clarifying that this should be adjusted for different environments or use a more generic variable name likeDATABASE_URL.-DEV_DATABASE_URL=postgres://user:password@localhost:5432/database +DATABASE_URL=postgres://user:password@localhost:5432/database # Adjust for your environment
76-76: Add more details about Kafka configurationThe documentation mentions Kafka is configured via
../../configs/kafka/index.jsbut doesn't specify what Kafka environment variables or configuration are needed.Consider adding a section about required Kafka configuration (brokers, authentication, etc.) that should be present in the environment or config file.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/migrations/pushDataToKafka/README.md(1 hunks)src/migrations/pushDataToKafka/pushUserDataToKafka.js(1 hunks)src/package.json(1 hunks)
🔇 Additional comments (3)
src/package.json (1)
64-64: No security vulnerabilities found in minimist@^1.2.8All known prototype-pollution advisories (patched as of versions 0.2.4, 1.2.3, and 1.2.6) affect versions below 1.2.6. Since you’re using ^1.2.8, you’re above the last patched version and free from those vulnerabilities.
src/migrations/pushDataToKafka/pushUserDataToKafka.js (2)
34-84: LGTM!The SQL query is well-structured with proper parameterization to prevent SQL injection. The multi-join approach efficiently fetches all required data in a single query.
126-132: Consider edge cases in event type determinationThe logic assumes that when
created_atequalsupdated_at, it's a create event. However, this might not be reliable if the database allows manual timestamp updates or if there are timing precision issues.Consider adding a more explicit way to determine if this is truly a new record, perhaps by checking if this is the first time the record is being pushed to Kafka.
|
@coderabbitai review bf528ac |
Summary by CodeRabbit