using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace w4c_workflows.Data.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "workflows"); migrationBuilder.CreateTable( name: "ApiKeys", schema: "workflows", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TenantId = table.Column(type: "text", nullable: false), KeyHash = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Label = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), ScopesJson = table.Column(type: "jsonb", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), LastUsedAt = table.Column(type: "timestamp with time zone", nullable: true), RevokedAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ApiKeys", x => x.Id); }); migrationBuilder.CreateTable( name: "DurableStates", schema: "workflows", columns: table => new { InstanceId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), TaskId = table.Column(type: "uuid", nullable: false), StateJson = table.Column(type: "jsonb", nullable: true), CheckpointAt = table.Column(type: "timestamp with time zone", nullable: false), CorrelationId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true) }, constraints: table => { table.PrimaryKey("PK_DurableStates", x => x.InstanceId); }); migrationBuilder.CreateTable( name: "Workflows", schema: "workflows", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TenantId = table.Column(type: "text", nullable: false), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Path = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), GitSha = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), Status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), Mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), TriggerJson = table.Column(type: "jsonb", nullable: true), Target = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), CompiledAt = table.Column(type: "timestamp with time zone", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Workflows", x => x.Id); }); migrationBuilder.CreateTable( name: "Tasks", schema: "workflows", columns: table => new { Id = table.Column(type: "uuid", nullable: false), WorkflowId = table.Column(type: "uuid", nullable: false), ParentId = table.Column(type: "uuid", nullable: true), NextId = table.Column(type: "uuid", nullable: true), OnErrorId = table.Column(type: "uuid", nullable: true), Language = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), Mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), EntryJson = table.Column(type: "jsonb", nullable: true), EnvJson = table.Column(type: "jsonb", nullable: true), Order = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tasks", x => x.Id); table.ForeignKey( name: "FK_Tasks_Workflows_WorkflowId", column: x => x.WorkflowId, principalSchema: "workflows", principalTable: "Workflows", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "WorkflowRuns", schema: "workflows", columns: table => new { Id = table.Column(type: "uuid", nullable: false), WorkflowId = table.Column(type: "uuid", nullable: false), TenantId = table.Column(type: "text", nullable: false), Status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), TriggerJson = table.Column(type: "jsonb", nullable: true), InputJson = table.Column(type: "jsonb", nullable: true), OutputJson = table.Column(type: "jsonb", nullable: true), Error = table.Column(type: "text", nullable: true), CorrelationId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true), 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_WorkflowRuns", x => x.Id); table.ForeignKey( name: "FK_WorkflowRuns_Workflows_WorkflowId", column: x => x.WorkflowId, principalSchema: "workflows", principalTable: "Workflows", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "TaskRuns", schema: "workflows", columns: table => new { Id = table.Column(type: "uuid", nullable: false), RunId = table.Column(type: "uuid", nullable: false), TaskId = table.Column(type: "uuid", nullable: false), Attempt = table.Column(type: "integer", nullable: false), Status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), InputJson = table.Column(type: "jsonb", nullable: true), OutputJson = table.Column(type: "jsonb", nullable: true), Error = table.Column(type: "text", nullable: true), RetryCount = table.Column(type: "integer", 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_TaskRuns", x => x.Id); table.ForeignKey( name: "FK_TaskRuns_Tasks_TaskId", column: x => x.TaskId, principalSchema: "workflows", principalTable: "Tasks", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_TaskRuns_WorkflowRuns_RunId", column: x => x.RunId, principalSchema: "workflows", principalTable: "WorkflowRuns", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ApiKeys_TenantId", schema: "workflows", table: "ApiKeys", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_DurableStates_CorrelationId", schema: "workflows", table: "DurableStates", column: "CorrelationId"); migrationBuilder.CreateIndex( name: "IX_TaskRuns_RunId", schema: "workflows", table: "TaskRuns", column: "RunId"); migrationBuilder.CreateIndex( name: "IX_TaskRuns_TaskId", schema: "workflows", table: "TaskRuns", column: "TaskId"); migrationBuilder.CreateIndex( name: "IX_Tasks_WorkflowId", schema: "workflows", table: "Tasks", column: "WorkflowId"); migrationBuilder.CreateIndex( name: "IX_WorkflowRuns_CorrelationId", schema: "workflows", table: "WorkflowRuns", column: "CorrelationId"); migrationBuilder.CreateIndex( name: "IX_WorkflowRuns_TenantId", schema: "workflows", table: "WorkflowRuns", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_WorkflowRuns_WorkflowId", schema: "workflows", table: "WorkflowRuns", column: "WorkflowId"); migrationBuilder.CreateIndex( name: "IX_Workflows_TenantId", schema: "workflows", table: "Workflows", column: "TenantId"); migrationBuilder.CreateIndex( name: "IX_Workflows_TenantId_Name", schema: "workflows", table: "Workflows", columns: new[] { "TenantId", "Name" }, unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ApiKeys", schema: "workflows"); migrationBuilder.DropTable( name: "DurableStates", schema: "workflows"); migrationBuilder.DropTable( name: "TaskRuns", schema: "workflows"); migrationBuilder.DropTable( name: "Tasks", schema: "workflows"); migrationBuilder.DropTable( name: "WorkflowRuns", schema: "workflows"); migrationBuilder.DropTable( name: "Workflows", schema: "workflows"); } } }