using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Pgvector; #nullable disable namespace ManagerService.Migrations { /// public partial class AddContentEmbedding : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("Npgsql:PostgresExtension:postgis", ",,") .Annotation("Npgsql:PostgresExtension:vector", ",,") .OldAnnotation("Npgsql:PostgresExtension:postgis", ",,"); migrationBuilder.CreateTable( name: "ContentEmbeddings", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), InstanceId = table.Column(type: "text", nullable: false), ConfigurationId = table.Column(type: "text", nullable: true), ContentId = table.Column(type: "text", nullable: false), ContentType = table.Column(type: "integer", nullable: false), ChunkIndex = table.Column(type: "integer", nullable: false), PageNumber = table.Column(type: "integer", nullable: true), Language = table.Column(type: "character varying(5)", maxLength: 5, nullable: false), Text = table.Column(type: "text", nullable: false), Embedding = table.Column(type: "vector(768)", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ContentEmbeddings", x => x.Id); }); migrationBuilder.CreateIndex( name: "IX_ContentEmbeddings_ContentType_ContentId_ChunkIndex", table: "ContentEmbeddings", columns: new[] { "ContentType", "ContentId", "ChunkIndex" }, unique: true); migrationBuilder.CreateIndex( name: "IX_ContentEmbeddings_Embedding", table: "ContentEmbeddings", column: "Embedding") .Annotation("Npgsql:IndexMethod", "hnsw") .Annotation("Npgsql:IndexOperators", new[] { "vector_cosine_ops" }); migrationBuilder.CreateIndex( name: "IX_ContentEmbeddings_InstanceId_ContentType", table: "ContentEmbeddings", columns: new[] { "InstanceId", "ContentType" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ContentEmbeddings"); migrationBuilder.AlterDatabase() .Annotation("Npgsql:PostgresExtension:postgis", ",,") .OldAnnotation("Npgsql:PostgresExtension:postgis", ",,") .OldAnnotation("Npgsql:PostgresExtension:vector", ",,"); } } }