157 lines
5.7 KiB
C#
157 lines
5.7 KiB
C#
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
#nullable disable
|
|
|
|
namespace EgwCoreLib.Lux.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddProdAssign : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
// aggiunta stored
|
|
addStored(migrationBuilder, "stp_ProdItem_UpdateProdLabel");
|
|
addStored(migrationBuilder, "stp_deleteOfferTree");
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "OrderRowState",
|
|
table: "sales_order_row",
|
|
type: "int",
|
|
nullable: false,
|
|
defaultValue: 0);
|
|
|
|
migrationBuilder.AddColumn<double>(
|
|
name: "EstimTime",
|
|
table: "production_item",
|
|
type: "double",
|
|
nullable: false,
|
|
defaultValue: 0.0);
|
|
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "ProdAssignID",
|
|
table: "production_item",
|
|
type: "int",
|
|
nullable: true);
|
|
|
|
migrationBuilder.AddColumn<string>(
|
|
name: "ProdItemTag",
|
|
table: "production_item",
|
|
type: "varchar(255)",
|
|
nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "production_assign",
|
|
columns: table => new
|
|
{
|
|
ProdAssignID = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
OrderRowID = table.Column<int>(type: "int", nullable: false),
|
|
ProdPlantCod = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_production_assign", x => x.ProdAssignID);
|
|
table.ForeignKey(
|
|
name: "FK_production_assign_sales_order_row_OrderRowID",
|
|
column: x => x.OrderRowID,
|
|
principalTable: "sales_order_row",
|
|
principalColumn: "OrderRowID",
|
|
onDelete: ReferentialAction.Restrict);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "idx_prod_item_tag",
|
|
table: "production_item",
|
|
column: "ProdItemTag",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_production_item_ProdAssignID",
|
|
table: "production_item",
|
|
column: "ProdAssignID");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_production_assign_OrderRowID",
|
|
table: "production_assign",
|
|
column: "OrderRowID");
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "FK_production_item_production_assign_ProdAssignID",
|
|
table: "production_item",
|
|
column: "ProdAssignID",
|
|
principalTable: "production_assign",
|
|
principalColumn: "ProdAssignID",
|
|
onDelete: ReferentialAction.Restrict);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
// rimozione stored
|
|
remStored(migrationBuilder, "stp_ProdItem_UpdateProdLabel");
|
|
remStored(migrationBuilder, "stp_deleteOfferTree");
|
|
|
|
migrationBuilder.DropForeignKey(
|
|
name: "FK_production_item_production_assign_ProdAssignID",
|
|
table: "production_item");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "production_assign");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "idx_prod_item_tag",
|
|
table: "production_item");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "IX_production_item_ProdAssignID",
|
|
table: "production_item");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "OrderRowState",
|
|
table: "sales_order_row");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "EstimTime",
|
|
table: "production_item");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "ProdAssignID",
|
|
table: "production_item");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "ProdItemTag",
|
|
table: "production_item");
|
|
|
|
}
|
|
|
|
private void addView(MigrationBuilder migrationBuilder, string objName)
|
|
{
|
|
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SqlScripts", "View", $"{objName}.sql");
|
|
string viewBody = File.ReadAllText(path);
|
|
migrationBuilder.Sql(viewBody);
|
|
}
|
|
private void addStored(MigrationBuilder migrationBuilder, string objName)
|
|
{
|
|
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SqlScripts", "Stored", $"{objName}.sql");
|
|
string viewBody = File.ReadAllText(path);
|
|
migrationBuilder.Sql(viewBody);
|
|
}
|
|
|
|
private void remView(MigrationBuilder migrationBuilder, string objName)
|
|
{
|
|
migrationBuilder.Sql($"DROP VIEW IF EXISTS {objName};");
|
|
}
|
|
private void remStored(MigrationBuilder migrationBuilder, string objName)
|
|
{
|
|
migrationBuilder.Sql($"DROP PROCEDURE IF EXISTS {objName};");
|
|
}
|
|
}
|
|
}
|