Files
cms_thermo_active/Thermo.Active.Database/Migrations/201806130949510_InitMigration.cs
T
2020-04-09 13:15:01 +02:00

166 lines
7.2 KiB
C#

namespace Step.Database.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class InitMigration : DbMigration
{
public override void Up()
{
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.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.maintenance",
c => new
{
id = c.Int(nullable: false, identity: true),
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),
maintenance_id = c.Int(),
user_id = c.Int(),
timestamp = c.DateTime(nullable: false, precision: 0),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.maintenance", t => t.maintenance_id)
.ForeignKey("dbo.user", t => t.user_id)
.Index(t => t.maintenance_id)
.Index(t => t.user_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.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", "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");
DropIndex("dbo.session", new[] { "machine_user_id" });
DropIndex("dbo.performed_maintenance", new[] { "maintenance" });
DropIndex("dbo.maintenance_note", new[] { "user_id" });
DropIndex("dbo.maintenance_note", new[] { "maintenance_id" });
DropIndex("dbo.maintenance", new[] { "user_id" });
DropIndex("dbo.machine_user", new[] { "role_id" });
DropIndex("dbo.machine_user", "unique_machine_user");
DropTable("dbo.session");
DropTable("dbo.performed_maintenance");
DropTable("dbo.maintenance_note");
DropTable("dbo.maintenance");
DropTable("dbo.user");
DropTable("dbo.role");
DropTable("dbo.machine_user");
DropTable("dbo.machine");
DropTable("dbo.function_access");
}
}
}