diff --git a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts index 8e9a7c7ca147..96506be7fa2a 100644 --- a/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts +++ b/packages/twenty-server/src/database/commands/data-seed-dev-workspace.command.ts @@ -17,6 +17,12 @@ import { SeedAppleWorkspaceId, SeedTwentyWorkspaceId, } from 'src/database/typeorm-seeds/core/workspaces'; +import { seedConnectedAccount } from 'src/database/typeorm-seeds/workspace/connectedAccount'; +import { seedMessage } from 'src/database/typeorm-seeds/workspace/message'; +import { seedMessageChannel } from 'src/database/typeorm-seeds/workspace/messageChannel'; +import { seedMessageChannelMessageAssociation } from 'src/database/typeorm-seeds/workspace/messageChannelMessageAssociation'; +import { seedMessageParticipant } from 'src/database/typeorm-seeds/workspace/messageParticipant'; +import { seedMessageThread } from 'src/database/typeorm-seeds/workspace/messageThread'; import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view'; // TODO: implement dry-run @@ -117,7 +123,6 @@ export class DataSeedWorkspaceCommand extends CommandRunner { dataSourceMetadata.schema, workspaceId, ); - await viewPrefillData( entityManager, dataSourceMetadata.schema, @@ -129,6 +134,34 @@ export class DataSeedWorkspaceCommand extends CommandRunner { console.error(error); } + try { + if (workspaceId === SeedAppleWorkspaceId) { + await seedMessageThread( + workspaceDataSource, + dataSourceMetadata.schema, + ); + await seedConnectedAccount( + workspaceDataSource, + dataSourceMetadata.schema, + ); + await seedMessage(workspaceDataSource, dataSourceMetadata.schema); + await seedMessageChannel( + workspaceDataSource, + dataSourceMetadata.schema, + ); + await seedMessageChannelMessageAssociation( + workspaceDataSource, + dataSourceMetadata.schema, + ); + await seedMessageParticipant( + workspaceDataSource, + dataSourceMetadata.schema, + ); + } + } catch (error) { + console.error(error); + } + await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id); } } diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/connectedAccount.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/connectedAccount.ts new file mode 100644 index 000000000000..b4ac50e96d44 --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/connectedAccount.ts @@ -0,0 +1,64 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'connectedAccount'; + +export const seedConnectedAccount = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + 'lastSyncHistoryId', + 'accountOwnerId', + 'refreshToken', + 'accessToken', + 'provider', + 'handle', + ]) + .orIgnore() + .values([ + { + id: '6773281b-9ac0-4390-9a1a-ab4d2c4e1bb7', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + lastSyncHistoryId: 'exampleLastSyncHistory', + accountOwnerId: '20202020-0687-4c41-b707-ed1bfca972a7', + refreshToken: 'exampleRefreshToken', + accessToken: 'exampleAccessToken', + provider: 'google', + handle: 'incoming', + }, + { + id: '67373de8-0cc8-4d60-a3a4-803245698908', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + lastSyncHistoryId: 'exampleLastSyncHistory', + accountOwnerId: '20202020-77d5-4cb6-b60a-f4a835a85d61', + refreshToken: 'exampleRefreshToken', + accessToken: 'exampleAccessToken', + provider: 'google', + handle: 'incoming', + }, + { + id: 'f2a8cf93-cafc-4323-908d-e5b42ad69fdf', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + lastSyncHistoryId: 'exampleLastSyncHistory', + accountOwnerId: '20202020-1553-45c6-a028-5a9064cce07f', + refreshToken: 'exampleRefreshToken', + accessToken: 'exampleAccessToken', + provider: 'google', + handle: 'incoming', + }, + ]) + .execute(); +}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/message.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/message.ts new file mode 100644 index 000000000000..a7b22a6f4131 --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/message.ts @@ -0,0 +1,64 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'message'; + +export const seedMessage = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + 'receivedAt', + 'text', + 'subject', + 'direction', + 'messageThreadId', + 'headerMessageId', + ]) + .orIgnore() + .values([ + { + id: '99ef24a8-2b8a-405d-8f42-e820ca921421', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + receivedAt: new Date(), + text: 'Hello, \n I hope this email finds you well. I am writing to request a meeting. I believe it would be beneficial for both parties to collaborate and explore potential opportunities. Would you be available for a meeting sometime next week? Please let me know your availability, and I will arrange a suitable time. \n Looking forward to your response.\n Best regards', + subject: 'Meeting Request', + direction: 'outgoing', + messageThreadId: 'f66b3db3-8bfa-453b-b99b-bc435a7d4da8', + headerMessageId: '99ef24a8-2b8a-405d-8f42-e820ca921421', + }, + { + id: '8f804a9a-04c8-4f24-93f2-764948e95014', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + receivedAt: new Date(), + text: 'Good Morning,\n I am writing to inquire about information. Could you please provide me with details regarding this topic? \n Your assistance in this matter would be greatly appreciated. Thank you in advance for your prompt response. \n Best regards,Tim', + subject: 'Inquiry Regarding Topic', + direction: 'outgoing', + messageThreadId: 'a05c4e4c-634a-4fde-aa7c-28a0eaf203ca', + headerMessageId: '8f804a9a-04c8-4f24-93f2-764948e95014', + }, + { + id: '3939d68a-ac6b-4f86-87a2-5f5f9d1b6481', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + receivedAt: new Date(), + text: 'Good Evening,\nI wanted to extend my sincere gratitude for taking the time to meet with me earlier today. It was a pleasure discussing with you, and I am excited about the potential opportunities for collaboration. \n Please feel free to reach out if you have any further questions or require additional information. I look forward to our continued communication. Best regards.', + subject: 'Thank You for the Meeting', + direction: 'incoming', + messageThreadId: 'f66b3db3-8bfa-453b-b99b-bc435a7d4da8', + headerMessageId: '3939d68a-ac6b-4f86-87a2-5f5f9d1b6481', + }, + ]) + .execute(); +}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannel.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannel.ts new file mode 100644 index 000000000000..bf0455123b2f --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannel.ts @@ -0,0 +1,93 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'messageChannel'; + +export const seedMessageChannel = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + 'isContactAutoCreationEnabled', + 'type', + 'connectedAccountId', + 'handle', + 'visibility', + ]) + .orIgnore() + .values([ + { + id: '815e647f-9b80-4c2c-a597-383db48de1d6', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: '6773281b-9ac0-4390-9a1a-ab4d2c4e1bb7', + handle: 'outgoing', + visibility: 'share_everything', + }, + { + id: 'cc2a5b92-09ed-4eb9-8b23-62aa4fd81d83', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: '6773281b-9ac0-4390-9a1a-ab4d2c4e1bb7', + handle: 'incoming', + visibility: 'share_everything', + }, + { + id: '756118c6-5ffe-4b32-814a-983d5e4911cd', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: '67373de8-0cc8-4d60-a3a4-803245698908', + handle: 'outgoing', + visibility: 'share_everything', + }, + { + id: '24b91637-9dad-4329-8180-62647a2d7510', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: '67373de8-0cc8-4d60-a3a4-803245698908', + handle: 'incoming', + visibility: 'share_everything', + }, + { + id: '3991bcbc-e2f1-49b5-85d2-5d3a3386990c', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: 'f2a8cf93-cafc-4323-908d-e5b42ad69fdf', + handle: 'outgoing', + visibility: 'share_everything', + }, + { + id: '6cbf78c7-fdff-438f-9132-7d5f216dfc4d', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + isContactAutoCreationEnabled: true, + type: 'email', + connectedAccountId: 'f2a8cf93-cafc-4323-908d-e5b42ad69fdf', + handle: 'incoming', + visibility: 'share_everything', + }, + ]) + .execute(); +}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannelMessageAssociation.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannelMessageAssociation.ts new file mode 100644 index 000000000000..0f0d4ea6c68f --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageChannelMessageAssociation.ts @@ -0,0 +1,60 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'messageChannelMessageAssociation'; + +export const seedMessageChannelMessageAssociation = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + 'messageThreadExternalId', + 'messageThreadId', + 'messageExternalId', + 'messageId', + 'messageChannelId', + ]) + .orIgnore() + .values([ + { + id: '067fb2c8-cc69-44ef-a82c-600c0dbf39ba', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + messageThreadExternalId: null, + messageThreadId: 'f66b3db3-8bfa-453b-b99b-bc435a7d4da8', + messageExternalId: null, + messageId: '99ef24a8-2b8a-405d-8f42-e820ca921421', + messageChannelId: '815e647f-9b80-4c2c-a597-383db48de1d6', + }, + { + id: '736e9516-d80e-4a13-b10b-72ba09082668', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + messageThreadExternalId: null, + messageThreadId: 'a05c4e4c-634a-4fde-aa7c-28a0eaf203ca', + messageExternalId: null, + messageId: '8f804a9a-04c8-4f24-93f2-764948e95014', + messageChannelId: '815e647f-9b80-4c2c-a597-383db48de1d6', + }, + { + id: 'bb9a3fb8-e6ec-4c8a-b431-0901eaf395a9', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + messageThreadExternalId: null, + messageThreadId: 'f66b3db3-8bfa-453b-b99b-bc435a7d4da8', + messageExternalId: null, + messageId: '3939d68a-ac6b-4f86-87a2-5f5f9d1b6481', + messageChannelId: '815e647f-9b80-4c2c-a597-383db48de1d6', + }, + ]) + .execute(); +}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/messageParticipant.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageParticipant.ts new file mode 100644 index 000000000000..25923a8064cf --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageParticipant.ts @@ -0,0 +1,100 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'messageParticipant'; + +export const seedMessageParticipant = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + 'workspaceMemberId', + 'personId', + 'displayName', + 'handle', + 'role', + 'messageId', + ]) + .orIgnore() + .values([ + { + id: '0f2ae856-3434-49d8-8aa2-ec8786153a0b', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '86083141-1c0e-494c-a1b6-85b1c6fefaa5', + displayName: 'Christoph', + handle: 'outgoing', + role: 'from', + messageId: '99ef24a8-2b8a-405d-8f42-e820ca921421', + }, + { + id: '4e8384c2-1659-41ec-93e2-fd70ff09f68c', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '0aa00beb-ac73-4797-824e-87a1f5aea9e0', + displayName: 'Sylvie', + handle: 'incoming', + role: 'to', + messageId: '99ef24a8-2b8a-405d-8f42-e820ca921421', + }, + { + id: 'e716f5ba-c18c-4dd5-ac61-3315bc559e2d', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '93c72d2e-f517-42fd-80ae-14173b3b70ae', + displayName: 'Christopher', + handle: 'incoming', + role: 'to', + messageId: '99ef24a8-2b8a-405d-8f42-e820ca921421', + }, + { + id: 'fc7db84a-e8d2-4ad8-9aea-b78bcbf79cdd', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '86083141-1c0e-494c-a1b6-85b1c6fefaa5', + displayName: 'Christoph', + handle: 'outgoing', + role: 'from', + messageId: '8f804a9a-04c8-4f24-93f2-764948e95014', + }, + { + id: '564c135b-5047-4a3c-abbf-e942e8c3f9c9', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '0aa00beb-ac73-4797-824e-87a1f5aea9e0', + displayName: 'Sylvie', + handle: 'incoming', + role: 'to', + messageId: '8f804a9a-04c8-4f24-93f2-764948e95014', + }, + { + id: '7e4a370e-6110-489a-ba6b-1ae6b7d721ac', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + workspaceMemberId: '20202020-0687-4c41-b707-ed1bfca972a7', + personId: '93c72d2e-f517-42fd-80ae-14173b3b70ae', + displayName: 'Christopher', + handle: 'incoming', + role: 'to', + messageId: '8f804a9a-04c8-4f24-93f2-764948e95014', + }, + ]) + .execute(); +}; diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/messageThread.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageThread.ts new file mode 100644 index 000000000000..e9853c0cbea6 --- /dev/null +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/messageThread.ts @@ -0,0 +1,46 @@ +import { DataSource } from 'typeorm'; + +const tableName = 'messageThread'; + +export const seedMessageThread = async ( + workspaceDataSource: DataSource, + schemaName: string, +) => { + await workspaceDataSource + .createQueryBuilder() + .insert() + .into(`${schemaName}.${tableName}`, [ + 'id', + 'createdAt', + 'updatedAt', + 'deletedAt', + ]) + .orIgnore() + .values([ + { + id: 'f66b3db3-8bfa-453b-b99b-bc435a7d4da8', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + }, + { + id: 'a05c4e4c-634a-4fde-aa7c-28a0eaf203ca', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + }, + { + id: '8ed861c2-1b56-4f10-a2fa-2ccaddf81f6c', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + }, + { + id: '5c28ed13-d51c-485a-b1b6-ed7c63e05d72', + createdAt: new Date(), + updatedAt: new Date(), + deletedAt: null, + }, + ]) + .execute(); +};