20260304070521_Migration_20260304150512.cs 6.88 KB
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Rcs.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Migration_20260304150512 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "robot_task_histories",
                columns: table => new
                {
                    task_id = table.Column<Guid>(type: "uuid", nullable: false),
                    task_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    task_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
                    robot_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    task_template_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    begin_location_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    end_location_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    status = table.Column<int>(type: "integer", nullable: false),
                    pause = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    priority = table.Column<int>(type: "integer", nullable: false, defaultValue: 99),
                    source = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
                    relation = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
                    shelf_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    error_info = table.Column<string>(type: "text", nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    updated_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    archived_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_robot_task_histories", x => x.task_id);
                    table.UniqueConstraint("ak_task_history_task_code", x => x.task_code);
                });

            migrationBuilder.CreateTable(
                name: "robot_sub_task_histories",
                columns: table => new
                {
                    sub_task_id = table.Column<Guid>(type: "uuid", nullable: false),
                    task_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    robot_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
                    begin_node_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    end_node_code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    sequence = table.Column<int>(type: "integer", nullable: false),
                    status = table.Column<int>(type: "integer", nullable: false),
                    execution_count = table.Column<int>(type: "integer", nullable: false),
                    created_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    updated_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    archived_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_robot_sub_task_histories", x => x.sub_task_id);
                    table.ForeignKey(
                        name: "FK_robot_sub_task_histories_robot_task_histories_task_code",
                        column: x => x.task_code,
                        principalTable: "robot_task_histories",
                        principalColumn: "task_code",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "idx_task_history_archived_at",
                table: "robot_task_histories",
                column: "archived_at");

            migrationBuilder.CreateIndex(
                name: "idx_task_history_begin_location_code",
                table: "robot_task_histories",
                column: "begin_location_code");

            migrationBuilder.CreateIndex(
                name: "idx_task_history_end_location_code",
                table: "robot_task_histories",
                column: "end_location_code");

            migrationBuilder.CreateIndex(
                name: "idx_task_history_robot_code",
                table: "robot_task_histories",
                column: "robot_code");

            migrationBuilder.CreateIndex(
                name: "idx_task_history_status",
                table: "robot_task_histories",
                column: "status");

            migrationBuilder.CreateIndex(
                name: "idx_task_history_task_code",
                table: "robot_task_histories",
                column: "task_code");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_archived_at",
                table: "robot_sub_task_histories",
                column: "archived_at");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_begin_node_code",
                table: "robot_sub_task_histories",
                column: "begin_node_code");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_end_node_code",
                table: "robot_sub_task_histories",
                column: "end_node_code");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_robot_code",
                table: "robot_sub_task_histories",
                column: "robot_code");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_task_code",
                table: "robot_sub_task_histories",
                column: "task_code");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_history_task_sequence",
                table: "robot_sub_task_histories",
                columns: new[] { "task_code", "sequence" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "robot_sub_task_histories");

            migrationBuilder.DropTable(
                name: "robot_task_histories");
        }
    }
}