9a0211f82c
- down x eliminazione stored & views OK
73 lines
2.9 KiB
C#
73 lines
2.9 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace MP.MONO.Data.Migrations
|
|
{
|
|
public partial class TaskExecTable : Migration
|
|
{
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "TaskExec",
|
|
columns: table => new
|
|
{
|
|
TaskID = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
DtRif = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
CodTask = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Result = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4")
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_TaskExec", x => x.TaskID);
|
|
})
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
// aggiunta view
|
|
addView(migrationBuilder, "v_ParetoStatus");
|
|
// aggiunta stored
|
|
addStored(migrationBuilder, "stp_paretoStatus");
|
|
addStored(migrationBuilder, "stp_removeOldData");
|
|
}
|
|
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "TaskExec");
|
|
// rimozione view
|
|
remView(migrationBuilder, "v_ParetoStatus");
|
|
// rimozione stored
|
|
remStored(migrationBuilder, "stp_paretoStatus");
|
|
remStored(migrationBuilder, "stp_removeOldData");
|
|
}
|
|
|
|
|
|
private void addView(MigrationBuilder migrationBuilder, string objName)
|
|
{
|
|
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().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.GetEntryAssembly().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};");
|
|
}
|
|
}
|
|
}
|