341 lines
15 KiB
C#
341 lines
15 KiB
C#
namespace Step.Database.Migrations
|
|
{
|
|
using System;
|
|
using System.Data.Entity.Migrations;
|
|
|
|
public partial class InitMigration : DbMigration
|
|
{
|
|
public override void Up()
|
|
{
|
|
CreateTable(
|
|
"dbo.alarm_description",
|
|
c => new
|
|
{
|
|
id = c.Int(nullable: false, identity: true),
|
|
title = c.String(unicode: false),
|
|
description = c.String(unicode: false),
|
|
})
|
|
.PrimaryKey(t => t.id);
|
|
|
|
CreateTable(
|
|
"dbo.alarm_occurrence",
|
|
c => new
|
|
{
|
|
id = c.Int(nullable: false, identity: true),
|
|
alarm_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_id)
|
|
.Index(t => t.alarm_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.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),
|
|
})
|
|
.PrimaryKey(t => t.id);
|
|
|
|
CreateTable(
|
|
"dbo.family",
|
|
c => new
|
|
{
|
|
id = c.Int(nullable: false, identity: true),
|
|
name = c.String(unicode: false),
|
|
type = c.Byte(nullable: 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.tool",
|
|
c => new
|
|
{
|
|
id = c.Int(nullable: false, identity: true),
|
|
offset_length = c.Int(nullable: false),
|
|
residual_life = c.Int(nullable: false),
|
|
residual_revive = c.Int(nullable: false),
|
|
status = c.Byte(nullable: false),
|
|
family_id = c.Int(nullable: false),
|
|
shank_id = c.Int(),
|
|
offsetId1 = c.Int(),
|
|
offsetId2 = c.Int(),
|
|
offsetId3 = c.Int(),
|
|
})
|
|
.PrimaryKey(t => t.id)
|
|
.ForeignKey("dbo.family", t => t.family_id, cascadeDelete: true)
|
|
.ForeignKey("dbo.shank", t => t.shank_id)
|
|
.Index(t => t.family_id)
|
|
.Index(t => t.shank_id);
|
|
|
|
CreateTable(
|
|
"dbo.shank",
|
|
c => new
|
|
{
|
|
magazine_id = c.Byte(),
|
|
position_id = c.Byte(),
|
|
id = c.Int(nullable: false, identity: true),
|
|
balluf = c.Int(),
|
|
magazine_position_type = c.Byte(nullable: false),
|
|
})
|
|
.PrimaryKey(t => t.id)
|
|
.ForeignKey("dbo.magazine_position", t => new { t.magazine_id, t.position_id })
|
|
.Index(t => new { t.magazine_id, t.position_id });
|
|
|
|
CreateTable(
|
|
"dbo.magazine_position",
|
|
c => new
|
|
{
|
|
magazine_id = c.Byte(nullable: false),
|
|
position_id = c.Byte(nullable: false),
|
|
type = c.Byte(nullable: false),
|
|
disabled = c.Boolean(nullable: false),
|
|
})
|
|
.PrimaryKey(t => new { t.magazine_id, t.position_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),
|
|
maintenance = c.Int(nullable: false),
|
|
})
|
|
.PrimaryKey(t => t.id)
|
|
.ForeignKey("dbo.maintenance", t => t.maintenance, cascadeDelete: true)
|
|
.Index(t => t.maintenance);
|
|
|
|
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),
|
|
})
|
|
.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.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.tool", "shank_id", "dbo.shank");
|
|
DropForeignKey("dbo.shank", new[] { "magazine_id", "position_id" }, "dbo.magazine_position");
|
|
DropForeignKey("dbo.tool", "family_id", "dbo.family");
|
|
DropForeignKey("dbo.alarm_user", "user_id", "dbo.user");
|
|
DropForeignKey("dbo.alarm_user", "alarm_occurence_id", "dbo.alarm_occurrence");
|
|
DropForeignKey("dbo.alarm_occurrence", "alarm_id", "dbo.alarm_description");
|
|
DropIndex("dbo.session", new[] { "machine_user_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.shank", new[] { "magazine_id", "position_id" });
|
|
DropIndex("dbo.tool", new[] { "shank_id" });
|
|
DropIndex("dbo.tool", new[] { "family_id" });
|
|
DropIndex("dbo.alarm_user", new[] { "alarm_occurence_id" });
|
|
DropIndex("dbo.alarm_user", new[] { "user_id" });
|
|
DropIndex("dbo.alarm_occurrence", new[] { "alarm_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.magazine_position");
|
|
DropTable("dbo.shank");
|
|
DropTable("dbo.tool");
|
|
DropTable("dbo.family");
|
|
DropTable("dbo.user");
|
|
DropTable("dbo.alarm_user");
|
|
DropTable("dbo.alarm_occurrence");
|
|
DropTable("dbo.alarm_description");
|
|
}
|
|
}
|
|
}
|