using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Distribution.Migrations { /// public partial class initialDbCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Items", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Items", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Regions", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Name = table.Column(type: "longtext", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Regions", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Routes", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), RouteName = table.Column(type: "longtext", nullable: false), StartPoint = table.Column(type: "longtext", nullable: false), EndPoint = table.Column(type: "longtext", nullable: false), Length = table.Column(type: "decimal(18,2)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Routes", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "SaleRoutes", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SaleRoutes", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Stores", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), OwnerName = table.Column(type: "longtext", nullable: false), StoreName = table.Column(type: "longtext", nullable: false), StoreAddress = table.Column(type: "longtext", nullable: false), Latitude = table.Column(type: "decimal(18,2)", nullable: false), Longitude = table.Column(type: "decimal(18,2)", nullable: false), OneTimeAmount = table.Column(type: "decimal(18,2)", nullable: false), CreditAmount = table.Column(type: "decimal(18,2)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Stores", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Vehicles", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), RegNumber = table.Column(type: "longtext", nullable: false), NumberPlate = table.Column(type: "longtext", nullable: false), Type = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Vehicles", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Orders", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), OrderDate = table.Column(type: "datetime(6)", nullable: false), FK_StoreId = table.Column(type: "char(36)", nullable: false), TotalAmount = table.Column(type: "decimal(18,2)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( name: "FK_Orders_Stores_FK_StoreId", column: x => x.FK_StoreId, principalTable: "Stores", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "DeliveryRuns", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), FK_VehicleId = table.Column(type: "char(36)", nullable: false), Meterstart = table.Column(type: "int", nullable: false), Meterend = table.Column(type: "int", nullable: false), FK_RouteId = table.Column(type: "char(36)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DeliveryRuns", x => x.Id); table.ForeignKey( name: "FK_DeliveryRuns_Routes_FK_RouteId", column: x => x.FK_RouteId, principalTable: "Routes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_DeliveryRuns_Vehicles_FK_VehicleId", column: x => x.FK_VehicleId, principalTable: "Vehicles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Warehouses", columns: table => new { Id = table.Column(type: "char(36)", nullable: false), Name = table.Column(type: "longtext", nullable: false), Location = table.Column(type: "longtext", nullable: false), Type = table.Column(type: "int", nullable: false), VehicleId = table.Column(type: "char(36)", nullable: true), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Warehouses", x => x.Id); table.ForeignKey( name: "FK_Warehouses_Vehicles_VehicleId", column: x => x.VehicleId, principalTable: "Vehicles", principalColumn: "Id"); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "OrderItems", columns: table => new { FK_OrderId = table.Column(type: "char(36)", nullable: false), FK_ItemId = table.Column(type: "char(36)", nullable: false), Quantity = table.Column(type: "int", nullable: false), Id = table.Column(type: "char(36)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderItems", x => new { x.FK_OrderId, x.FK_ItemId }); table.ForeignKey( name: "FK_OrderItems_Items_FK_ItemId", column: x => x.FK_ItemId, principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OrderItems_Orders_FK_OrderId", column: x => x.FK_OrderId, principalTable: "Orders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_DeliveryRuns_FK_RouteId", table: "DeliveryRuns", column: "FK_RouteId"); migrationBuilder.CreateIndex( name: "IX_DeliveryRuns_FK_VehicleId", table: "DeliveryRuns", column: "FK_VehicleId"); migrationBuilder.CreateIndex( name: "IX_OrderItems_FK_ItemId", table: "OrderItems", column: "FK_ItemId"); migrationBuilder.CreateIndex( name: "IX_Orders_FK_StoreId", table: "Orders", column: "FK_StoreId"); migrationBuilder.CreateIndex( name: "IX_Warehouses_VehicleId", table: "Warehouses", column: "VehicleId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "DeliveryRuns"); migrationBuilder.DropTable( name: "OrderItems"); migrationBuilder.DropTable( name: "Regions"); migrationBuilder.DropTable( name: "SaleRoutes"); migrationBuilder.DropTable( name: "Warehouses"); migrationBuilder.DropTable( name: "Routes"); migrationBuilder.DropTable( name: "Items"); migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "Vehicles"); migrationBuilder.DropTable( name: "Stores"); } } }