namespace Vrh.iScheduler.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialDB : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "iScheduler.ScheduleObjects",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ObjectType = c.String(nullable: false, maxLength: 100),
                        ObjectId = c.String(nullable: false, maxLength: 100),
                        ObjectName = c.String(nullable: false, maxLength: 200),
                        ObjectGroupId = c.String(nullable: false, maxLength: 100),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => new { t.ObjectType, t.ObjectId }, unique: true, name: "IX_ScheduleObject_ObjectTypeObjectId");
            
            CreateTable(
                "iScheduler.Schedules",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ScheduleObjectId = c.Int(nullable: false),
                        ScheduleOperationId = c.Short(nullable: false),
                        OperationTime = c.DateTime(nullable: false),
                        State = c.Byte(nullable: false),
                        ScheduleSeriesId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("iScheduler.ScheduleObjects", t => t.ScheduleObjectId)
                .ForeignKey("iScheduler.ScheduleOperations", t => t.ScheduleOperationId)
                .ForeignKey("iScheduler.ScheduleSeries", t => t.ScheduleSeriesId)
                .Index(t => t.ScheduleObjectId)
                .Index(t => t.ScheduleOperationId)
                .Index(t => t.ScheduleSeriesId);
            
            CreateTable(
                "iScheduler.ScheduleOperations",
                c => new
                    {
                        Id = c.Short(nullable: false, identity: true),
                        ObjectType = c.String(nullable: false, maxLength: 100),
                        OperationId = c.String(nullable: false, maxLength: 100),
                        OperationName = c.String(nullable: false, maxLength: 200),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => new { t.ObjectType, t.OperationId }, unique: true, name: "IX_ScheduleOperation_ObjectTypeOperationId");
            
            CreateTable(
                "iScheduler.ScheduleSeries",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        SeriesType = c.String(nullable: false, maxLength: 100),
                        SeriesColor = c.String(maxLength: 30),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("iScheduler.Schedules", "ScheduleSeriesId", "iScheduler.ScheduleSeries");
            DropForeignKey("iScheduler.Schedules", "ScheduleOperationId", "iScheduler.ScheduleOperations");
            DropForeignKey("iScheduler.Schedules", "ScheduleObjectId", "iScheduler.ScheduleObjects");
            DropIndex("iScheduler.ScheduleOperations", "IX_ScheduleOperation_ObjectTypeOperationId");
            DropIndex("iScheduler.Schedules", new[] { "ScheduleSeriesId" });
            DropIndex("iScheduler.Schedules", new[] { "ScheduleOperationId" });
            DropIndex("iScheduler.Schedules", new[] { "ScheduleObjectId" });
            DropIndex("iScheduler.ScheduleObjects", "IX_ScheduleObject_ObjectTypeObjectId");
            DropTable("iScheduler.ScheduleSeries");
            DropTable("iScheduler.ScheduleOperations");
            DropTable("iScheduler.Schedules");
            DropTable("iScheduler.ScheduleObjects");
        }
    }
}
