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 relation join column #10212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

magrinj
Copy link
Member

@magrinj magrinj commented Feb 14, 2025

Copy link
Contributor

github-actions bot commented Feb 14, 2025

TODOs/FIXMEs:

  • // TODO: Fix this, it's working in other places but not here: packages/twenty-server/src/database/commands/upgrade-version/0-42/0-42-migrate-relations-to-field-metadata.command.ts
  • // TODO: Fix this, it's working in other places but not here: packages/twenty-server/src/database/commands/upgrade-version/0-42/0-42-migrate-relations-to-field-metadata.command.ts

Generated by 🚫 dangerJS against ecb8f88

@magrinj magrinj marked this pull request as ready for review February 14, 2025 09:47
@magrinj magrinj force-pushed the feat/populate-relation-join-column branch from a0efa3e to ecb8f88 Compare February 14, 2025 09:53
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 introduces significant changes to the field metadata and relation handling system. Here's a summary of the key changes:

The PR moves the MigrateRelationsToFieldMetadataCommand from version 0.41 to 0.42 while introducing support for relation join columns and improved type safety.

Key points to consider:

  • Dependency injection will fail in 0.41 upgrade module since the command is still referenced but removed from providers
  • The removal of 'default' type option across multiple files could break existing code that relies on this type
  • The PR introduces a new IsExactly type utility but weakens type safety in some places by replacing satisfies with as assertions
  • The PR title/description doesn't accurately reflect the scope of changes being made to the metadata system
  • The changes to upgrade version handling (0.41 -> 0.42) could cause issues for users following specific upgrade paths

The changes appear technically sound but require careful consideration of backwards compatibility and upgrade paths.

29 file(s) reviewed, 6 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: Command imported from 0.42 but used in 0.41 upgrade. This could cause version compatibility issues if 0.42 features are required.

@@ -7,6 +7,8 @@ import { MigrateRichTextFieldCommand } from 'src/database/commands/upgrade-versi
import { UpgradeTo0_42Command } from 'src/database/commands/upgrade-version/0-42/0-42-upgrade-version.command';
import { FeatureFlag } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version/0-42/0-42-migrate-relations-to-field-metadata.command';
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: TypeORMModule is imported but not used in the module's imports array. Either add it to imports or remove if not needed.

Suggested change
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';

Comment on lines +89 to +91
isFieldMetadataOfType(fieldMetadata, FieldMetadataType.UUID),
// TODO: Fix this, it's working in other places but not here
) as FieldMetadataEntity<FieldMetadataType.UUID>[];
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 TODO indicates isFieldMetadataOfType is not working here but is working elsewhere. This inconsistency needs investigation as it could lead to incorrect type filtering. Consider removing the type assertion if the function is fixed.

Comment on lines 75 to +76
@Field(() => FieldMetadataType)
type: FieldMetadataType;
type: T;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Changing type to T ensures type-safety between the generic parameter and the actual field type. However, this could potentially break existing code that expects type to be FieldMetadataType.

@@ -59,7 +59,7 @@ export class FieldMetadataEntity<
nullable: false,
type: 'varchar',
})
type: FieldMetadataType;
type: T;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Changing type to T could cause runtime type checking issues if T doesn't match the actual database value. Consider adding a runtime type guard.

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 instead of satisfies removes compile-time type checking. Consider keeping satisfies for better type safety.

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.

[RelationMetadata] - Add a new property joinColumnName for ONE_TO_MANY
1 participant