PIbd-22_Filippov_D.S._Cours.../VeterinaryDatabaseImplement/Migrations/20240529175621_InitialCreate10.cs
2024-05-30 07:33:38 +04:00

490 lines
21 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace VeterinaryDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate10 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Doctors",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DoctorFIO = table.Column<string>(type: "text", nullable: false),
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Doctors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Owners",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OwnerFIO = table.Column<string>(type: "text", nullable: false),
Login = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Owners", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Drugs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DrugName = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
DoctorId = table.Column<int>(type: "integer", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Drugs", x => x.Id);
table.ForeignKey(
name: "FK_Drugs_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Medications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MedicationName = table.Column<string>(type: "text", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
DoctorId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Medications", x => x.Id);
table.ForeignKey(
name: "FK_Medications_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Visits",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OwnerId = table.Column<int>(type: "integer", nullable: false),
DoctorId = table.Column<int>(type: "integer", nullable: false),
VisitName = table.Column<string>(type: "text", nullable: false),
DateVisit = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.Id);
table.ForeignKey(
name: "FK_Visits_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Visits_Owners_OwnerId",
column: x => x.OwnerId,
principalTable: "Owners",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Purchases",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OwnerId = table.Column<int>(type: "integer", nullable: false),
PuchaseName = table.Column<string>(type: "text", nullable: false),
DrugId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Purchases", x => x.Id);
table.ForeignKey(
name: "FK_Purchases_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Purchases_Owners_OwnerId",
column: x => x.OwnerId,
principalTable: "Owners",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DrugMedications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DrugId = table.Column<int>(type: "integer", nullable: false),
MedicationId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DrugMedications", x => x.Id);
table.ForeignKey(
name: "FK_DrugMedications_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DrugMedications_Medications_MedicationId",
column: x => x.MedicationId,
principalTable: "Medications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Pets",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OwnerId = table.Column<int>(type: "integer", nullable: false),
PetName = table.Column<string>(type: "text", nullable: false),
PetType = table.Column<string>(type: "text", nullable: false),
PetBreed = table.Column<string>(type: "text", nullable: false),
PetGender = table.Column<string>(type: "text", nullable: false),
MedicationId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Pets", x => x.Id);
table.ForeignKey(
name: "FK_Pets_Medications_MedicationId",
column: x => x.MedicationId,
principalTable: "Medications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Pets_Owners_OwnerId",
column: x => x.OwnerId,
principalTable: "Owners",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceName = table.Column<string>(type: "text", nullable: false),
DoctorId = table.Column<int>(type: "integer", nullable: false),
VisitId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
table.ForeignKey(
name: "FK_Services_Doctors_DoctorId",
column: x => x.DoctorId,
principalTable: "Doctors",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Services_Visits_VisitId",
column: x => x.VisitId,
principalTable: "Visits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PurchasePets",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PurchaseId = table.Column<int>(type: "integer", nullable: false),
PetId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchasePets", x => x.Id);
table.ForeignKey(
name: "FK_PurchasePets_Pets_PetId",
column: x => x.PetId,
principalTable: "Pets",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchasePets_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VisitPets",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
VisitId = table.Column<int>(type: "integer", nullable: false),
PetId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_VisitPets", x => x.Id);
table.ForeignKey(
name: "FK_VisitPets_Pets_PetId",
column: x => x.PetId,
principalTable: "Pets",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_VisitPets_Visits_VisitId",
column: x => x.VisitId,
principalTable: "Visits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "DrugServices",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DrugId = table.Column<int>(type: "integer", nullable: false),
ServiceId = table.Column<int>(type: "integer", nullable: false),
MedicationId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DrugServices", x => x.Id);
table.ForeignKey(
name: "FK_DrugServices_Drugs_DrugId",
column: x => x.DrugId,
principalTable: "Drugs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_DrugServices_Medications_MedicationId",
column: x => x.MedicationId,
principalTable: "Medications",
principalColumn: "Id");
table.ForeignKey(
name: "FK_DrugServices_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ServiceMedications",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceId = table.Column<int>(type: "integer", nullable: false),
MedicationId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceMedications", x => x.Id);
table.ForeignKey(
name: "FK_ServiceMedications_Medications_MedicationId",
column: x => x.MedicationId,
principalTable: "Medications",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ServiceMedications_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_DrugMedications_DrugId",
table: "DrugMedications",
column: "DrugId");
migrationBuilder.CreateIndex(
name: "IX_DrugMedications_MedicationId",
table: "DrugMedications",
column: "MedicationId");
migrationBuilder.CreateIndex(
name: "IX_Drugs_DoctorId",
table: "Drugs",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_DrugServices_DrugId",
table: "DrugServices",
column: "DrugId");
migrationBuilder.CreateIndex(
name: "IX_DrugServices_MedicationId",
table: "DrugServices",
column: "MedicationId");
migrationBuilder.CreateIndex(
name: "IX_DrugServices_ServiceId",
table: "DrugServices",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_Medications_DoctorId",
table: "Medications",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Pets_MedicationId",
table: "Pets",
column: "MedicationId");
migrationBuilder.CreateIndex(
name: "IX_Pets_OwnerId",
table: "Pets",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_PurchasePets_PetId",
table: "PurchasePets",
column: "PetId");
migrationBuilder.CreateIndex(
name: "IX_PurchasePets_PurchaseId",
table: "PurchasePets",
column: "PurchaseId");
migrationBuilder.CreateIndex(
name: "IX_Purchases_DrugId",
table: "Purchases",
column: "DrugId");
migrationBuilder.CreateIndex(
name: "IX_Purchases_OwnerId",
table: "Purchases",
column: "OwnerId");
migrationBuilder.CreateIndex(
name: "IX_ServiceMedications_MedicationId",
table: "ServiceMedications",
column: "MedicationId");
migrationBuilder.CreateIndex(
name: "IX_ServiceMedications_ServiceId",
table: "ServiceMedications",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_Services_DoctorId",
table: "Services",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Services_VisitId",
table: "Services",
column: "VisitId");
migrationBuilder.CreateIndex(
name: "IX_VisitPets_PetId",
table: "VisitPets",
column: "PetId");
migrationBuilder.CreateIndex(
name: "IX_VisitPets_VisitId",
table: "VisitPets",
column: "VisitId");
migrationBuilder.CreateIndex(
name: "IX_Visits_DoctorId",
table: "Visits",
column: "DoctorId");
migrationBuilder.CreateIndex(
name: "IX_Visits_OwnerId",
table: "Visits",
column: "OwnerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DrugMedications");
migrationBuilder.DropTable(
name: "DrugServices");
migrationBuilder.DropTable(
name: "PurchasePets");
migrationBuilder.DropTable(
name: "ServiceMedications");
migrationBuilder.DropTable(
name: "VisitPets");
migrationBuilder.DropTable(
name: "Purchases");
migrationBuilder.DropTable(
name: "Services");
migrationBuilder.DropTable(
name: "Pets");
migrationBuilder.DropTable(
name: "Drugs");
migrationBuilder.DropTable(
name: "Visits");
migrationBuilder.DropTable(
name: "Medications");
migrationBuilder.DropTable(
name: "Owners");
migrationBuilder.DropTable(
name: "Doctors");
}
}
}