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

Migrate domainName field from text type to links type #6410

Merged
merged 21 commits into from
Jul 30, 2024
Merged

Conversation

ijreilly
Copy link
Collaborator

Closes #5759.

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

The pull request migrates the domainName field from a text type to a links type, allowing for multiple domain values.

  • CommandMenu.tsx: Updated to use getCompanyDomainName for fetching company logos.
  • Company.ts: Changed domainName field to support both string and link object types.
  • mapFavorites.ts: Adapted to use getCompanyDomainName for avatar URLs.
  • 0-23-migrate-domain-to-links.command.ts: Added migration command for domainName field.
  • quick-actions.service.ts: Updated enrichCompany method to handle new linked field type.

19 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@ijreilly ijreilly marked this pull request as draft July 25, 2024 15:38
@ijreilly ijreilly marked this pull request as ready for review July 25, 2024 16:02
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

(updates since last review)

The pull request migrates the domainName field from a text type to a links type, enhancing the ability to handle multiple domain values.

  • packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-migrate-domain-to-links.command.ts: Introduces a comprehensive migration command with error handling and rollback mechanisms.
  • packages/twenty-server/src/engine/api/graphql/workspace-query-runner/workspace-query-runner.service.ts: Integrates TwentyORMGlobalManager for repository operations, improving data access consistency.
  • packages/twenty-server/src/engine/twenty-orm/factories/workspace-datasource.factory.ts: Simplifies cache version logic using nullish coalescing operator.
  • packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/services/workspace-sync-object-metadata-identifiers.service.ts: Adds null check for standardId to enhance metadata retrieval robustness.
  • packages/twenty-front/src/modules/object-record/utils/sanitizeRecordInput.ts: Removes getCompanyDomainName dependency, simplifying domainName sanitization logic.

14 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

dataSourceMetadata: DataSourceEntity;
}) {
await workspaceQueryRunner.query(
`UPDATE "${dataSourceMetadata.schema}"."company" SET "${targetColumnName}" = CASE WHEN "${sourceColumnName}" LIKE 'https://%' THEN "${sourceColumnName}" ELSE 'https://' || "${sourceColumnName}" END;`,
Copy link
Member

Choose a reason for hiding this comment

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

is 'https' a requirement for LINKS fields? I'm wondering if we really want to do that otherwise? Also it might overwrite to "https://http://www.google.com" (unlikely though)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think we really want to have that https:// prefix, we add it in the front-end.
Maybe I could replace LIKE 'https://%' with LIKE 'http' to be extra safe

});

// Backfill primaryLinkLabel with empty string
await this.backfillColumnWithEmptyString({
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to set empty string? I thought this column would have a defaultValue already

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh you are right ! I added the defaultValue logic after, so until then I needed this. removing it now thanks

@@ -0,0 +1,8 @@
// temporary, to remove once domainName has been fully migrated to Links type
export const getCompanyDomainName = (company: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this one is not aligned with getCompanyDomainName from front package

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, thanks

@@ -10,6 +10,10 @@ type FieldMetadataDefaultSettings = {
isForeignKey?: boolean;
};

type FieldMetadataLinksSettings = {
isDomain?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to introduce this in this PR? I don't see where this is used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right it's not actually

@@ -159,7 +161,7 @@ export class QuickActionsService {
}

const enrichedData = await this.intelligenceService.enrichCompany(
company.domainName,
getCompanyNameFromDomainName(getCompanyDomainName(company.domainName)),
Copy link
Member

Choose a reason for hiding this comment

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

It used to work with domainName only, why do we want the name of the company now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

its a mistake, thanks for spotting this. (i think this service is not in use anymore by the way)

VALUES ($1, $2, $3, $4, $5)`,
[
companyToCreate.id,
companyToCreate.domainName,
'https://' + companyToCreate.domainName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we add 'https://' here but we don't in getExistingCompaniesByDomainNames? The get and the create should have a consistant api, either companyToCreate and domainNames should both contain https:// or they shouldn't.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had not paid attention to that, thanks.
I am replacing the query to compare the domain names without the 'https://' or 'http://' prefix; this seems safer than adding the prefix the domainNames and comparing. (although when we migrate the existing data we are adding https:// so all existing data should have a https:// prefix but still)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yet to test though, waiting on your help on how to trigger sync again

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tested !

@@ -23,7 +23,7 @@ export const companyPrefillData = async (
.values([
{
name: 'Airbnb',
domainName: 'airbnb.com',
domainNamePrimaryLinkUrl: 'airbnb.com',
Copy link
Contributor

Choose a reason for hiding this comment

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

https:// ?

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM, great job @ijreilly! 👏

Copy link
Contributor

@bosiraphael bosiraphael left a comment

Choose a reason for hiding this comment

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

LGTM

@ijreilly ijreilly merged commit 8e35eda into main Jul 30, 2024
14 checks passed
@ijreilly ijreilly deleted the migrate-domain branch July 30, 2024 09:47
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.

Migrate Domain Field to the new Link Field Type
4 participants