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

feat: populate join column for new relation #9974

Closed
wants to merge 11 commits into from

Conversation

magrinj
Copy link
Member

@magrinj magrinj commented Feb 3, 2025

No description provided.

Copy link
Member

@charlesBochet charlesBochet left a 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

@magrinj magrinj force-pushed the feat/relation-populate-join-column branch 4 times, most recently from 3b8b4d5 to 9b88290 Compare February 13, 2025 15:15
@magrinj magrinj marked this pull request as ready for review February 13, 2025 15:24
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 replacing isRelationFieldMetadata for better type safety
  • Removes 'default' type option from field metadata interfaces in favor of strict FieldMetadataType
  • Adds joinColumnName property to FieldMetadataRelationSettings 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';
Copy link
Contributor

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"
Copy link
Contributor

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.

Suggested change
"typescript": "5.7.2"
"node": "^18.18.0",

Comment on lines +126 to +129
const joinColumnFieldMetadata = joinColumnFieldMetadataCollection.find(
(joinColumnFieldMetadata) =>
joinColumnFieldMetadata.name === `${fieldMetadata.name}Id`,
);
Copy link
Contributor

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

Comment on lines +17 to +18
IsExactly<T, FieldMetadataType> extends true
? FieldMetadataDefaultOption[] | FieldMetadataComplexOption[]
Copy link
Contributor

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.

Comment on lines +53 to +57
IsExactly<T, FieldMetadataType> extends true
? FieldMetadataDefaultSettings
: T extends keyof FieldMetadataSettingsMapping
? FieldMetadataSettingsMapping[T] & FieldMetadataDefaultSettings
: never;
Copy link
Contributor

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

Comment on lines 39 to +40
dataType: NumberDataType.INT,
} satisfies FieldMetadataSettings<FieldMetadataType.NUMBER>;
} as FieldMetadataSettings<FieldMetadataType.NUMBER>;
Copy link
Contributor

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.

Comment on lines 31 to 33
dataType: NumberDataType.FLOAT,
decimals: 6,
type: 'percentage',
Copy link
Contributor

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

Suggested change
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>,
Copy link
Contributor

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.

Comment on lines +1 to +5
export type IsExactly<T, U> = [T] extends [U]
? [U] extends [T]
? true
: false
: false;
Copy link
Contributor

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.

Suggested change
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"],
Copy link
Contributor

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.

Suggested change
"lib": ["es2020", "dom"],
"lib": ["es2018", "dom"],

@magrinj magrinj force-pushed the feat/relation-populate-join-column branch from 03ea600 to 256ad8f Compare February 14, 2025 08:45
@magrinj magrinj closed this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants