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

Migration Carpool V2 : CEE Applications #2484

Merged
merged 16 commits into from
May 19, 2024
Merged

Conversation

jonathanfallon
Copy link
Member

@jonathanfallon jonathanfallon commented May 3, 2024

#2474

Summary by CodeRabbit

  • New Features

    • Added a new migration script to introduce journey_id column in the database.
    • Introduced a function to convert Carpool V2 statuses to Carpool V1 statuses.
    • Added a verbose logging option for database migrations.
    • New target drop_test_databases added for easier test database management.
  • Bug Fixes

    • Corrected typos and improved status handling in Carpool and Cee services.
  • Chores

    • Updated .gitignore to ignore .pgclirc files.
    • Simplified Docker Compose version declarations for development and end-to-end testing.
  • Tests

    • Added comprehensive test cases for status conversion and Cee application registration.
  • Documentation

    • Added deprecation notices and updated interface documentation for Carpool and Cee services.

Copy link
Contributor

coderabbitai bot commented May 3, 2024

Walkthrough

This update introduces several enhancements and fixes across the project. Key changes include adding .pgclirc to .gitignore, updating VS Code settings for TypeScript imports, and adding a new drop_test_databases target in the justfile. Significant modifications were made to the database schema and migrations, particularly for the cee_applications table. Additionally, various updates were made to TypeScript files to handle Carpool V2 and V1 status conversions, improve repository methods, and enhance test configurations.

Changes

File(s) Change Summary
.gitignore Added .pgclirc to ignored files.
.vscode/settings.json Updated TypeScript import settings and path mappings.
api/justfile Added drop_test_databases target.
api/src/db/migrations/...add_journey_id_column.js Added migration script for journey_id column.
api/src/db/migrations/cee/...add_journey_id_column.*.sql Modified schema for operator_journey_id and indexes.
api/src/pdc/providers/carpool/helpers/...StatusConverter.*.ts Added status converter function and tests for Carpool V2 to V1.
api/src/pdc/providers/carpool/interfaces/common.ts Deprecated CarpoolV1StatusEnum.
api/src/pdc/providers/seed/Migrator.ts Added verbose property for conditional logging.
api/src/pdc/providers/test/dbMacro.ts Conditional database retention based on environment variable.
api/src/pdc/services/cee/actions/RegisterCeeAction.*.ts Updated imports, fixed typos, and enhanced status handling.
api/src/pdc/services/cee/interfaces/CeeRepositoryProviderInterface.ts Added fields and updated types in interfaces.
api/src/pdc/services/cee/providers/CeeRepositoryProvider.*.ts Updated SQL queries and table references.
docker-compose.*.yml Adjusted version declarations.
flake.nix Added postgresql_14 package.
shared/cee/common/CeeApplicationInterface.ts Updated types and corrected typos in interface names.
shared/cee/registerApplication.contract.ts Corrected typos in import statements and interface names.

🐇
In the code, a journey's begun,
With columns and tables, a new run.
TypeScript's imports now align,
Carpool statuses intertwine.
Databases drop on command,
All changes, perfectly planned.
Let's code, let's build, let's shine! 🌟
🐇


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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@jonathanfallon jonathanfallon force-pushed the carpool_v2_fix/cee branch 2 times, most recently from 1def6d9 to a514fdd Compare May 7, 2024 23:28
@jonathanfallon jonathanfallon marked this pull request as ready for review May 19, 2024 13:26
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

Out of diff range and nitpick comments (5)
api/src/pdc/providers/test/dbMacro.ts (1)

39-40: Consider documenting the APP_POSTGRES_KEEP_TEST_DATABASES environment variable in the project's README for clarity.

api/justfile (1)

143-143: Consider documenting the drop_test_databases target in the project's README to guide developers on its usage.

api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts (2)

154-176: Optimize the SQL query in searchForValidJourney.

Consider using a SQL view or a stored procedure if this query is used frequently, to improve performance and maintainability.


326-340: Mark deprecated code clearly and plan for removal.

Consider adding a timeline or conditions under which this deprecated code can be safely removed to avoid future maintenance issues.

api/src/pdc/providers/seed/Migrator.ts (1)

79-79: Improve logging consistency.

Consider using a dedicated logging library instead of console.debug for better control over logging levels and outputs.

Also applies to: 84-84, 88-88, 92-92, 97-97, 102-102, 107-107, 111-111

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 50bb296 and af61188.
Files selected for processing (22)
  • .gitignore (1 hunks)
  • .vscode/settings.json (2 hunks)
  • api/justfile (1 hunks)
  • api/src/db/migrations/20240425112600-add_journey_id_column.js (1 hunks)
  • api/src/db/migrations/cee/20240425112600-add_journey_id_column.down.sql (1 hunks)
  • api/src/db/migrations/cee/20240425112600-add_journey_id_column.up.sql (1 hunks)
  • api/src/pdc/providers/carpool/helpers/carpoolV2ToV1StatusConverter.spec.ts (1 hunks)
  • api/src/pdc/providers/carpool/helpers/carpoolV2ToV1StatusConverter.ts (1 hunks)
  • api/src/pdc/providers/carpool/interfaces/common.ts (1 hunks)
  • api/src/pdc/providers/seed/Migrator.ts (3 hunks)
  • api/src/pdc/providers/test/dbMacro.ts (1 hunks)
  • api/src/pdc/services/cee/actions/RegisterCeeAction.integration.spec.ts (3 hunks)
  • api/src/pdc/services/cee/actions/RegisterCeeAction.ts (5 hunks)
  • api/src/pdc/services/cee/interfaces/CeeRepositoryProviderInterface.ts (4 hunks)
  • api/src/pdc/services/cee/providers/CeeRepositoryProvider.integration.spec.ts (10 hunks)
  • api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts (10 hunks)
  • docker-compose.dev.yml (1 hunks)
  • docker-compose.e2e.yml (1 hunks)
  • docker-compose.yml (1 hunks)
  • flake.nix (1 hunks)
  • shared/cee/common/CeeApplicationInterface.ts (2 hunks)
  • shared/cee/registerApplication.contract.ts (1 hunks)
Files skipped from review due to trivial changes (7)
  • .gitignore
  • .vscode/settings.json
  • api/src/db/migrations/20240425112600-add_journey_id_column.js
  • api/src/db/migrations/cee/20240425112600-add_journey_id_column.down.sql
  • docker-compose.dev.yml
  • docker-compose.yml
  • shared/cee/registerApplication.contract.ts
Additional comments not posted (19)
flake.nix (1)

23-23: Addition of postgresql_14 aligns with the database migration needs.

api/src/pdc/providers/carpool/helpers/carpoolV2ToV1StatusConverter.ts (2)

1-36: The status conversion function is well-implemented and documented.


34-36: Check related files for consistency with the status conversion logic.

Verification successful

To verify the consistency of the status conversion logic, we need to review the logic in carpoolV2ToV1StatusConverter.ts and compare it with the logic in castStatus.ts and getStatus.ts.

Let's start by examining the logic in carpoolV2ToV1StatusConverter.ts.


The logic in carpoolV2ToV1StatusConverter.ts appears to be consistent with the logic in castStatus.ts and getStatus.ts. Here are the key points of comparison:

  • Fraud Status Handling:

    • carpoolV2ToV1StatusConverter.ts checks if fraud_status is Failed and returns FraudcheckError.
    • castStatus.ts maps fraudcheck_error to FraudError.
  • Acquisition Status Handling:

    • Both files handle statuses like Received, Updated, Processed, Failed, Canceled, and Expired similarly, mapping them to corresponding enums.
  • General Status Mapping:

    • The mapping logic in carpoolV2ToV1StatusConverter.ts aligns with the status conversion logic in castStatus.ts.

Given this consistency, the status conversion logic across these files appears to be coherent.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify related files for consistent status conversion logic.

# Test: Search for related files and check their content.
cat api/src/pdc/services/acquisition/helpers/castStatus.ts
cat api/src/pdc/services/carpool/helpers/getStatus.ts

Length of output: 2845



Script:

#!/bin/bash
# Description: Display the content of carpoolV2ToV1StatusConverter.ts for review.

cat api/src/pdc/providers/carpool/helpers/carpoolV2ToV1StatusConverter.ts

Length of output: 1325

api/src/pdc/providers/test/dbMacro.ts (1)

37-48: Logic to conditionally keep or drop test databases is correctly implemented.

api/src/pdc/providers/carpool/interfaces/common.ts (1)

56-70: Deprecation of CarpoolV1StatusEnum is clearly documented and correctly implemented.

shared/cee/common/CeeApplicationInterface.ts (1)

Line range hint 1-16: Updates to CEE application interfaces align with Carpool V2 migration requirements.

api/src/db/migrations/cee/20240425112600-add_journey_id_column.up.sql (1)

1-71: SQL migration script correctly implements the addition of operator_journey_id and related schema changes.

api/src/pdc/services/cee/interfaces/CeeRepositoryProviderInterface.ts (1)

Line range hint 1-116: Interface updates in CeeRepositoryProviderInterface correctly reflect the new database schema and Carpool V2 migration.

api/justfile (1)

139-149: Addition of drop_test_databases target provides a useful utility for managing test databases.

api/src/pdc/providers/carpool/helpers/carpoolV2ToV1StatusConverter.spec.ts (1)

1-114: Comprehensive test coverage for status conversion logic.

api/src/pdc/services/cee/actions/RegisterCeeAction.ts (2)

155-155: Correctly updated method to handle long CEE applications.


121-121: Successfully integrated new status conversion in short application processing.

Also applies to: 122-122

docker-compose.e2e.yml (1)

1-1: Correct configuration for end-to-end testing environment.

api/src/pdc/services/cee/actions/RegisterCeeAction.integration.spec.ts (1)

Line range hint 1-243: Comprehensive integration tests covering various scenarios for CEE application registration.

api/src/pdc/services/cee/providers/CeeRepositoryProvider.integration.spec.ts (1)

Line range hint 1-465: Thorough integration tests for CeeRepositoryProvider covering all critical functionalities.

api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts (3)

3-3: Ensure the new import Uuid is utilized appropriately in the file.

Verification successful

The new import Uuid is utilized appropriately in the file CeeRepositoryProvider.ts.

  • Uuid is used in the type annotation for the query result.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `Uuid` is used correctly in the file.

# Test: Search for the usage of `Uuid`. Expect: Proper usage in type annotations or variable assignments.
rg --type typescript $'Uuid' api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts

Length of output: 122



Script:

#!/bin/bash
# Description: Verify that `Uuid` is used correctly in the file.

# Test: Search for the usage of `Uuid`. Expect: Proper usage in type annotations or variable assignments.
rg --type ts 'Uuid' api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts

Length of output: 216


24-32: Update table names to reflect new database schema.

Ensure that all references to these tables in SQL queries are updated accordingly.


304-310: Ensure proper handling of conflict scenarios.

Verification successful

The current implementation uses ON CONFLICT DO NOTHING to handle conflicts, which means it ignores conflicts without any additional handling. However, the subsequent code checks if the row count is not equal to 1 and throws a ConflictException if no record was inserted, indicating that another record is already active.

  • Lines of interest:
    • ON CONFLICT DO NOTHING
    • if (res.rowCount !== 1) { throw new ConflictException(); }

This approach ensures that conflicts are detected and handled appropriately by throwing an exception when necessary.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the conflict handling logic in SQL queries.

# Test: Check if the conflict handling logic is robust and covers all necessary cases.
rg --type typescript $'ON CONFLICT' api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts

Length of output: 131



Script:

#!/bin/bash
# Description: Verify the conflict handling logic in SQL queries.

# Test: Check if the conflict handling logic is robust and covers all necessary cases.
rg --type ts 'ON CONFLICT' api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts

Length of output: 117



Script:

#!/bin/bash
# Description: Extract surrounding code to understand the context of 'ON CONFLICT DO NOTHING'.

# Extract 10 lines before and after the match to understand the context.
rg --type ts -C 10 'ON CONFLICT DO NOTHING' api/src/pdc/services/cee/providers/CeeRepositoryProvider.ts

Length of output: 715

api/src/pdc/providers/seed/Migrator.ts (1)

25-25: Ensure the new verbose configuration is used appropriately.

Also applies to: 40-40

Verification successful

The verbose configuration is used appropriately to control logging in the Migrator.ts file.

  • Lines where verbose is used to conditionally log messages:
    • this.config.verbose && console.debug('Seeding company ${company.legal_name}')
    • this.config.verbose && console.debug('Seeding geo')
    • this.config.verbose && console.debug('Seeding operator ${operator.name}')
    • this.config.verbose && console.debug('Seeding user ${user.email}')
    • this.config.verbose && console.debug('Seeding territory group ${territory_group.name}')
    • this.config.verbose && console.debug('Seeding carpool ${carpool.acquisition_id}')
    • this.config.verbose && console.debug('Seeding carpool ${carpool[0].acquisition_id}')
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `verbose` configuration is used correctly to control logging.

# Test: Search for the usage of `verbose`. Expect: Conditional logging based on this flag.
rg --type typescript $'verbose' api/src/pdc/providers/seed/Migrator.ts

Length of output: 104



Script:

#!/bin/bash
# Description: Verify that the `verbose` configuration is used correctly to control logging.

# Test: Search for the usage of `verbose`. Expect: Conditional logging based on this flag.
rg --type ts 'verbose' api/src/pdc/providers/seed/Migrator.ts

Length of output: 678

@jonathanfallon jonathanfallon merged commit 0628973 into main May 19, 2024
8 checks passed
@jonathanfallon jonathanfallon deleted the carpool_v2_fix/cee branch May 19, 2024 16:16
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.

None yet

1 participant