-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat: populate join column for new relation #9974
Conversation
...c/database/commands/upgrade-version/0-41/0-41-migrate-relations-to-field-metadata.command.ts
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.
Agree on what's in the PR for now, happy to re-review it when it makes sense
3b8b4d5
to
9b88290
Compare
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.
PR Summary
This PR implements significant changes to handle relation field metadata and join columns more effectively. It involves a major TypeScript upgrade and extensive type system improvements.
Key changes:
- Moves
MigrateRelationsToFieldMetadataCommand
from v0.41 to v0.42 upgrade module with enhanced join column handling - Introduces new
isFieldMetadataOfType
utilities replacingisRelationFieldMetadata
for better type safety - Removes 'default' type option from field metadata interfaces in favor of strict
FieldMetadataType
- Adds
joinColumnName
property toFieldMetadataRelationSettings
for explicit join column configuration - Updates TypeScript target to ES2018 across packages to support newer language features
The changes appear well-structured but require careful testing of upgrade paths and existing code compatibility due to the removal of the 'default' type option.
35 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
import { RemoveDuplicateMcmasCommand } from 'src/database/commands/upgrade-version/0-41/0-41-remove-duplicate-mcmas'; | ||
import { SeedWorkflowViewsCommand } from 'src/database/commands/upgrade-version/0-41/0-41-seed-workflow-views.command'; | ||
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version/0-42/0-42-migrate-relations-to-field-metadata.command'; |
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.
logic: The migration command has been moved from 0.41 to 0.42 but is still being used in the 0.41 upgrade. This could cause version compatibility issues if there are dependencies between migrations.
@@ -78,7 +78,7 @@ | |||
"rimraf": "^5.0.5", | |||
"twenty-emails": "workspace:*", | |||
"twenty-shared": "workspace:*", | |||
"typescript": "5.3.3" | |||
"typescript": "5.7.2" |
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.
logic: TypeScript 5.7.2 requires Node.js >= 18.18.0, but the engine specification on line 84 requires ^18.17.1. This could lead to compatibility issues.
"typescript": "5.7.2" | |
"node": "^18.18.0", |
const joinColumnFieldMetadata = joinColumnFieldMetadataCollection.find( | ||
(joinColumnFieldMetadata) => | ||
joinColumnFieldMetadata.name === `${fieldMetadata.name}Id`, | ||
); |
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.
style: Join column matching relies on exact name pattern. Consider adding a more flexible matching mechanism or validation for edge cases
IsExactly<T, FieldMetadataType> extends true | ||
? FieldMetadataDefaultOption[] | FieldMetadataComplexOption[] |
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.
logic: This condition will only be true when T is exactly FieldMetadataType, not when T is a specific type from FieldMetadataType. This may cause unexpected behavior when used with specific field types.
IsExactly<T, FieldMetadataType> extends true | ||
? FieldMetadataDefaultSettings | ||
: T extends keyof FieldMetadataSettingsMapping | ||
? FieldMetadataSettingsMapping[T] & FieldMetadataDefaultSettings | ||
: never; |
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.
logic: the new type checking logic using IsExactly will return FieldMetadataDefaultSettings for exact FieldMetadataType matches, which is different from the previous behavior where it would return never. This could cause type mismatches in existing code
dataType: NumberDataType.INT, | ||
} satisfies FieldMetadataSettings<FieldMetadataType.NUMBER>; | ||
} as FieldMetadataSettings<FieldMetadataType.NUMBER>; |
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.
style: Using 'as' type assertion instead of 'satisfies' reduces type safety. Consider keeping 'satisfies' to ensure type correctness at compile time.
dataType: NumberDataType.FLOAT, | ||
decimals: 6, | ||
type: 'percentage', |
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.
logic: decimals is set to 6 for percentage but label indicates 3 decimals
dataType: NumberDataType.FLOAT, | |
decimals: 6, | |
type: 'percentage', | |
dataType: NumberDataType.FLOAT, | |
decimals: 3, | |
type: 'percentage', |
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface'; | ||
|
||
export const isUUIDFieldMetadata = ( | ||
fieldMetadata: FieldMetadataInterface<any>, |
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.
style: Using any
here loses type safety. Consider using FieldMetadataType
instead, similar to other type guard utilities in the codebase.
export type IsExactly<T, U> = [T] extends [U] | ||
? [U] extends [T] | ||
? true | ||
: false | ||
: false; |
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.
style: Consider adding JSDoc comments to explain the purpose and behavior of this type utility, including examples of usage.
export type IsExactly<T, U> = [T] extends [U] | |
? [U] extends [T] | |
? true | |
: false | |
: false; | |
/** | |
* Checks if two types are exactly the same. | |
* | |
* @example | |
* type A = IsExactly<string, string>; // true | |
* type B = IsExactly<string | number, string>; // false | |
* type C = IsExactly<{ a: string }, { a: string }>; // true | |
*/ | |
export type IsExactly<T, U> = [T] extends [U] | |
? [U] extends [T] | |
? true | |
: false | |
: false; |
@@ -8,7 +8,7 @@ | |||
"emitDecoratorMetadata": true, | |||
"experimentalDecorators": true, | |||
"importHelpers": true, | |||
"target": "es2015", | |||
"target": "ES2018", | |||
"module": "esnext", | |||
"lib": ["es2020", "dom"], |
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.
style: lib includes es2020 but target is ES2018. Consider aligning these versions to avoid potential issues with TypeScript's type checking.
"lib": ["es2020", "dom"], | |
"lib": ["es2018", "dom"], |
03ea600
to
256ad8f
Compare
No description provided.