using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; namespace GreenTree.Strohrmann.ERP.Domain.Migrations { public partial class BusinessModel : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "EmployeeDegrees", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), Value = table.Column(nullable: false), Order = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_EmployeeDegrees", x => x.Id); }); migrationBuilder.CreateTable( name: "Suppliers", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), Description = table.Column(nullable: true), Address = table.Column(nullable: false), Town = table.Column(nullable: false), ZipCode = table.Column(nullable: false), Country = table.Column(nullable: false), PhoneFirst = table.Column(nullable: true), PhoneSecond = table.Column(nullable: true), MailFirst = table.Column(nullable: true), MailSecond = table.Column(nullable: true), Comment = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Suppliers", x => x.Id); }); migrationBuilder.CreateTable( name: "Taxes", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), ShortName = table.Column(nullable: false), Value = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Taxes", x => x.Id); }); migrationBuilder.CreateTable( name: "Units", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), ShortName = table.Column(nullable: false), Description = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_Units", x => x.Id); }); migrationBuilder.CreateTable( name: "Employees", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Firstname = table.Column(nullable: false), Lastname = table.Column(nullable: false), MailAddress = table.Column(nullable: true), Birthdate = table.Column(nullable: true), EmployeeDegreeId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Employees", x => x.Id); table.ForeignKey( name: "FK_Employees_EmployeeDegrees_EmployeeDegreeId", column: x => x.EmployeeDegreeId, principalTable: "EmployeeDegrees", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Customers", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Firstname = table.Column(nullable: false), Lastname = table.Column(nullable: false), CompanyName = table.Column(nullable: true), Address = table.Column(nullable: false), Town = table.Column(nullable: false), ZipCode = table.Column(nullable: false), Country = table.Column(nullable: false), TaxId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Customers", x => x.Id); table.ForeignKey( name: "FK_Customers_Taxes_TaxId", column: x => x.TaxId, principalTable: "Taxes", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Materials", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), ItemNumber = table.Column(nullable: false), Description = table.Column(nullable: false), NetValue = table.Column(nullable: false), Height = table.Column(nullable: false), Width = table.Column(nullable: false), Depth = table.Column(nullable: false), DefaultUnitId = table.Column(nullable: false), SupplierId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Materials", x => x.Id); table.ForeignKey( name: "FK_Materials_Units_DefaultUnitId", column: x => x.DefaultUnitId, principalTable: "Units", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Materials_Suppliers_SupplierId", column: x => x.SupplierId, principalTable: "Suppliers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Crafts", columns: table => new { Id = table.Column(nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(nullable: false), CreationDate = table.Column(nullable: false), CustomerId = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_Crafts", x => x.Id); table.ForeignKey( name: "FK_Crafts_Customers_CustomerId", column: x => x.CustomerId, principalTable: "Customers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "CraftEmployees", columns: table => new { CraftId = table.Column(nullable: false), EmployeeId = table.Column(nullable: false), Amount = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_CraftEmployees", x => new { x.CraftId, x.EmployeeId }); table.ForeignKey( name: "FK_CraftEmployees_Crafts_CraftId", column: x => x.CraftId, principalTable: "Crafts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CraftEmployees_Employees_EmployeeId", column: x => x.EmployeeId, principalTable: "Employees", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "CraftMaterials", columns: table => new { CraftId = table.Column(nullable: false), MaterialId = table.Column(nullable: false), Amount = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_CraftMaterials", x => new { x.CraftId, x.MaterialId }); table.ForeignKey( name: "FK_CraftMaterials_Crafts_CraftId", column: x => x.CraftId, principalTable: "Crafts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CraftMaterials_Materials_MaterialId", column: x => x.MaterialId, principalTable: "Materials", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.InsertData( table: "Taxes", columns: new[] { "Id", "Name", "ShortName", "Value" }, values: new object[,] { { 1, "Deutschland Umsatzsteuer", "Umst. (19%)", 0.19m }, { 2, "Deutschland Umsatzsteuer 2020", "Umst. (16%) 2020", 0.16m } }); migrationBuilder.InsertData( table: "Units", columns: new[] { "Id", "Description", "Name", "ShortName" }, values: new object[,] { { 1, "Angabe in Einheit Meter", "Meter", "m" }, { 2, "Angabe in Einheit Quadratmeter", "Quadratmeter", "m²" }, { 3, "Angabe in Einheit Kubikmeter", "Kubikmeter", "m³" }, { 4, "Angabe in Einheit Liter", "Liter", "l" }, { 5, "Angabe in Stückzahl", "Stück", "Stck." }, { 6, "Angabe in Stückzahl", "Kilogramm", "Kg" }, { 7, "Angabe in Zeitstunden", "Stunden", "Std." } }); migrationBuilder.CreateIndex( name: "IX_CraftEmployees_EmployeeId", table: "CraftEmployees", column: "EmployeeId"); migrationBuilder.CreateIndex( name: "IX_CraftMaterials_MaterialId", table: "CraftMaterials", column: "MaterialId"); migrationBuilder.CreateIndex( name: "IX_Crafts_CustomerId", table: "Crafts", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Customers_TaxId", table: "Customers", column: "TaxId"); migrationBuilder.CreateIndex( name: "IX_Employees_EmployeeDegreeId", table: "Employees", column: "EmployeeDegreeId"); migrationBuilder.CreateIndex( name: "IX_Materials_DefaultUnitId", table: "Materials", column: "DefaultUnitId"); migrationBuilder.CreateIndex( name: "IX_Materials_SupplierId", table: "Materials", column: "SupplierId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "CraftEmployees"); migrationBuilder.DropTable( name: "CraftMaterials"); migrationBuilder.DropTable( name: "Employees"); migrationBuilder.DropTable( name: "Crafts"); migrationBuilder.DropTable( name: "Materials"); migrationBuilder.DropTable( name: "EmployeeDegrees"); migrationBuilder.DropTable( name: "Customers"); migrationBuilder.DropTable( name: "Units"); migrationBuilder.DropTable( name: "Suppliers"); migrationBuilder.DropTable( name: "Taxes"); } } }