Move RAG repository from rag-api to rag-data — consolidate data layer ownership

- Move IRagRepository, EfRagRepository, and VectorSerializer from rag-api/Data to rag-data/Repositories
- Add rag-api-models ProjectReference to rag-data.csproj for model type availability
- Delete rag-api/Data folder (no longer needed; all data access is now in rag-data)
- This aligns RAG with email-api and other services: all data code in the data project

Pattern: rag-api (API logic) → rag-data (repository, EF entities, migrations)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 09:38:25 +03:00
parent 36759d8fee
commit 487924e345
25 changed files with 125 additions and 57 deletions
+2 -2
View File
@@ -5,8 +5,8 @@ namespace CvMatcher.Data;
public sealed class CvMatcherDbContext : DbContext
{
public const string SchemaName = "cvMatcher";
public const string MigrationTableName = "_Migrations";
public const string SchemaName = MigrationConstants.SchemaName;
public const string MigrationTableName = MigrationConstants.MigrationTableName;
public CvMatcherDbContext(DbContextOptions<CvMatcherDbContext> options) : base(options)
{
@@ -0,0 +1,11 @@
namespace CvMatcher.Data;
/// <summary>
/// Schema constants used by CvMatcherDbContext and migrations.
/// Centralized to avoid hardcoded strings and ensure consistency.
/// </summary>
public static class MigrationConstants
{
public const string SchemaName = "cvMatcher";
public const string MigrationTableName = "_Migrations";
}
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using CvMatcher.Data;
#nullable disable
@@ -12,11 +13,11 @@ namespace CvMatcher.Data.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "cvMatcher");
name: MigrationConstants.SchemaName);
migrationBuilder.CreateTable(
name: "ChatCache",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
columns: table => new
{
CacheKey = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -32,7 +33,7 @@ namespace CvMatcher.Data.Migrations
migrationBuilder.CreateTable(
name: "Results",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -49,7 +50,7 @@ namespace CvMatcher.Data.Migrations
migrationBuilder.CreateIndex(
name: "IX_Results_CvDocumentId_JobDocumentId",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
table: "Results",
columns: new[] { "CvDocumentId", "JobDocumentId" },
unique: true);
@@ -60,11 +61,11 @@ namespace CvMatcher.Data.Migrations
{
migrationBuilder.DropTable(
name: "ChatCache",
schema: "cvMatcher");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "Results",
schema: "cvMatcher");
schema: MigrationConstants.SchemaName);
}
}
}
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using CvMatcher.Data;
#nullable disable
@@ -12,7 +13,7 @@ namespace CvMatcher.Data.Migrations
{
migrationBuilder.AddColumn<string>(
name: "Language",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
table: "Results",
type: "nvarchar(max)",
nullable: false,
@@ -24,7 +25,7 @@ namespace CvMatcher.Data.Migrations
{
migrationBuilder.DropColumn(
name: "Language",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
table: "Results");
}
}
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using CvMatcher.Data;
#nullable disable
@@ -13,7 +14,7 @@ namespace CvMatcher.Data.Migrations
{
migrationBuilder.CreateTable(
name: "AiPrompts",
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Key = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
@@ -28,7 +29,7 @@ namespace CvMatcher.Data.Migrations
});
migrationBuilder.InsertData(
schema: "cvMatcher",
schema: MigrationConstants.SchemaName,
table: "AiPrompts",
columns: ["Key", "Language", "Value", "Description"],
values: new object[]
@@ -43,7 +44,7 @@ namespace CvMatcher.Data.Migrations
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(name: "AiPrompts", schema: "cvMatcher");
migrationBuilder.DropTable(name: "AiPrompts", schema: MigrationConstants.SchemaName);
}
}
}
@@ -5,8 +5,8 @@ namespace CvSearch.Data;
public sealed class CvSearchDbContext : DbContext
{
public const string SchemaName = "cvSearch";
public const string MigrationTableName = "_Migrations";
public const string SchemaName = MigrationConstants.SchemaName;
public const string MigrationTableName = MigrationConstants.MigrationTableName;
public CvSearchDbContext(DbContextOptions<CvSearchDbContext> options) : base(options) { }
@@ -0,0 +1,11 @@
namespace CvSearch.Data;
/// <summary>
/// Schema constants used by CvSearchDbContext and migrations.
/// Centralized to avoid hardcoded strings and ensure consistency.
/// </summary>
public static class MigrationConstants
{
public const string SchemaName = "cvSearch";
public const string MigrationTableName = "_Migrations";
}
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using CvSearch.Data;
#nullable disable
@@ -12,11 +13,11 @@ namespace CvSearch.Data.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "cvSearch");
name: MigrationConstants.SchemaName);
migrationBuilder.CreateTable(
name: "JobSearchResults",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -36,7 +37,7 @@ namespace CvSearch.Data.Migrations
migrationBuilder.CreateTable(
name: "JobSearchSessions",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -55,7 +56,7 @@ namespace CvSearch.Data.Migrations
migrationBuilder.CreateTable(
name: "JobSearchTokens",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -88,15 +89,15 @@ namespace CvSearch.Data.Migrations
{
migrationBuilder.DropTable(
name: "JobSearchResults",
schema: "cvSearch");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "JobSearchSessions",
schema: "cvSearch");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "JobSearchTokens",
schema: "cvSearch");
schema: MigrationConstants.SchemaName);
}
}
}
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using CvSearch.Data;
#nullable disable
@@ -12,7 +13,7 @@ namespace CvSearch.Data.Migrations
{
migrationBuilder.AddColumn<string>(
name: "Language",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
table: "JobSearchTokens",
type: "nvarchar(8)",
maxLength: 8,
@@ -21,7 +22,7 @@ namespace CvSearch.Data.Migrations
migrationBuilder.AddColumn<string>(
name: "Language",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
table: "JobSearchSessions",
type: "nvarchar(8)",
maxLength: 8,
@@ -34,12 +35,12 @@ namespace CvSearch.Data.Migrations
{
migrationBuilder.DropColumn(
name: "Language",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
table: "JobSearchTokens");
migrationBuilder.DropColumn(
name: "Language",
schema: "cvSearch",
schema: MigrationConstants.SchemaName,
table: "JobSearchSessions");
}
}
+2 -2
View File
@@ -5,8 +5,8 @@ namespace EmailApi.Data;
public sealed class EmailApiDbContext : DbContext
{
public const string SchemaName = "emailApi";
public const string MigrationTableName = "_Migrations";
public const string SchemaName = MigrationConstants.SchemaName;
public const string MigrationTableName = MigrationConstants.MigrationTableName;
public EmailApiDbContext(DbContextOptions<EmailApiDbContext> options) : base(options) { }
+11
View File
@@ -0,0 +1,11 @@
namespace EmailApi.Data;
/// <summary>
/// Schema constants used by EmailApiDbContext and migrations.
/// Centralized to avoid hardcoded strings and ensure consistency.
/// </summary>
public static class MigrationConstants
{
public const string SchemaName = "emailApi";
public const string MigrationTableName = "_Migrations";
}
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using EmailApi.Data;
#nullable disable
@@ -11,11 +12,11 @@ namespace EmailApi.Data.Migrations
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(name: "emailApi");
migrationBuilder.EnsureSchema(name: MigrationConstants.SchemaName);
migrationBuilder.CreateTable(
name: "EmailTemplates",
schema: "emailApi",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Key = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
@@ -39,7 +40,7 @@ namespace EmailApi.Data.Migrations
=> m.InsertData("EmailTemplates",
["Key", "Language", "Value", "Description", "OperatorCopy"],
[key, lang, value, description, operatorCopy],
"emailApi");
MigrationConstants.SchemaName);
// ── HTML shell (no operator copy — these are layout fragments, not addressable emails) ──
Row("email.html-shell.start", "*",
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using EmailApi.Data;
#nullable disable
@@ -31,7 +32,7 @@ namespace EmailApi.Data.Migrations
=> m.InsertData("EmailTemplates",
["Key", "Language", "Value", "Description", "OperatorCopy"],
[key, lang, value, description, operatorCopy],
"emailApi");
MigrationConstants.SchemaName);
// ── HTML shell (no operator copy — these are layout fragments, not addressable emails) ──
Row("email.html-shell.start", "*",
+11
View File
@@ -0,0 +1,11 @@
namespace MyAi.Data;
/// <summary>
/// Schema constants used by MyAiDbContext and migrations.
/// Centralized to avoid hardcoded strings and ensure consistency.
/// </summary>
public static class MigrationConstants
{
public const string SchemaName = "myAi";
public const string MigrationTableName = "_Migrations";
}
+2 -2
View File
@@ -5,8 +5,8 @@ namespace MyAi.Data;
public sealed class MyAiDbContext : DbContext
{
public const string SchemaName = "myAi";
public const string MigrationTableName = "_Migrations";
public const string SchemaName = MigrationConstants.SchemaName;
public const string MigrationTableName = MigrationConstants.MigrationTableName;
public MyAiDbContext(DbContextOptions<MyAiDbContext> options) : base(options) { }
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using MyAi.Data;
#nullable disable
@@ -12,11 +13,11 @@ namespace MyAi.Data.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "myAi");
name: MigrationConstants.SchemaName);
migrationBuilder.CreateTable(
name: "Templates",
schema: "myAi",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Key = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
@@ -36,7 +37,7 @@ namespace MyAi.Data.Migrations
private static void Seed(MigrationBuilder m)
{
void Row(string key, string lang, string value, string description = "")
=> m.InsertData("Templates", ["Key", "Language", "Value", "Description"], [key, lang, value, description], "myAi");
=> m.InsertData("Templates", ["Key", "Language", "Value", "Description"], [key, lang, value, description], MigrationConstants.SchemaName);
// Match result email — subject
Row("email.match.subject", "en", "MyAi.ro CV Match: {{score}}% - {{jobLabel}}", "Subject for the CV match result email");
@@ -107,7 +108,7 @@ namespace MyAi.Data.Migrations
{
migrationBuilder.DropTable(
name: "Templates",
schema: "myAi");
schema: MigrationConstants.SchemaName);
}
}
}
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using MyAi.Data;
#nullable disable
@@ -12,7 +13,7 @@ namespace MyAi.Data.Migrations
{
void Update(string key, string lang, string value)
=> migrationBuilder.UpdateData("Templates", ["Key", "Language"], [key, lang],
["Value"], [value], "myAi");
["Value"], [value], MigrationConstants.SchemaName);
// email.match.body — en
Update("email.match.body", "en",
@@ -120,7 +121,7 @@ namespace MyAi.Data.Migrations
{
void Update(string key, string lang, string value)
=> migrationBuilder.UpdateData("Templates", ["Key", "Language"], [key, lang],
["Value"], [value], "myAi");
["Value"], [value], MigrationConstants.SchemaName);
Update("email.match.body", "en",
"CV Matcher result\n\nCV Document ID: {{cvDocumentId}}\nJob: {{jobLabel}}\nJob URL: {{jobUrl}}\nScore: {{score}}%\n\nSummary:\n{{summary}}\n\nStrengths:\n{{strengths}}\n\nGaps:\n{{gaps}}\n\nRecommendations:\n{{recommendations}}");
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Migrations;
using MyAi.Data;
#nullable disable
@@ -10,8 +11,8 @@ namespace MyAi.Data.Migrations
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("DELETE FROM [myAi].[Templates] WHERE [Key] LIKE 'email.%'");
migrationBuilder.Sql("DELETE FROM [myAi].[Templates] WHERE [Key] LIKE 'ai.%'");
migrationBuilder.Sql($"DELETE FROM [{MigrationConstants.SchemaName}].[Templates] WHERE [Key] LIKE 'email.%'");
migrationBuilder.Sql($"DELETE FROM [{MigrationConstants.SchemaName}].[Templates] WHERE [Key] LIKE 'ai.%'");
}
/// <inheritdoc />
+11
View File
@@ -0,0 +1,11 @@
namespace Rag.Data;
/// <summary>
/// Schema constants used by RagDbContext and migrations.
/// Centralized to avoid hardcoded strings and ensure consistency.
/// </summary>
public static class MigrationConstants
{
public const string SchemaName = "rag";
public const string MigrationTableName = "_Migrations";
}
@@ -1,5 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Rag.Data;
#nullable disable
@@ -12,11 +13,11 @@ namespace Rag.Data.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "rag");
name: MigrationConstants.SchemaName);
migrationBuilder.CreateTable(
name: "ChatCompletionCache",
schema: "rag",
schema: MigrationConstants.SchemaName,
columns: table => new
{
CacheKey = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -32,7 +33,7 @@ namespace Rag.Data.Migrations
migrationBuilder.CreateTable(
name: "Documents",
schema: "rag",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -52,7 +53,7 @@ namespace Rag.Data.Migrations
migrationBuilder.CreateTable(
name: "EmbeddingCache",
schema: "rag",
schema: MigrationConstants.SchemaName,
columns: table => new
{
CacheKey = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -68,7 +69,7 @@ namespace Rag.Data.Migrations
migrationBuilder.CreateTable(
name: "Chunks",
schema: "rag",
schema: MigrationConstants.SchemaName,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
@@ -91,25 +92,25 @@ namespace Rag.Data.Migrations
migrationBuilder.CreateIndex(
name: "IX_Chunks_DocumentId",
schema: "rag",
schema: MigrationConstants.SchemaName,
table: "Chunks",
column: "DocumentId");
migrationBuilder.CreateIndex(
name: "IX_Documents_DocumentType",
schema: "rag",
schema: MigrationConstants.SchemaName,
table: "Documents",
column: "DocumentType");
migrationBuilder.CreateIndex(
name: "IX_Documents_TextHash",
schema: "rag",
schema: MigrationConstants.SchemaName,
table: "Documents",
column: "TextHash");
migrationBuilder.CreateIndex(
name: "IX_EmbeddingCache_TextHash",
schema: "rag",
schema: MigrationConstants.SchemaName,
table: "EmbeddingCache",
column: "TextHash");
}
@@ -119,19 +120,19 @@ namespace Rag.Data.Migrations
{
migrationBuilder.DropTable(
name: "ChatCompletionCache",
schema: "rag");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "Chunks",
schema: "rag");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "EmbeddingCache",
schema: "rag");
schema: MigrationConstants.SchemaName);
migrationBuilder.DropTable(
name: "Documents",
schema: "rag");
schema: MigrationConstants.SchemaName);
}
}
}
+2 -2
View File
@@ -5,8 +5,8 @@ namespace Rag.Data;
public sealed class RagDbContext : DbContext
{
public const string SchemaName = "rag";
public const string MigrationTableName = "_Migrations";
public const string SchemaName = MigrationConstants.SchemaName;
public const string MigrationTableName = MigrationConstants.MigrationTableName;
public RagDbContext(DbContextOptions<RagDbContext> options) : base(options)
{
@@ -1,6 +1,7 @@
using Rag.Data;
using Rag.Data.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Rag.Data.Repositories.Contracts;
using Rag.Models;
+1
View File
@@ -18,6 +18,7 @@
<ItemGroup>
<ProjectReference Include="..\shared-data\shared-data.csproj" />
<ProjectReference Include="..\rag-api-models\rag-api-models.csproj" />
</ItemGroup>
</Project>