w4c-workflows-api/Data/Migrations/20260828130001_InitialCreate.cs

259 lines
12 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace w4c_workflows.Data.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "workflows");
migrationBuilder.CreateTable(
name: "ApiKeys",
schema: "workflows",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
TenantId = table.Column<string>(type: "text", nullable: false),
KeyHash = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
Label = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
ScopesJson = table.Column<string>(type: "jsonb", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
LastUsedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
RevokedAt = table.Column<DateTime>(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<string>(type: "character varying(128)", maxLength: 128, nullable: false),
TaskId = table.Column<Guid>(type: "uuid", nullable: false),
StateJson = table.Column<string>(type: "jsonb", nullable: true),
CheckpointAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
CorrelationId = table.Column<string>(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<Guid>(type: "uuid", nullable: false),
TenantId = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
Path = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
GitSha = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
Status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
Mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
TriggerJson = table.Column<string>(type: "jsonb", nullable: true),
Target = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
CompiledAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
WorkflowId = table.Column<Guid>(type: "uuid", nullable: false),
ParentId = table.Column<Guid>(type: "uuid", nullable: true),
NextId = table.Column<Guid>(type: "uuid", nullable: true),
OnErrorId = table.Column<Guid>(type: "uuid", nullable: true),
Language = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
Mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
EntryJson = table.Column<string>(type: "jsonb", nullable: true),
EnvJson = table.Column<string>(type: "jsonb", nullable: true),
Order = table.Column<int>(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<Guid>(type: "uuid", nullable: false),
WorkflowId = table.Column<Guid>(type: "uuid", nullable: false),
TenantId = table.Column<string>(type: "text", nullable: false),
Status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
TriggerJson = table.Column<string>(type: "jsonb", nullable: true),
InputJson = table.Column<string>(type: "jsonb", nullable: true),
OutputJson = table.Column<string>(type: "jsonb", nullable: true),
Error = table.Column<string>(type: "text", nullable: true),
CorrelationId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
FinishedAt = table.Column<DateTime>(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<Guid>(type: "uuid", nullable: false),
RunId = table.Column<Guid>(type: "uuid", nullable: false),
TaskId = table.Column<Guid>(type: "uuid", nullable: false),
Attempt = table.Column<int>(type: "integer", nullable: false),
Status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
InputJson = table.Column<string>(type: "jsonb", nullable: true),
OutputJson = table.Column<string>(type: "jsonb", nullable: true),
Error = table.Column<string>(type: "text", nullable: true),
RetryCount = table.Column<int>(type: "integer", nullable: false),
StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
FinishedAt = table.Column<DateTime>(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);
}
/// <inheritdoc />
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");
}
}
}