feat: atualizar relacionamentos de entidades e melhorar resiliência do banco de dados#136
feat: atualizar relacionamentos de entidades e melhorar resiliência do banco de dados#136samuelzedec merged 4 commits intomainfrom
Conversation
- Adiciona EnableSensitiveDataLogging, EnableServiceProviderCaching e EnableDetailedErrors
…xtension correspondente - Remove `MonthlyReport` do enum `AssistantType` - Atualiza `GetModel` para refletir a remoção, eliminando o mapeamento relacionado
…mpany` - Adiciona coluna `company_id` em `product_embeddings` - Cria índice e chave estrangeira vinculando `product_embeddings` a `company` - Atualiza arquivo designer da migração para refletir as mudanças
…ção e melhorias no relacionamento de entidades
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the AI embeddings service to add company-scoped product embeddings searches and removes the unused GetByEntityIdAsync method. The main changes establish a direct relationship between ProductEmbeddings and Company entities to enable multi-tenant product similarity searches.
Key changes:
- Added
CompanyIdparameter toFindSimilarAsyncmethod to scope embeddings searches by company - Removed unused
GetByEntityIdAsyncmethod from the AI model service interface and implementations - Added Company relationship to ProductEmbeddingsModel with proper foreign key constraints
- Removed
AssistantType.MonthlyReportenum value and its associated model mapping
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| AiProductService.cs | Added companyId parameter to FindSimilarAsync and removed GetByEntityIdAsync override |
| AiModelService.cs | Updated abstract FindSimilarAsync signature with companyId parameter and removed GetByEntityIdAsync |
| ProductEmbeddingsModel.cs | Added CompanyId property and Company navigation property with private setter |
| AppDbContextModelSnapshot.cs | Added CompanyId column, index, and foreign key relationship to Company |
| 20251109044954_AddProductEmbeddingsCompanyRelation.cs | Migration to add company_id column and foreign key constraint |
| ProductEmbeddingsModelMap.cs | Added CompanyId property and Company relationship mappings |
| GenerateProductEmbeddingsMessageConsumer.cs | Updated to include CompanyId when creating ProductEmbeddingsModel |
| IAiModelService.cs | Changed TInput to contravariant, added companyId param to FindSimilarAsync, removed GetByEntityIdAsync |
| AssistantTypeExtension.cs | Removed MonthlyReport case from model mapping |
| AssistantType.cs | Removed MonthlyReport enum value |
| AppDbContextFactory.cs | Added EnableSensitiveDataLogging and EnableServiceProviderCaching |
| DependencyInjection.cs | Added EnableDetailedErrors and EnableServiceProviderCaching to DbContext |
| Directory.Build.props | Version bumped to 4.3.1 |
| CHANGELOG.md | Added v4.3.1 entry describing changes |
Files not reviewed (1)
- src/Riber.Infrastructure/Persistence/Migrations/20251109044954_AddProductEmbeddingsCompanyRelation.Designer.cs: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Riber - Changelog | ||
|
|
||
| ## v4.3.1 - 09/12/2025 | ||
| **REFATOÇÃO**: Remove o método de busca por id da entidade nos IAiModelService |
There was a problem hiding this comment.
Corrected spelling of 'REFATOÇÃO' to 'REFATORAÇÃO'.
| **REFATOÇÃO**: Remove o método de busca por id da entidade nos IAiModelService | |
| **REFATORAÇÃO**: Remove o método de busca por id da entidade nos IAiModelService |
|
|
||
| ## v4.3.1 - 09/12/2025 | ||
| **REFATOÇÃO**: Remove o método de busca por id da entidade nos IAiModelService | ||
| Adiciona relationacimento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca |
There was a problem hiding this comment.
Corrected spelling of 'relationacimento' to 'relacionamento'.
| Adiciona relationacimento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca | |
| Adiciona relacionamento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca |
| nullable: false, | ||
| defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); |
There was a problem hiding this comment.
Adding a required NOT NULL column with an empty GUID default value will cause issues if there are existing records in the product_embeddings table. The migration should either include a data migration step to populate the CompanyId from the related Product, or the column should initially be nullable.
| nullable: false, | |
| defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); | |
| nullable: true); | |
| // Backfill company_id for existing records by joining to product table | |
| migrationBuilder.Sql(@" | |
| UPDATE product_embeddings | |
| SET company_id = product.company_id | |
| FROM product | |
| WHERE product_embeddings.product_id = product.id | |
| "); | |
| // Alter column to be NOT NULL after backfilling | |
| migrationBuilder.AlterColumn<Guid>( | |
| name: "company_id", | |
| table: "product_embeddings", | |
| type: "uuid", | |
| nullable: false, | |
| oldClrType: typeof(Guid), | |
| oldType: "uuid", | |
| oldNullable: true); |


4.3.1e adiciona changelog refletindo refatoração e melhorias de relacionamentos.product_embeddingscomcompany:company_idemproduct_embeddings.AssistantTyperemovendoMonthlyReporte ajusta extensãoGetModelpara refletir esta mudança.EnableSensitiveDataLogging,EnableServiceProviderCachingeEnableDetailedErrors.