20260204025553_Migration_20260204105546.cs 4.51 KB
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Rcs.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Migration_20260204105546 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "cache_columns",
                table: "robots",
                type: "integer",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "cache_levels",
                table: "robots",
                type: "integer",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "cache_rows",
                table: "robots",
                type: "integer",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "robot_cache_locations",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false),
                    robot_id = table.Column<Guid>(type: "uuid", nullable: false),
                    location_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    row = table.Column<int>(type: "integer", nullable: false),
                    column = table.Column<int>(type: "integer", nullable: false),
                    level = table.Column<int>(type: "integer", nullable: false),
                    container_id = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
                    material_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
                    material_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
                    quantity = table.Column<double>(type: "double precision", nullable: true),
                    weight = table.Column<double>(type: "double precision", nullable: true),
                    remark = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
                    created_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
                    updated_at = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_robot_cache_locations", x => x.id);
                    table.ForeignKey(
                        name: "FK_robot_cache_locations_robots_robot_id",
                        column: x => x.robot_id,
                        principalTable: "robots",
                        principalColumn: "robot_id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_code",
                table: "robot_cache_locations",
                column: "location_code");

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_column",
                table: "robot_cache_locations",
                column: "column");

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_level",
                table: "robot_cache_locations",
                column: "level");

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_position",
                table: "robot_cache_locations",
                columns: new[] { "row", "column", "level" });

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_robot_id",
                table: "robot_cache_locations",
                column: "robot_id");

            migrationBuilder.CreateIndex(
                name: "idx_robot_cache_location_row",
                table: "robot_cache_locations",
                column: "row");
        }

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

            migrationBuilder.DropColumn(
                name: "cache_columns",
                table: "robots");

            migrationBuilder.DropColumn(
                name: "cache_levels",
                table: "robots");

            migrationBuilder.DropColumn(
                name: "cache_rows",
                table: "robots");
        }
    }
}