Подключение к серверу

This commit is contained in:
ArtemEmelyanov 2023-05-02 12:46:36 +04:00
parent e949397d5a
commit 721c875694
4 changed files with 348 additions and 1 deletions

View File

@ -15,7 +15,7 @@ namespace ForumDatabase
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=SUBD;Username=postgres;Password=postgres");
optionsBuilder.UseNpgsql("Host=192.168.56.104;Port=5432;Database=ForumSubd;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,196 @@
// <auto-generated />
using System;
using ForumDatabase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace ForumDatabase.Migrations
{
[DbContext(typeof(ForumDatabase))]
[Migration("20230502084230_ConnectToServer")]
partial class ConnectToServer
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ForumDatabase.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("ForumDatabase.Models.Message", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<int>("TopicId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("TopicId");
b.HasIndex("UserId");
b.ToTable("Messages");
});
modelBuilder.Entity("ForumDatabase.Models.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("ForumDatabase.Models.Topic", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CategoryId")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Topics");
});
modelBuilder.Entity("ForumDatabase.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("RegistrationDate")
.HasColumnType("timestamp with time zone");
b.Property<int>("RoleId")
.HasColumnType("integer");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("ForumDatabase.Models.Message", b =>
{
b.HasOne("ForumDatabase.Models.Topic", "Topic")
.WithMany()
.HasForeignKey("TopicId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ForumDatabase.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Topic");
b.Navigation("User");
});
modelBuilder.Entity("ForumDatabase.Models.Topic", b =>
{
b.HasOne("ForumDatabase.Models.Category", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("ForumDatabase.Models.User", b =>
{
b.HasOne("ForumDatabase.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,102 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ForumDatabase.Migrations
{
/// <inheritdoc />
public partial class ConnectToServer : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_Users_RoleId",
table: "Users",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_Topics_CategoryId",
table: "Topics",
column: "CategoryId");
migrationBuilder.CreateIndex(
name: "IX_Messages_TopicId",
table: "Messages",
column: "TopicId");
migrationBuilder.CreateIndex(
name: "IX_Messages_UserId",
table: "Messages",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Messages_Topics_TopicId",
table: "Messages",
column: "TopicId",
principalTable: "Topics",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Messages_Users_UserId",
table: "Messages",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Topics_Categories_CategoryId",
table: "Topics",
column: "CategoryId",
principalTable: "Categories",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Users_Roles_RoleId",
table: "Users",
column: "RoleId",
principalTable: "Roles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Messages_Topics_TopicId",
table: "Messages");
migrationBuilder.DropForeignKey(
name: "FK_Messages_Users_UserId",
table: "Messages");
migrationBuilder.DropForeignKey(
name: "FK_Topics_Categories_CategoryId",
table: "Topics");
migrationBuilder.DropForeignKey(
name: "FK_Users_Roles_RoleId",
table: "Users");
migrationBuilder.DropIndex(
name: "IX_Users_RoleId",
table: "Users");
migrationBuilder.DropIndex(
name: "IX_Topics_CategoryId",
table: "Topics");
migrationBuilder.DropIndex(
name: "IX_Messages_TopicId",
table: "Messages");
migrationBuilder.DropIndex(
name: "IX_Messages_UserId",
table: "Messages");
}
}
}

View File

@ -65,6 +65,10 @@ namespace ForumDatabase.Migrations
b.HasKey("Id");
b.HasIndex("TopicId");
b.HasIndex("UserId");
b.ToTable("Messages");
});
@ -105,6 +109,8 @@ namespace ForumDatabase.Migrations
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("Topics");
});
@ -136,8 +142,51 @@ namespace ForumDatabase.Migrations
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("ForumDatabase.Models.Message", b =>
{
b.HasOne("ForumDatabase.Models.Topic", "Topic")
.WithMany()
.HasForeignKey("TopicId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ForumDatabase.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Topic");
b.Navigation("User");
});
modelBuilder.Entity("ForumDatabase.Models.Topic", b =>
{
b.HasOne("ForumDatabase.Models.Category", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Category");
});
modelBuilder.Entity("ForumDatabase.Models.User", b =>
{
b.HasOne("ForumDatabase.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
});
#pragma warning restore 612, 618
}
}