using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Nexus.Api.Migrations { /// public partial class AddOpenClawRunProjection : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "OpenClawRuns", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Title = table.Column(type: "character varying(160)", maxLength: 160, nullable: false), Prompt = table.Column(type: "text", nullable: false), AgentId = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), SessionKey = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), Status = table.Column(type: "character varying(40)", maxLength: 40, nullable: false), TaskId = table.Column(type: "uuid", nullable: true), ProjectId = table.Column(type: "uuid", nullable: true), OpenClawRunId = table.Column(type: "character varying(240)", maxLength: 240, nullable: true), RetriedFromRunId = table.Column(type: "uuid", nullable: true), StartIdempotencyKey = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), CorrelationId = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Actor = table.Column(type: "character varying(240)", maxLength: 240, nullable: false), TraceParent = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), LastError = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true), LastGatewaySequence = table.Column(type: "bigint", nullable: true), SequenceGapDetected = table.Column(type: "boolean", nullable: false), Revision = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), StartedAt = table.Column(type: "timestamp with time zone", nullable: true), FinishedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_OpenClawRuns", x => x.Id); table.ForeignKey( name: "FK_OpenClawRuns_Projects_ProjectId", column: x => x.ProjectId, principalTable: "Projects", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_OpenClawRuns_Tasks_TaskId", column: x => x.TaskId, principalTable: "Tasks", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "OpenClawRunHistory", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RunId = table.Column(type: "uuid", nullable: false), Action = table.Column(type: "character varying(80)", maxLength: 80, nullable: false), FromStatus = table.Column(type: "character varying(40)", maxLength: 40, nullable: false), ToStatus = table.Column(type: "character varying(40)", maxLength: 40, nullable: false), Message = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: false), Actor = table.Column(type: "character varying(240)", maxLength: 240, nullable: false), CorrelationId = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), IdempotencyKey = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), TraceParent = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), GatewayEventId = table.Column(type: "character varying(120)", maxLength: 120, nullable: true), GatewaySequence = table.Column(type: "bigint", nullable: true), SequenceGapDetected = table.Column(type: "boolean", nullable: false), ResultRunId = table.Column(type: "uuid", nullable: true), OccurredAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_OpenClawRunHistory", x => x.Id); table.ForeignKey( name: "FK_OpenClawRunHistory_OpenClawRuns_RunId", column: x => x.RunId, principalTable: "OpenClawRuns", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_OpenClawRunHistory_GatewayEventId", table: "OpenClawRunHistory", column: "GatewayEventId", unique: true); migrationBuilder.CreateIndex( name: "IX_OpenClawRunHistory_RunId_Action_IdempotencyKey", table: "OpenClawRunHistory", columns: new[] { "RunId", "Action", "IdempotencyKey" }, unique: true); migrationBuilder.CreateIndex( name: "IX_OpenClawRunHistory_RunId_OccurredAt", table: "OpenClawRunHistory", columns: new[] { "RunId", "OccurredAt" }); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_OpenClawRunId", table: "OpenClawRuns", column: "OpenClawRunId", unique: true); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_ProjectId", table: "OpenClawRuns", column: "ProjectId"); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_RetriedFromRunId", table: "OpenClawRuns", column: "RetriedFromRunId"); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_SessionKey", table: "OpenClawRuns", column: "SessionKey"); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_StartIdempotencyKey", table: "OpenClawRuns", column: "StartIdempotencyKey", unique: true); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_Status_UpdatedAt", table: "OpenClawRuns", columns: new[] { "Status", "UpdatedAt" }); migrationBuilder.CreateIndex( name: "IX_OpenClawRuns_TaskId", table: "OpenClawRuns", column: "TaskId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "OpenClawRunHistory"); migrationBuilder.DropTable( name: "OpenClawRuns"); } } }