Handle migration of Phone field to Phones field (#7128)

This PR was created by [GitStart](https://gitstart.com/) to address the
requirements from this ticket:
[TWNTY-6260](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-6260).
This ticket was imported from:
[TWNTY-6260](https://github.com/twentyhq/twenty/issues/6260)

 --- 

### Description

This is the second PR on TWNTY-6260 which handles data migration of
Phone field to Phones field.\
\
How to Test?\
 Follow the below steps:

- On the main branch, 
- go to
`packages/twenty-server/src/database/typeorm-seeds/workspace/people.ts`
and change any person's phone number to a string with characters for
example: "test invalid phone", and then reset the DB.
  - reset database using `npx nx database:reset twenty-server`
- This is to make sure that invalid numbers will be handled properly. We
should use the invalid value itself to avoid removing data and see how
the behavior is on the front end. should be the same as in the main, the
display shows the invalid value, but the input is empty when you click,
and then you can update.
- Checkout to `TWNTY-6260-phone-migration` branch
- Rebuild typescript using `npx nx build twenty-server`
- Run command `yarn command:prod upgrade-0.32` to do migration
- Run both backend and frontend to see the migrated field

### Demo

- **Loom Video:**\

<https://www.loom.com/share/4b9bcb423cee447d8ad09852a83b27da?sid=ed74ecaa-0339-4575-acdc-a863e95e94fd>

### Refs

#6260

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: Marie Stoppa <marie.stoppa@essec.edu>
Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
gitstart-app[bot]
2024-09-24 16:31:30 +02:00
committed by GitHub
parent b83f0f46e5
commit fa241fa4e9
25 changed files with 709 additions and 78 deletions

View File

@ -1,5 +1,11 @@
import { EntityManager } from 'typeorm';
export const AIRBNB_ID = 'c776ee49-f608-4a77-8cc8-6fe96ae1e43f';
export const QONTO_ID = 'f45ee421-8a3e-4aa5-a1cf-7207cc6754e1';
export const STRIPE_ID = '1f70157c-4ea5-4d81-bc49-e1401abfbb94';
export const FIGMA_ID = '9d5bcf43-7d38-4e88-82cb-d6d4ce638bf0';
export const NOTION_ID = '06290608-8bf0-4806-99ae-a715a6a93fad';
export const companyPrefillData = async (
entityManager: EntityManager,
schemaName: string,
@ -8,6 +14,7 @@ export const companyPrefillData = async (
.createQueryBuilder()
.insert()
.into(`${schemaName}.company`, [
'id',
'name',
'domainNamePrimaryLinkUrl',
'addressAddressStreet1',
@ -25,6 +32,7 @@ export const companyPrefillData = async (
.orIgnore()
.values([
{
id: AIRBNB_ID,
name: 'Airbnb',
domainNamePrimaryLinkUrl: 'https://airbnb.com',
addressAddressStreet1: '888 Brannan St',
@ -40,6 +48,7 @@ export const companyPrefillData = async (
createdByName: 'System',
},
{
id: QONTO_ID,
name: 'Qonto',
domainNamePrimaryLinkUrl: 'https://qonto.com',
addressAddressStreet1: '18 rue de navarrin',
@ -55,6 +64,7 @@ export const companyPrefillData = async (
createdByName: 'System',
},
{
id: STRIPE_ID,
name: 'Stripe',
domainNamePrimaryLinkUrl: 'https://stripe.com',
addressAddressStreet1: 'Eutaw Street',
@ -70,6 +80,7 @@ export const companyPrefillData = async (
createdByName: 'System',
},
{
id: FIGMA_ID,
name: 'Figma',
domainNamePrimaryLinkUrl: 'https://figma.com',
addressAddressStreet1: '760 Market St',
@ -85,6 +96,7 @@ export const companyPrefillData = async (
createdByName: 'System',
},
{
id: NOTION_ID,
name: 'Notion',
domainNamePrimaryLinkUrl: 'https://notion.com',
addressAddressStreet1: '2300 Harrison St',

View File

@ -1,5 +1,13 @@
import { EntityManager } from 'typeorm';
import {
AIRBNB_ID,
FIGMA_ID,
NOTION_ID,
QONTO_ID,
STRIPE_ID,
} from 'src/engine/workspace-manager/standard-objects-prefill-data/company';
// FixMe: Is this file a duplicate of src/database/typeorm-seeds/workspace/people.ts
export const personPrefillData = async (
entityManager: EntityManager,
@ -18,6 +26,9 @@ export const personPrefillData = async (
'createdBySource',
'createdByWorkspaceMemberId',
'createdByName',
'phonesPrimaryPhoneNumber',
'phonesPrimaryPhoneCountryCode',
'companyId',
])
.orIgnore()
.values([
@ -32,6 +43,9 @@ export const personPrefillData = async (
createdBySource: 'MANUAL',
createdByWorkspaceMemberId: null,
createdByName: 'System',
phonesPrimaryPhoneNumber: '1234567890',
phonesPrimaryPhoneCountryCode: '+1',
companyId: AIRBNB_ID,
},
{
nameFirstName: 'Alexandre',
@ -44,6 +58,9 @@ export const personPrefillData = async (
createdBySource: 'MANUAL',
createdByWorkspaceMemberId: null,
createdByName: 'System',
phonesPrimaryPhoneNumber: '677118822',
phonesPrimaryPhoneCountryCode: '+33',
companyId: QONTO_ID,
},
{
nameFirstName: 'Patrick',
@ -56,6 +73,9 @@ export const personPrefillData = async (
createdBySource: 'MANUAL',
createdByWorkspaceMemberId: null,
createdByName: 'System',
phonesPrimaryPhoneNumber: '987625341',
phonesPrimaryPhoneCountryCode: '+1',
companyId: STRIPE_ID,
},
{
nameFirstName: 'Dylan',
@ -68,6 +88,9 @@ export const personPrefillData = async (
createdBySource: 'MANUAL',
createdByWorkspaceMemberId: null,
createdByName: 'System',
phonesPrimaryPhoneNumber: '09882261',
phonesPrimaryPhoneCountryCode: '+1',
companyId: FIGMA_ID,
},
{
nameFirstName: 'Ivan',
@ -80,6 +103,9 @@ export const personPrefillData = async (
createdBySource: 'MANUAL',
createdByWorkspaceMemberId: null,
createdByName: 'System',
phonesPrimaryPhoneNumber: '88226173',
phonesPrimaryPhoneCountryCode: '+1',
companyId: NOTION_ID,
},
])
.returning('*')

View File

@ -57,7 +57,7 @@ export const peopleAllView = async (
{
fieldMetadataId:
objectMetadataMap[STANDARD_OBJECT_IDS.person].fields[
PERSON_STANDARD_FIELD_IDS.phone
PERSON_STANDARD_FIELD_IDS.phones
],
position: 4,
isVisible: true,

View File

@ -310,6 +310,7 @@ export const PERSON_STANDARD_FIELD_IDS = {
xLink: '20202020-8fc2-487c-b84a-55a99b145cfd',
jobTitle: '20202020-b0d0-415a-bef9-640a26dacd9b',
phone: '20202020-4564-4b8b-a09f-05445f2e0bce',
phones: '34becd3e-3c51-43fa-8b6e-af39e29368ab',
city: '20202020-5243-4ffb-afc5-2c675da41346',
avatarUrl: '20202020-b8a6-40df-961c-373dc5d2ec21',
position: '20202020-fcd5-4231-aff5-fff583eaa0b1',