namespace Rantory.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class OperationChemical : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.OperationChemicals",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        OperationId = c.Int(nullable: false),
                        ChemicalId = c.Int(nullable: false),
                        UnitId = c.Int(nullable: false),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        CurrencyId = c.Int(nullable: false),
                        Sum = c.Decimal(nullable: false, precision: 18, scale: 2),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Chemicals", t => t.ChemicalId, cascadeDelete: true)
                .ForeignKey("dbo.Currencies", t => t.CurrencyId, cascadeDelete: true)
                .ForeignKey("dbo.Operations", t => t.OperationId, cascadeDelete: true)
                .ForeignKey("dbo.Units", t => t.UnitId, cascadeDelete: true)
                .Index(t => t.OperationId)
                .Index(t => t.ChemicalId)
                .Index(t => t.UnitId)
                .Index(t => t.CurrencyId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.OperationChemicals", "UnitId", "dbo.Units");
            DropForeignKey("dbo.OperationChemicals", "OperationId", "dbo.Operations");
            DropForeignKey("dbo.OperationChemicals", "CurrencyId", "dbo.Currencies");
            DropForeignKey("dbo.OperationChemicals", "ChemicalId", "dbo.Chemicals");
            DropIndex("dbo.OperationChemicals", new[] { "CurrencyId" });
            DropIndex("dbo.OperationChemicals", new[] { "UnitId" });
            DropIndex("dbo.OperationChemicals", new[] { "ChemicalId" });
            DropIndex("dbo.OperationChemicals", new[] { "OperationId" });
            DropTable("dbo.OperationChemicals");
        }
    }
}
