20251231073040_Migration_20251231153032.cs 11.2 KB
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Rcs.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Migration_20251231153032 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "agv_tasks");

            migrationBuilder.CreateTable(
                name: "robot_tasks",
                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: false),
                    robot_id = table.Column<Guid>(type: "uuid", nullable: true),
                    task_template_id = table.Column<Guid>(type: "uuid", nullable: false),
                    begin_node_id = table.Column<Guid>(type: "uuid", nullable: true),
                    end_node_id = table.Column<Guid>(type: "uuid", nullable: true),
                    status = table.Column<int>(type: "integer", nullable: false),
                    priority = table.Column<int>(type: "integer", nullable: false, defaultValue: 99),
                    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)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_robot_tasks", x => x.task_id);
                    table.ForeignKey(
                        name: "FK_robot_tasks_map_nodes_begin_node_id",
                        column: x => x.begin_node_id,
                        principalTable: "map_nodes",
                        principalColumn: "node_id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_robot_tasks_map_nodes_end_node_id",
                        column: x => x.end_node_id,
                        principalTable: "map_nodes",
                        principalColumn: "node_id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_robot_tasks_robots_robot_id",
                        column: x => x.robot_id,
                        principalTable: "robots",
                        principalColumn: "robot_id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_robot_tasks_task_templates_task_template_id",
                        column: x => x.task_template_id,
                        principalTable: "task_templates",
                        principalColumn: "template_id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "robot_sub_tasks",
                columns: table => new
                {
                    sub_task_id = table.Column<Guid>(type: "uuid", nullable: false),
                    task_id = table.Column<Guid>(type: "uuid", nullable: false),
                    robot_id = table.Column<Guid>(type: "uuid", nullable: true),
                    begin_node_id = table.Column<Guid>(type: "uuid", nullable: false),
                    end_node_id = table.Column<Guid>(type: "uuid", nullable: false),
                    sequence = table.Column<int>(type: "integer", nullable: false),
                    status = 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)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_robot_sub_tasks", x => x.sub_task_id);
                    table.ForeignKey(
                        name: "FK_robot_sub_tasks_map_nodes_begin_node_id",
                        column: x => x.begin_node_id,
                        principalTable: "map_nodes",
                        principalColumn: "node_id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_robot_sub_tasks_map_nodes_end_node_id",
                        column: x => x.end_node_id,
                        principalTable: "map_nodes",
                        principalColumn: "node_id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_robot_sub_tasks_robot_tasks_task_id",
                        column: x => x.task_id,
                        principalTable: "robot_tasks",
                        principalColumn: "task_id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_robot_sub_tasks_robots_robot_id",
                        column: x => x.robot_id,
                        principalTable: "robots",
                        principalColumn: "robot_id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_robot_id",
                table: "robot_sub_tasks",
                column: "robot_id");

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_sequence",
                table: "robot_sub_tasks",
                columns: new[] { "task_id", "sequence" });

            migrationBuilder.CreateIndex(
                name: "idx_sub_task_task_id",
                table: "robot_sub_tasks",
                column: "task_id");

            migrationBuilder.CreateIndex(
                name: "IX_robot_sub_tasks_begin_node_id",
                table: "robot_sub_tasks",
                column: "begin_node_id");

            migrationBuilder.CreateIndex(
                name: "IX_robot_sub_tasks_end_node_id",
                table: "robot_sub_tasks",
                column: "end_node_id");

            migrationBuilder.CreateIndex(
                name: "idx_task_code",
                table: "robot_tasks",
                column: "task_code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_task_robot_id",
                table: "robot_tasks",
                column: "robot_id");

            migrationBuilder.CreateIndex(
                name: "idx_task_status",
                table: "robot_tasks",
                column: "status");

            migrationBuilder.CreateIndex(
                name: "IX_robot_tasks_begin_node_id",
                table: "robot_tasks",
                column: "begin_node_id");

            migrationBuilder.CreateIndex(
                name: "IX_robot_tasks_end_node_id",
                table: "robot_tasks",
                column: "end_node_id");

            migrationBuilder.CreateIndex(
                name: "IX_robot_tasks_task_template_id",
                table: "robot_tasks",
                column: "task_template_id");
        }

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

            migrationBuilder.DropTable(
                name: "robot_tasks");

            migrationBuilder.CreateTable(
                name: "agv_tasks",
                columns: table => new
                {
                    task_id = table.Column<Guid>(type: "uuid", nullable: false),
                    end_node_code = table.Column<Guid>(type: "uuid", nullable: true),
                    robot_id = table.Column<Guid>(type: "uuid", nullable: true),
                    start_node_code = table.Column<Guid>(type: "uuid", nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    error_info = table.Column<string>(type: "text", nullable: false),
                    execution_order = table.Column<int>(type: "integer", nullable: true),
                    main_task_guid = table.Column<string>(type: "character varying(36)", maxLength: 36, nullable: true),
                    priority = table.Column<int>(type: "integer", nullable: false, defaultValue: 99),
                    status = table.Column<int>(type: "integer", 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: false),
                    task_type = table.Column<int>(type: "integer", nullable: false),
                    updated_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_agv_tasks", x => x.task_id);
                    table.ForeignKey(
                        name: "FK_agv_tasks_map_nodes_end_node_code",
                        column: x => x.end_node_code,
                        principalTable: "map_nodes",
                        principalColumn: "node_id");
                    table.ForeignKey(
                        name: "FK_agv_tasks_map_nodes_start_node_code",
                        column: x => x.start_node_code,
                        principalTable: "map_nodes",
                        principalColumn: "node_id");
                    table.ForeignKey(
                        name: "FK_agv_tasks_robots_robot_id",
                        column: x => x.robot_id,
                        principalTable: "robots",
                        principalColumn: "robot_id",
                        onDelete: ReferentialAction.SetNull);
                });

            migrationBuilder.CreateIndex(
                name: "idx_agv_task_code",
                table: "agv_tasks",
                column: "task_code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "idx_agv_task_main_guid",
                table: "agv_tasks",
                column: "main_task_guid");

            migrationBuilder.CreateIndex(
                name: "idx_agv_task_robot",
                table: "agv_tasks",
                column: "robot_id");

            migrationBuilder.CreateIndex(
                name: "idx_agv_task_status",
                table: "agv_tasks",
                column: "status");

            migrationBuilder.CreateIndex(
                name: "IX_agv_tasks_end_node_code",
                table: "agv_tasks",
                column: "end_node_code");

            migrationBuilder.CreateIndex(
                name: "IX_agv_tasks_start_node_code",
                table: "agv_tasks",
                column: "start_node_code");
        }
    }
}