Files
tiku-backend.net/Tiku.Infrastructure/Persistence/Migrations/20260805062137_AddLearningTransactionalOutbox.cs

99 lines
5.3 KiB
C#

using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddLearningTransactionalOutbox : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "learning_outbox_messages",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
schema_version = table.Column<int>(type: "integer", nullable: false),
aggregate_id = table.Column<Guid>(type: "uuid", nullable: false),
payload = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
occurred_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
available_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
dead_lettered_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
attempt_count = table.Column<int>(type: "integer", nullable: false),
locked_by = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
lock_expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
last_error = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_learning_outbox_messages", x => x.id);
table.UniqueConstraint("ak_learning_outbox_messages_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_learning_outbox_messages_attempt_count", "attempt_count >= 0");
table.ForeignKey(
name: "fk_learning_outbox_messages_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "learning_projection_receipts",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
outbox_message_id = table.Column<Guid>(type: "uuid", nullable: false),
projection_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_learning_projection_receipts", x => x.id);
table.UniqueConstraint("ak_learning_projection_receipts_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_learning_projection_receipts_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_learning_outbox_messages_tenant_id_event_type_aggregate_id",
table: "learning_outbox_messages",
columns: new[] { "tenant_id", "event_type", "aggregate_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_learning_outbox_pending",
table: "learning_outbox_messages",
columns: new[] { "available_at", "lock_expires_at", "occurred_at", "id" },
filter: "processed_at IS NULL AND dead_lettered_at IS NULL");
migrationBuilder.CreateIndex(
name: "ix_learning_projection_receipts_tenant_id_outbox_message_id_pr~",
table: "learning_projection_receipts",
columns: new[] { "tenant_id", "outbox_message_id", "projection_name" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "learning_outbox_messages");
migrationBuilder.DropTable(
name: "learning_projection_receipts");
}
}
}