Skip to content

feat: atualizar relacionamentos de entidades e melhorar resiliência do banco de dados#136

Merged
samuelzedec merged 4 commits intomainfrom
develop
Nov 9, 2025
Merged

feat: atualizar relacionamentos de entidades e melhorar resiliência do banco de dados#136
samuelzedec merged 4 commits intomainfrom
develop

Conversation

@samuelzedec
Copy link
Owner

@samuelzedec samuelzedec commented Nov 9, 2025

  • Atualiza versão do projeto para 4.3.1 e adiciona changelog refletindo refatoração e melhorias de relacionamentos.
  • Introduz migração para vincular product_embeddings com company:
    • Adiciona coluna company_id em product_embeddings.
    • Cria índice e chave estrangeira para este relacionamento.
    • Garante que arquivos de design da migração estejam alinhados com as atualizações.
  • Refatora AssistantType removendo MonthlyReport e ajusta extensão GetModel para refletir esta mudança.
  • Habilita opções avançadas do EF Core para resiliência e debugging melhorados:
    • Adiciona EnableSensitiveDataLogging, EnableServiceProviderCaching e EnableDetailedErrors.

- 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
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
57.1% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@samuelzedec samuelzedec merged commit 3342873 into main Nov 9, 2025
2 of 3 checks passed
@samuelzedec samuelzedec requested a review from Copilot November 9, 2025 05:26
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 CompanyId parameter to FindSimilarAsync method to scope embeddings searches by company
  • Removed unused GetByEntityIdAsync method from the AI model service interface and implementations
  • Added Company relationship to ProductEmbeddingsModel with proper foreign key constraints
  • Removed AssistantType.MonthlyReport enum 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
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'REFATOÇÃO' to 'REFATORAÇÃO'.

Suggested change
**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

Copilot uses AI. Check for mistakes.

## 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
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'relationacimento' to 'relacionamento'.

Suggested change
Adiciona relationacimento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca
Adiciona relacionamento entre entidade `ProductEmbeddings` e `Company` para uma melhor busca

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +19
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant