Потерли базу данных и сделали новую

This commit is contained in:
Katanaa Die 2024-04-30 20:43:17 +04:00
parent a7eb217ea0
commit a7d997664e
3 changed files with 171 additions and 189 deletions

View File

@ -12,8 +12,8 @@ using VetclinicDatabaseImplement;
namespace VetclinicDatabaseImplement.Migrations
{
[DbContext(typeof(VetclinicDatabase))]
[Migration("20240428173727_test3")]
partial class test3
[Migration("20240430164234_test123")]
partial class test123
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -167,6 +167,9 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
@ -174,6 +177,8 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ServiceId");
b.ToTable("DoctorVisits");
});
@ -192,9 +197,6 @@ namespace VetclinicDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("DrugPurchaseId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -202,9 +204,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("DoctorId");
b.HasIndex("DrugPurchaseId")
.IsUnique();
b.ToTable("Drugs");
});
@ -257,6 +256,9 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<DateTime>("DatePurchase")
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
@ -264,6 +266,8 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("DrugId");
b.ToTable("DrugPurchases");
});
@ -303,9 +307,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<int>("DoctorVisitId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -317,9 +318,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("DoctorId");
b.HasIndex("DoctorVisitId")
.IsUnique();
b.ToTable("Services");
});
@ -404,7 +402,15 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.Service", "Service")
.WithMany()
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Service");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Drug", b =>
@ -415,15 +421,7 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.DrugPurchase", "DrugPurchase")
.WithOne("Drug")
.HasForeignKey("VetclinicDatabaseImplement.Models.Drug", "DrugPurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Doctor");
b.Navigation("DrugPurchase");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DrugMedicines", b =>
@ -453,7 +451,15 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.Drug", "Drug")
.WithMany()
.HasForeignKey("DrugId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Drug");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Medicine", b =>
@ -475,15 +481,7 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.DoctorVisit", "DoctorVisit")
.WithOne("Service")
.HasForeignKey("VetclinicDatabaseImplement.Models.Service", "DoctorVisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Doctor");
b.Navigation("DoctorVisit");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.ServiceMedicines", b =>
@ -531,9 +529,6 @@ namespace VetclinicDatabaseImplement.Migrations
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DoctorVisit", b =>
{
b.Navigation("Animals");
b.Navigation("Service")
.IsRequired();
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Drug", b =>
@ -544,9 +539,6 @@ namespace VetclinicDatabaseImplement.Migrations
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DrugPurchase", b =>
{
b.Navigation("AnimalDrugPurchase");
b.Navigation("Drug")
.IsRequired();
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Medicine", b =>

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace VetclinicDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class test3 : Migration
public partial class test123 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -64,46 +64,22 @@ namespace VetclinicDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "DoctorVisits",
name: "Drugs",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Status = table.Column<int>(type: "int", nullable: false),
DateVisit = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false)
DrugName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
DoctorId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DoctorVisits", x => x.Id);
table.PrimaryKey("PK_Drugs", x => x.Id);
table.ForeignKey(
name: "FK_DoctorVisits_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DrugPurchases",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Cost = table.Column<double>(type: "float", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
DatePurchase = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DrugPurchases", x => x.Id);
table.ForeignKey(
name: "FK_DrugPurchases_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
name: "FK_Drugs_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -129,39 +105,12 @@ namespace VetclinicDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AnimalDoctorVisit",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AnimalId = table.Column<int>(type: "int", nullable: false),
DoctorVisitId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AnimalDoctorVisit", x => x.Id);
table.ForeignKey(
name: "FK_AnimalDoctorVisit_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AnimalDoctorVisit_DoctorVisits_DoctorVisitId",
column: x => x.DoctorVisitId,
principalTable: "DoctorVisits",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DoctorVisitId = table.Column<int>(type: "int", nullable: false),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
DoctorId = table.Column<int>(type: "int", nullable: false)
@ -169,71 +118,96 @@ namespace VetclinicDatabaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
table.ForeignKey(
name: "FK_Services_DoctorVisits_DoctorVisitId",
column: x => x.DoctorVisitId,
principalTable: "DoctorVisits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Services_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AnimalDrugPurchases",
name: "DrugPurchases",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AnimalId = table.Column<int>(type: "int", nullable: false),
DrugPurchaseId = table.Column<int>(type: "int", nullable: false),
DrugPurchasesId = table.Column<int>(type: "int", nullable: false)
Cost = table.Column<double>(type: "float", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
DatePurchase = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
DrugId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AnimalDrugPurchases", x => x.Id);
table.PrimaryKey("PK_DrugPurchases", x => x.Id);
table.ForeignKey(
name: "FK_AnimalDrugPurchases_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
name: "FK_DrugPurchases_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AnimalDrugPurchases_DrugPurchases_DrugPurchasesId",
column: x => x.DrugPurchasesId,
principalTable: "DrugPurchases",
name: "FK_DrugPurchases_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Drugs",
name: "DrugMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DrugPurchaseId = table.Column<int>(type: "int", nullable: false),
DrugName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
DoctorId = table.Column<int>(type: "int", nullable: false)
DrugId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Drugs", x => x.Id);
table.PrimaryKey("PK_DrugMedicines", x => x.Id);
table.ForeignKey(
name: "FK_Drugs_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
name: "FK_DrugMedicines_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Drugs_DrugPurchases_DrugPurchaseId",
column: x => x.DrugPurchaseId,
principalTable: "DrugPurchases",
name: "FK_DrugMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "DoctorVisits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Status = table.Column<int>(type: "int", nullable: false),
DateVisit = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
ServiceId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DoctorVisits", x => x.Id);
table.ForeignKey(
name: "FK_DoctorVisits_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DoctorVisits_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@ -266,28 +240,54 @@ namespace VetclinicDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "DrugMedicines",
name: "AnimalDrugPurchases",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DrugId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
AnimalId = table.Column<int>(type: "int", nullable: false),
DrugPurchaseId = table.Column<int>(type: "int", nullable: false),
DrugPurchasesId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DrugMedicines", x => x.Id);
table.PrimaryKey("PK_AnimalDrugPurchases", x => x.Id);
table.ForeignKey(
name: "FK_DrugMedicines_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
name: "FK_AnimalDrugPurchases_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DrugMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
name: "FK_AnimalDrugPurchases_DrugPurchases_DrugPurchasesId",
column: x => x.DrugPurchasesId,
principalTable: "DrugPurchases",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "AnimalDoctorVisit",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AnimalId = table.Column<int>(type: "int", nullable: false),
DoctorVisitId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AnimalDoctorVisit", x => x.Id);
table.ForeignKey(
name: "FK_AnimalDoctorVisit_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AnimalDoctorVisit_DoctorVisits_DoctorVisitId",
column: x => x.DoctorVisitId,
principalTable: "DoctorVisits",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
@ -322,6 +322,11 @@ namespace VetclinicDatabaseImplement.Migrations
table: "DoctorVisits",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_DoctorVisits_ServiceId",
table: "DoctorVisits",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_DrugMedicines_DrugId",
table: "DrugMedicines",
@ -337,17 +342,16 @@ namespace VetclinicDatabaseImplement.Migrations
table: "DrugPurchases",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_DrugPurchases_DrugId",
table: "DrugPurchases",
column: "DrugId");
migrationBuilder.CreateIndex(
name: "IX_Drugs_DoctorId",
table: "Drugs",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Drugs_DrugPurchaseId",
table: "Drugs",
column: "DrugPurchaseId",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Medicines_DoctorId",
table: "Medicines",
@ -367,12 +371,6 @@ namespace VetclinicDatabaseImplement.Migrations
name: "IX_Services_DoctorId",
table: "Services",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Services_DoctorVisitId",
table: "Services",
column: "DoctorVisitId",
unique: true);
}
/// <inheritdoc />
@ -390,11 +388,14 @@ namespace VetclinicDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "ServiceMedicines");
migrationBuilder.DropTable(
name: "DoctorVisits");
migrationBuilder.DropTable(
name: "Animals");
migrationBuilder.DropTable(
name: "Drugs");
name: "DrugPurchases");
migrationBuilder.DropTable(
name: "Medicines");
@ -403,16 +404,13 @@ namespace VetclinicDatabaseImplement.Migrations
name: "Services");
migrationBuilder.DropTable(
name: "DrugPurchases");
name: "Clients");
migrationBuilder.DropTable(
name: "DoctorVisits");
name: "Drugs");
migrationBuilder.DropTable(
name: "Doctors");
migrationBuilder.DropTable(
name: "Clients");
}
}
}

View File

@ -164,6 +164,9 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
@ -171,6 +174,8 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ServiceId");
b.ToTable("DoctorVisits");
});
@ -189,9 +194,6 @@ namespace VetclinicDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("DrugPurchaseId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -199,9 +201,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("DoctorId");
b.HasIndex("DrugPurchaseId")
.IsUnique();
b.ToTable("Drugs");
});
@ -254,6 +253,9 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<DateTime>("DatePurchase")
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
@ -261,6 +263,8 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("DrugId");
b.ToTable("DrugPurchases");
});
@ -300,9 +304,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<int>("DoctorVisitId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -314,9 +315,6 @@ namespace VetclinicDatabaseImplement.Migrations
b.HasIndex("DoctorId");
b.HasIndex("DoctorVisitId")
.IsUnique();
b.ToTable("Services");
});
@ -401,7 +399,15 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.Service", "Service")
.WithMany()
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Service");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Drug", b =>
@ -412,15 +418,7 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.DrugPurchase", "DrugPurchase")
.WithOne("Drug")
.HasForeignKey("VetclinicDatabaseImplement.Models.Drug", "DrugPurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Doctor");
b.Navigation("DrugPurchase");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DrugMedicines", b =>
@ -450,7 +448,15 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.Drug", "Drug")
.WithMany()
.HasForeignKey("DrugId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Drug");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Medicine", b =>
@ -472,15 +478,7 @@ namespace VetclinicDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetclinicDatabaseImplement.Models.DoctorVisit", "DoctorVisit")
.WithOne("Service")
.HasForeignKey("VetclinicDatabaseImplement.Models.Service", "DoctorVisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Doctor");
b.Navigation("DoctorVisit");
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.ServiceMedicines", b =>
@ -528,9 +526,6 @@ namespace VetclinicDatabaseImplement.Migrations
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DoctorVisit", b =>
{
b.Navigation("Animals");
b.Navigation("Service")
.IsRequired();
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Drug", b =>
@ -541,9 +536,6 @@ namespace VetclinicDatabaseImplement.Migrations
modelBuilder.Entity("VetclinicDatabaseImplement.Models.DrugPurchase", b =>
{
b.Navigation("AnimalDrugPurchase");
b.Navigation("Drug")
.IsRequired();
});
modelBuilder.Entity("VetclinicDatabaseImplement.Models.Medicine", b =>