Nuova migratins del DB

This commit is contained in:
Samuele Locatelli
2020-04-24 13:18:42 +02:00
parent ca253a5497
commit 41558f278e
4 changed files with 503 additions and 22 deletions
@@ -0,0 +1,29 @@
// <auto-generated />
namespace Thermo.Active.Database.Migrations
{
using System.CodeDom.Compiler;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Resources;
[GeneratedCode("EntityFramework.Migrations", "6.2.0-61023")]
public sealed partial class ThermoStart : IMigrationMetadata
{
private readonly ResourceManager Resources = new ResourceManager(typeof(ThermoStart));
string IMigrationMetadata.Id
{
get { return "202004241109233_Thermo-Start"; }
}
string IMigrationMetadata.Source
{
get { return null; }
}
string IMigrationMetadata.Target
{
get { return Resources.GetString("Target"); }
}
}
}
@@ -0,0 +1,328 @@
namespace Thermo.Active.Database.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class ThermoStart : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.alarm_description",
c => new
{
id = c.Int(nullable: false),
title = c.String(unicode: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.alarm_file",
c => new
{
id = c.Int(nullable: false, identity: true),
file_name = c.String(unicode: false),
local_file_name = c.String(unicode: false),
alarm_desc_id = c.Int(nullable: false),
source = c.Int(nullable: false),
user_id = c.Int(),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.user", t => t.user_id)
.Index(t => t.user_id);
CreateTable(
"dbo.user",
c => new
{
id = c.Int(nullable: false, identity: true),
username = c.String(nullable: false, unicode: false),
first_name = c.String(unicode: false),
last_name = c.String(unicode: false),
password = c.String(unicode: false),
security_stamp = c.String(unicode: false),
language = c.String(unicode: false),
deleted = c.Boolean(nullable: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.alarm_occurrence",
c => new
{
id = c.Int(nullable: false, identity: true),
alarm_id = c.Int(nullable: false),
alarm_description_id = c.Int(),
source = c.Int(nullable: false),
type = c.Int(nullable: false),
processes = c.Int(nullable: false),
timestamp = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.alarm_description", t => t.alarm_description_id)
.Index(t => t.alarm_description_id);
CreateTable(
"dbo.alarm_user",
c => new
{
user_id = c.Int(nullable: false),
alarm_occurence_id = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.user_id, t.alarm_occurence_id })
.ForeignKey("dbo.alarm_occurrence", t => t.alarm_occurence_id, cascadeDelete: true)
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
.Index(t => t.user_id)
.Index(t => t.alarm_occurence_id);
CreateTable(
"dbo.alarm_note",
c => new
{
id = c.Int(nullable: false, identity: true),
message = c.String(unicode: false),
user_id = c.Int(nullable: false),
alarm_desc_id = c.Int(nullable: false),
source = c.Int(nullable: false),
timestamp = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
.Index(t => t.user_id);
CreateTable(
"dbo.family",
c => new
{
id = c.Short(nullable: false),
name = c.String(unicode: false),
right_size = c.Byte(nullable: false),
left_size = c.Byte(nullable: false),
tcp_table = c.Byte(nullable: false),
gamma = c.Byte(nullable: false),
rotation_type = c.Byte(nullable: false),
cooling_byte = c.Byte(nullable: false),
max_speed = c.Int(nullable: false),
max_load = c.Byte(nullable: false),
min_load_pct_autoload = c.Byte(nullable: false),
max_load_pct_autoload = c.Byte(nullable: false),
dynamic_compensation = c.Byte(nullable: false),
min_load_dynamic_comp = c.Byte(nullable: false),
max_load_dynamic_comp = c.Byte(nullable: false),
life_type = c.Byte(nullable: false),
nominal_life = c.Int(nullable: false),
revive_delta = c.Int(nullable: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.favorite_user_softkey",
c => new
{
user_softkey_id = c.Int(nullable: false),
user_id = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.user_softkey_id, t.user_id });
CreateTable(
"dbo.function_access",
c => new
{
id = c.Int(nullable: false, identity: true),
name = c.String(unicode: false),
write_level_min = c.Int(nullable: false),
read_level_min = c.Int(nullable: false),
area = c.String(unicode: false),
enabled = c.Boolean(nullable: false),
plc_id = c.Int(nullable: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.machine",
c => new
{
id = c.Int(nullable: false, identity: true),
name = c.String(unicode: false),
unique_id = c.String(unicode: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.machine_user",
c => new
{
id = c.Int(nullable: false, identity: true),
machine_id = c.Int(nullable: false),
user_id = c.Int(nullable: false),
role_id = c.Int(nullable: false),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.machine", t => t.machine_id, cascadeDelete: true)
.ForeignKey("dbo.role", t => t.role_id, cascadeDelete: true)
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
.Index(t => new { t.machine_id, t.user_id }, unique: true, clustered: true, name: "unique_machine_user")
.Index(t => t.role_id);
CreateTable(
"dbo.role",
c => new
{
id = c.Int(nullable: false, identity: true),
name = c.String(unicode: false),
level = c.Int(nullable: false),
})
.PrimaryKey(t => t.id);
CreateTable(
"dbo.maintenance_file",
c => new
{
id = c.Int(nullable: false, identity: true),
file_name = c.String(unicode: false),
local_file_name = c.String(unicode: false),
maintenance_id = c.Int(nullable: false),
user_id = c.Int(),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
.ForeignKey("dbo.user", t => t.user_id)
.Index(t => t.maintenance_id)
.Index(t => t.user_id);
CreateTable(
"dbo.maintenance",
c => new
{
id = c.Int(nullable: false),
intervall = c.Double(),
deadline = c.DateTime(nullable: false, precision: 0),
type = c.Int(nullable: false),
counter_id = c.Int(nullable: false),
title = c.String(unicode: false),
description = c.String(unicode: false),
unit_of_measure = c.Int(),
creation_date = c.DateTime(nullable: false, precision: 0),
last_expiration_date = c.DateTime(precision: 0),
user_id = c.Int(),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.user", t => t.user_id)
.Index(t => t.user_id);
CreateTable(
"dbo.maintenance_note",
c => new
{
id = c.Int(nullable: false, identity: true),
message = c.String(unicode: false),
user_id = c.Int(nullable: false),
maintenance_id = c.Int(nullable: false),
timestamp = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id, cascadeDelete: true)
.ForeignKey("dbo.user", t => t.user_id, cascadeDelete: true)
.Index(t => t.user_id)
.Index(t => t.maintenance_id);
CreateTable(
"dbo.performed_maintenance",
c => new
{
id = c.Int(nullable: false, identity: true),
date = c.DateTime(nullable: false, precision: 0),
counter_value = c.Int(nullable: false),
control_word = c.Int(nullable: false),
maintenance = c.Int(nullable: false),
maintainers_id = c.Int(),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.user", t => t.maintainers_id)
.ForeignKey("dbo.maintenance", t => t.maintenance, cascadeDelete: true)
.Index(t => t.maintenance)
.Index(t => t.maintainers_id);
CreateTable(
"dbo.queue",
c => new
{
id = c.Int(nullable: false),
process = c.Int(nullable: false),
part_program_name = c.String(unicode: false),
reps = c.Int(nullable: false),
remaining_reps = c.Int(nullable: false),
absolute_path = c.String(unicode: false),
status = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.id, t.process });
CreateTable(
"dbo.session",
c => new
{
id = c.Int(nullable: false, identity: true),
token = c.String(unicode: false),
machine_user_id = c.Int(nullable: false),
first_login = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.machine_user", t => t.machine_user_id, cascadeDelete: true)
.Index(t => t.machine_user_id);
}
public override void Down()
{
DropForeignKey("dbo.session", "machine_user_id", "dbo.machine_user");
DropForeignKey("dbo.performed_maintenance", "maintenance", "dbo.maintenance");
DropForeignKey("dbo.performed_maintenance", "maintainers_id", "dbo.user");
DropForeignKey("dbo.maintenance_note", "user_id", "dbo.user");
DropForeignKey("dbo.maintenance_note", "maintenance_id", "dbo.maintenance");
DropForeignKey("dbo.maintenance_file", "user_id", "dbo.user");
DropForeignKey("dbo.maintenance_file", "maintenance_id", "dbo.maintenance");
DropForeignKey("dbo.maintenance", "user_id", "dbo.user");
DropForeignKey("dbo.machine_user", "user_id", "dbo.user");
DropForeignKey("dbo.machine_user", "role_id", "dbo.role");
DropForeignKey("dbo.machine_user", "machine_id", "dbo.machine");
DropForeignKey("dbo.alarm_note", "user_id", "dbo.user");
DropForeignKey("dbo.alarm_user", "user_id", "dbo.user");
DropForeignKey("dbo.alarm_user", "alarm_occurence_id", "dbo.alarm_occurrence");
DropForeignKey("dbo.alarm_occurrence", "alarm_description_id", "dbo.alarm_description");
DropForeignKey("dbo.alarm_file", "user_id", "dbo.user");
DropIndex("dbo.session", new[] { "machine_user_id" });
DropIndex("dbo.performed_maintenance", new[] { "maintainers_id" });
DropIndex("dbo.performed_maintenance", new[] { "maintenance" });
DropIndex("dbo.maintenance_note", new[] { "maintenance_id" });
DropIndex("dbo.maintenance_note", new[] { "user_id" });
DropIndex("dbo.maintenance", new[] { "user_id" });
DropIndex("dbo.maintenance_file", new[] { "user_id" });
DropIndex("dbo.maintenance_file", new[] { "maintenance_id" });
DropIndex("dbo.machine_user", new[] { "role_id" });
DropIndex("dbo.machine_user", "unique_machine_user");
DropIndex("dbo.alarm_note", new[] { "user_id" });
DropIndex("dbo.alarm_user", new[] { "alarm_occurence_id" });
DropIndex("dbo.alarm_user", new[] { "user_id" });
DropIndex("dbo.alarm_occurrence", new[] { "alarm_description_id" });
DropIndex("dbo.alarm_file", new[] { "user_id" });
DropTable("dbo.session");
DropTable("dbo.queue");
DropTable("dbo.performed_maintenance");
DropTable("dbo.maintenance_note");
DropTable("dbo.maintenance");
DropTable("dbo.maintenance_file");
DropTable("dbo.role");
DropTable("dbo.machine_user");
DropTable("dbo.machine");
DropTable("dbo.function_access");
DropTable("dbo.favorite_user_softkey");
DropTable("dbo.family");
DropTable("dbo.alarm_note");
DropTable("dbo.alarm_user");
DropTable("dbo.alarm_occurrence");
DropTable("dbo.user");
DropTable("dbo.alarm_file");
DropTable("dbo.alarm_description");
}
}
}
File diff suppressed because one or more lines are too long
@@ -1,12 +1,15 @@
namespace Thermo.Active.Database.Migrations
{
using System;
using System.Data.Entity;
using System.Linq;
using Thermo.Active.Model.DatabaseModels;
using System.Data.Entity.Migrations;
using static Thermo.Active.Model.Constants.FUNCTIONALITY_NAMES;
using static Thermo.Active.Model.Constants.AREAS;
using static Thermo.Active.Model.Constants;
public sealed class Configuration : DbMigrationsConfiguration<DatabaseContext>
internal sealed class Configuration : DbMigrationsConfiguration<Thermo.Active.Database.DatabaseContext>
{
public Configuration()
{
@@ -15,7 +18,7 @@ namespace Thermo.Active.Database.Migrations
ContextKey = "Thermo.Active.Database.DatabaseContext";
}
protected override void Seed(DatabaseContext context)
protected override void Seed(Thermo.Active.Database.DatabaseContext context)
{
// This method will be called after migrating to the latest version. 0-99 Customer. 100 - 199 CMS
context.Roles.AddOrUpdate(
@@ -26,32 +29,27 @@ namespace Thermo.Active.Database.Migrations
new RoleModel() { RoleId = (int)ROLE_IDS.CUSTOMER_OPERATOR, Level = 20, Name = "Operator" },
new RoleModel() { RoleId = (int)ROLE_IDS.CUSTOMER_MAINTAINER, Level = 10, Name = "Maintainer" }
);
context.FunctionsAccess.AddOrUpdate(
// General Function, if plcId is 0 then the functionality is not connected to the NC
new FunctionAccessModel() { Name = GENERAL, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0},
new FunctionAccessModel() { Name = USER_FUNCTIONS, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0},
new FunctionAccessModel() { Name = NC_DATA, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0},
new FunctionAccessModel() { Name = ALARM_CMD, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 1},
new FunctionAccessModel() { Name = STARTUP_ICONS, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 2},
new FunctionAccessModel() { Name = GENERAL, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = USER_FUNCTIONS, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = NC_DATA, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = ALARM_CMD, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 1 },
new FunctionAccessModel() { Name = STARTUP_ICONS, Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 2 },
// Under hood
new FunctionAccessModel() { Name = PROCESS_CMD, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 3},
new FunctionAccessModel() { Name = NC_SOFTKEY, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 4},
new FunctionAccessModel() { Name = USER_SOFTKEY, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 5},
new FunctionAccessModel() { Name = HEADS_CMD, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 6},
new FunctionAccessModel() { Name = AXES_SELECTION, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 7},
#if false
new FunctionAccessModel() { Name = TOOL_MANAGER, Area = TOOLING_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 8 },
#endif
new FunctionAccessModel() { Name = MAINTENANCE, Area = MAINTENANCE_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 9},
new FunctionAccessModel() { Name = PROCESS_CMD, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 3 },
new FunctionAccessModel() { Name = NC_SOFTKEY, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 4 },
new FunctionAccessModel() { Name = USER_SOFTKEY, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 5 },
new FunctionAccessModel() { Name = HEADS_CMD, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 6 },
new FunctionAccessModel() { Name = AXES_SELECTION, Area = UNDER_HOOD, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 7 },
new FunctionAccessModel() { Name = MAINTENANCE, Area = MAINTENANCE_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 9 },
// Main Areas
// Main Areas
new FunctionAccessModel() { Name = "productionArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 20, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = "toolingArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 20, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = "reportArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 30, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = "alarmsArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 },
new FunctionAccessModel() { Name = "maintenanceArea", Area = GENERAL_KEY, Enabled = true, WriteLevelMin = 1, ReadLevelMin = 1, PlcId = 0 },
@@ -64,4 +62,4 @@ namespace Thermo.Active.Database.Migrations
context.SaveChanges();
}
}
}
}