-
Notifications
You must be signed in to change notification settings - Fork 577
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
Conversation
WalkthroughThe changes refactor and enhance task-related data structures by separating the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 newcreatedByUserId
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 ofcreatedByUserId
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 tsLength of output: 3337
LGTM for
import.service.ts
update – foreign key mapping now correctly usescreatedByUserId
.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
andpackages/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
tocreatedByUserId
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
tocreatedByUser
maintains consistency with the broader renaming initiative.
155-155
: LGTM! Property rename in createRandomTask is consistent.The change from
creator
tocreatedByUser
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
tocreatedByUserId
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
tocreatedByUserIds
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
andisScreeningTask
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
tocreatedByUserId
andcreators
tocreatedByUserIds
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:
- Dropping the existing constraint and index
- Renaming the column
- Creating new indexes
- 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
.../core/src/lib/database/migrations/1740146592586-AlterOrganizationProjectModuleEntityTable.ts
Outdated
Show resolved
Hide resolved
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: 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 usingconsole.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
📒 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 tocreatorId
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.
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: 0
🧹 Nitpick comments (3)
packages/core/src/lib/database/migrations/1740374349632-AlterTaskEntityTable.ts (3)
1-3
: Consider using a standardized logger instead ofconsole.log
.
Usingchalk
plusconsole.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 thedown
migration.
Currently, theup
method prints a start message, whereas thedown
method provides no console feedback. Consider printing a similar message in thedown
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
📒 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 tocreatedByUserId
withON 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 oldcreatorId
column to the newcreatedByUserId
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 = [], |
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.
@GloireMutaliko21 We changed into some filters. So please change it according to other projects.
View your CI Pipeline Execution ↗ for commit 4c484e2.
☁️ Nx Cloud last updated this comment at |
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