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

[Fix] Alter "Task" Entity Table #8800

Merged
merged 3 commits into from
Feb 24, 2025
Merged

[Fix] Alter "Task" Entity Table #8800

merged 3 commits into from
Feb 24, 2025

Conversation

rahul-rocket
Copy link
Collaborator

@rahul-rocket rahul-rocket commented Feb 24, 2025

PR

Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.


Summary by CodeRabbit

  • New Features
    • Expanded task details with additional attributes like title, number, and status, enabling more informative task tracking.
  • Refactor
    • Unified naming for task creator data to ensure clear and consistent identification in task logs and notifications.
  • Chores
    • Applied a seamless database migration to update the task structure, supporting improved performance and stability.

Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Walkthrough

The changes refactor and enhance task-related data structures by separating the ITask interface into two interfaces and adding new enumerations and properties in the task model. Several files now consistently use createdByUserId instead of creatorId across events, queries, and foreign key mappings. Formatting updates have been applied to DTO declarations and import statements. A new database migration file provides structured alterations to the task table to support these changes.

Changes

File(s) Change Summary
contracts/.../task.model.ts Refactored ITask into IBaseTaskProperties and ITaskAssociations; added TaskParticipantEnum; updated property names (e.g., removed creator/creatorId, replaced with createdByUserId in filters).
core/.../task.entity.ts Introduced new properties (e.g., title, number, prefix, description, status, priority, etc.); standardized comments; added createdByUser and createdByUserId fields.
core/.../commands/handlers/{automation-task.sync.handler, task-create.handler}.ts,
core/.../tasks/screening-tasks/screening-tasks.service.ts,
core/.../tasks/task.service.ts,
core/.../tasks/task.subscriber.ts,
plugins/.../hubstaff.service.ts
Consistently renamed creatorId to createdByUserId in event publishing, query conditions, task creation logic, and subscriber logic.
core/.../tasks/dto/{task-max-number-query.dto, update-task.dto}.ts,
core/.../export-import/import/import.service.ts
Reformatted DTO class declarations and import statements (switched to single quotes); updated foreign key mapping from creatorId to createdByUserId.
core/.../activity-log/activity-log.service.ts Updated comment in the create method to clarify that the log entry is created using employeeId and tenantId instead of creatorId.
core/.../tasks/task.seed.ts Updated task seeding functions by renaming task.creator to task.createdByUser in default and random task creation.
core/.../database/migrations/1740374349632-AlterTaskEntityTable.ts Added a migration file that alters the task table by renaming columns, modifying constraints, and updating indexes based on the database type.

Possibly related PRs

Suggested labels

hold

Suggested reviewers

  • GloireMutaliko21

Oh, hopping through the code at night,
I found changes shining with delight,
Renaming fields with nimble paws,
Structuring tasks without a flaw,
A migration hop and a DTO tweak,
In fields we trust—oh rabbit, so chic!
🐇✨ Happy to code with a joyful beat!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a2306cf and ce93d01.

📒 Files selected for processing (14)
  • packages/contracts/src/lib/task.model.ts (4 hunks)
  • packages/core/src/lib/activity-log/activity-log.service.ts (1 hunks)
  • packages/core/src/lib/database/migrations/1740146592586-AlterOrganizationProjectModuleEntityTable.ts (1 hunks)
  • packages/core/src/lib/export-import/import/import.service.ts (1 hunks)
  • packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (1 hunks)
  • packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (3 hunks)
  • packages/core/src/lib/tasks/dto/task-max-number-query.dto.ts (1 hunks)
  • packages/core/src/lib/tasks/dto/update-task.dto.ts (1 hunks)
  • packages/core/src/lib/tasks/screening-tasks/screening-tasks.service.ts (1 hunks)
  • packages/core/src/lib/tasks/task.entity.ts (10 hunks)
  • packages/core/src/lib/tasks/task.seed.ts (2 hunks)
  • packages/core/src/lib/tasks/task.service.ts (4 hunks)
  • packages/core/src/lib/tasks/task.subscriber.ts (1 hunks)
  • packages/plugins/integration-hubstaff/src/lib/hubstaff.service.ts (2 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/core/src/lib/activity-log/activity-log.service.ts
  • packages/core/src/lib/tasks/dto/update-task.dto.ts
  • packages/core/src/lib/tasks/dto/task-max-number-query.dto.ts
  • packages/plugins/integration-hubstaff/src/lib/hubstaff.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
  • GitHub Check: build
🔇 Additional comments (18)
packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts (1)

162-162: LGTM! Correctly using the new createdByUserId property.

The change maintains consistency with the new naming convention for user ID references.

packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts (1)

127-127: LGTM! Consistent usage of createdByUserId across all event types.

The changes maintain consistency in user ID references across mention, subscription, and notification events.

Also applies to: 141-141, 180-180

packages/core/src/lib/export-import/import/import.service.ts (1)

2065-2065:

❓ Verification inconclusive

LGTM! Foreign key mapping correctly updated.

The foreign key mapping has been updated to use createdByUserId, maintaining consistency with the new naming convention.

Run this script to verify that all task-related foreign key references have been updated:


🏁 Script executed:

#!/bin/bash
# Search for any remaining references to 'creatorId' in task-related files
rg -l "creatorId" --type ts

Length of output: 3337


LGTM for import.service.ts update – foreign key mapping now correctly uses createdByUserId.

I ran a global search for "creatorId" and noticed several occurrences in task-related files (e.g., migration scripts, models, and task services). These instances mostly appear in legacy or migration files, which may be intentionally retained for historical reasons. Please verify that these remaining "creatorId" references are expected and do not require renaming to align with the new convention.

  • Files to verify (non-exhaustive list):
    • packages/contracts/src/lib/screening-task.model.ts
    • Various migration files under packages/core/src/lib/database/migrations/
    • Task-related service and model files in both packages/core and packages/desktop-lib
packages/core/src/lib/tasks/task.subscriber.ts (1)

52-52: LGTM! Property rename is consistent with codebase changes.

The change from creatorId to createdByUserId aligns with the broader renaming initiative across the codebase, maintaining consistency in how task creators are referenced.

packages/core/src/lib/tasks/task.seed.ts (2)

72-72: LGTM! Property rename in createDefaultTask is consistent.

The change from creator to createdByUser maintains consistency with the broader renaming initiative.


155-155: LGTM! Property rename in createRandomTask is consistent.

The change from creator to createdByUser in the random task creation maintains consistency with the broader renaming initiative.

packages/core/src/lib/tasks/task.service.ts (2)

1045-1045: LGTM! Property rename in getTasksByDateFilters is consistent.

The change from creatorId to createdByUserId in both the method parameters and query conditions maintains consistency.

Also applies to: 1071-1072


1147-1147: LGTM! Property rename in buildAdvancedWhereCondition is consistent.

The change from creators to createdByUserIds in the filter conditions maintains consistency with the new naming convention.

Also applies to: 1163-1163

packages/contracts/src/lib/task.model.ts (4)

20-23: LGTM! TaskParticipantEnum is well-defined.

The enum clearly defines the possible types of task participants.


25-42: Good separation of concerns in IBaseTaskProperties.

The interface effectively combines base entity properties with task-specific attributes. The addition of isDraft and isScreeningTask with clear documentation improves code clarity.


44-53: Well-structured ITaskAssociations interface.

The interface cleanly separates task associations from base properties, making the code more maintainable and easier to understand.


101-101: LGTM! Property renames are consistent.

The changes from creatorId to createdByUserId and creators to createdByUserIds maintain consistency across the codebase.

Also applies to: 122-122

packages/core/src/lib/database/migrations/1740146592586-AlterOrganizationProjectModuleEntityTable.ts (2)

59-67: LGTM! Well-structured PostgreSQL migration.

The migration properly handles the column rename operation by:

  1. Dropping the existing constraint and index
  2. Renaming the column
  3. Creating new indexes
  4. Adding the foreign key constraint with appropriate cascade rules

75-83: LGTM! Properly implemented down migration.

The down migration correctly reverses all changes in the proper order, ensuring the migration is fully reversible.

packages/core/src/lib/tasks/task.entity.ts (4)

71-215: LGTM! Well-documented and properly validated properties.

The entity properties are well-defined with:

  • Clear JSDoc comments explaining each property
  • Appropriate validation decorators
  • Consistent use of optional flags

397-414: LGTM! Well-structured relationship with User entity.

The new createdByUser relationship is properly defined with:

  • Appropriate cascade rules for user deletion
  • Proper indexing of the foreign key
  • Clear documentation

483-557: LGTM! Well-defined many-to-many relationships.

The many-to-many relationships are properly configured with:

  • Explicit join table names
  • Consistent cascade rules
  • Appropriate ownership settings

66-68: LGTM! Well-structured entity definition.

The Task entity is well-defined with:

  • Proper interface implementation
  • Appropriate database indexing
  • Clear organization of decorators

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: 0

🧹 Nitpick comments (5)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (5)

1-4: Consider removing chalk in production migrations
While console logs can be helpful, in production-grade migrations we often minimize external dependencies for simpler maintainability. If you only need basic logging, you could consider using console.log or the built-in logger from TypeORM instead.


8-30: Add more robust error reporting for the "up" migration
While your switch statement cleanly routes by database type, you may want to add additional logging or error handling to clarify partial successes if one or more steps fail. This can be critical when debugging multi-step migrations.


86-215: Consider refactoring the SQLite up migration to avoid repetitive index drops
You’ve implemented a thorough approach to recreating the table and indexes for SQLite, but there is a lot of repetitive dropping, re-insertion, and re-creation of indexes. For readability and maintainability, consider extracting repeated logic (like re-creating indexes) into a helper function or a shared method within the migration file.


217-346: Reduce duplication in the SQLite down migration
Similar to the “up” migration, the “down” migration also contains repeated patterns for dropping and re-creating indexes and tables. A small refactoring could consolidate these into reusable code blocks, improving clarity.


348-361: MySQL support is not yet implemented
The placeholders for MySQL migrations are empty. If MySQL is required, this migration will remain incomplete.

Do you want me to propose a MySQL-specific implementation for both up and down methods or open a new issue to track this task?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ce93d01 and d4afcfc.

📒 Files selected for processing (1)
  • packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (2)
Learnt from: rahul-rocket
PR: ever-co/ever-gauzy#8800
File: packages/core/src/lib/database/migrations/1740146592586-AlterOrganizationProjectModuleEntityTable.ts:0-0
Timestamp: 2025-02-24T05:26:43.208Z
Learning: SQLite and MySQL migration implementations for the Task entity table alterations will be added in subsequent commits. This is an intentional decision to implement the changes incrementally.
Learnt from: rahul-rocket
PR: ever-co/ever-gauzy#8769
File: packages/core/src/lib/database/migrations/1739364133493-AlterCommentEntityTable.ts:658-659
Timestamp: 2025-02-13T16:48:54.177Z
Learning: TypeORM-generated migrations may use different data types for UUID fields (uuid in PostgreSQL, varchar(255) in MySQL) as this is handled by TypeORM's migration generator and is the standard practice across the packages.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
  • GitHub Check: build
🔇 Additional comments (4)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (4)

5-7: Class naming is coherent
The migration class name and exported symbol are consistent, which eases traceability.


32-52: Good symmetry in the “down” method
The “down” migration complements the “up” migration well, making rollback straightforward.


59-68: Validate the newly created constraints
Dropping and recreating constraints and indexes can introduce discrepancies if references or constraints have changed in other parts of the schema. It might be prudent to confirm that no references to creatorId remain in the rest of the codebase.


70-84: Rollback logic is consistent
Your rollback approach properly reverts the schema to the original references and indexes.

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: 0

🧹 Nitpick comments (3)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (3)

1-3: Consider using a standardized logger instead of console.log.
Using chalk plus console.log is convenient for local development, but if you're running migrations programmatically or in a CI/CD pipeline, you may lose some logging benefits and consistency.


13-30: Optional: add matching logging for the down migration.
Currently, the up method prints a start message, whereas the down method provides no console feedback. Consider printing a similar message in the down method for consistency.


86-215: Note the multi-step process for renaming columns in SQLite.
Because SQLite doesn’t support native column renames, this approach creates a temporary table, copies data, and re-creates indexes. If your table contains significant data, migration performance could be impacted.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4afcfc and 4c484e2.

📒 Files selected for processing (1)
  • packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (1)
Learnt from: rahul-rocket
PR: ever-co/ever-gauzy#8769
File: packages/core/src/lib/database/migrations/1739364133493-AlterCommentEntityTable.ts:658-659
Timestamp: 2025-02-13T16:48:54.177Z
Learning: TypeORM-generated migrations may use different data types for UUID fields (uuid in PostgreSQL, varchar(255) in MySQL) as this is handled by TypeORM's migration generator and is the standard practice across the packages.
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
  • GitHub Check: build
🔇 Additional comments (4)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (4)

60-68: Validate ON DELETE CASCADE behavior.
When you drop and recreate the foreign key to createdByUserId with ON DELETE CASCADE, it means all tasks will be removed if the user is deleted. Verify that this is the intended behavior, as it might result in unexpected data loss.


148-153: Confirm data integrity while inserting into the new table.
This block copies data from the old creatorId column to the new createdByUserId column. Double-check that all rows are copied properly and that no records are dropped in the process.


216-346: Recheck index drops and re-creation for correctness.
Indexes are dropped and re-created multiple times. This is standard for SQLite migrations but verify that all relevant indexes are properly restored at the end, especially the unique “taskNumber” index.


354-361: Check MySQL foreign key constraints.
Like PostgreSQL, each time the foreign key is recreated, ON DELETE CASCADE applies. Confirm if consistent cross-database behavior (i.e., unblocking or blocking deletions) is truly desired, as this can cause irreversible deletion of dependent tasks.

@@ -1144,7 +1144,7 @@ export class TaskService extends TenantAwareCrudService<Task> {
priorityIds = [],
sizeIds = [],
parentIds = [],
creators = [],
createdByUserIds = [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GloireMutaliko21 We changed into some filters. So please change it according to other projects.

@rahul-rocket rahul-rocket merged commit 8d7d4f1 into develop Feb 24, 2025
15 of 16 checks passed
@rahul-rocket rahul-rocket deleted the fix/alter-task-entity branch February 24, 2025 06:03
Copy link

nx-cloud bot commented Feb 24, 2025

View your CI Pipeline Execution ↗ for commit 4c484e2.

Command Status Duration Result
nx build gauzy -c=production --prod --verbose ✅ Succeeded 4m 1s View ↗
nx build api -c=production --prod ✅ Succeeded 1m 11s View ↗
nx build desktop-ui-lib --configuration=develop... ✅ Succeeded 30s View ↗
nx build desktop-ui-lib --configuration=production ✅ Succeeded 27s View ↗
nx build plugin-integration-wakatime ✅ Succeeded 4s View ↗
nx build desktop-lib ✅ Succeeded 6s View ↗
nx build desktop-window ✅ Succeeded <1s View ↗
nx build desktop-core ✅ Succeeded <1s View ↗
Additional runs (52) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-24 06:25:45 UTC

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.

1 participant