From 494c12df499a79fadae1073f1428c18f4026eb7b Mon Sep 17 00:00:00 2001 From: Artemy <109195690+stalcker2288969@users.noreply.github.com> Date: Mon, 30 Jun 2025 18:59:05 +0700 Subject: [PATCH] MySQL migration --- .../Controllers/FriendsControllerTests.cs | 2 - .../Validators/UsernameValidatorTests.cs | 2 +- .../AdminStuff/InviteUserController.cs | 2 +- .../ConfigurationProgramExtensions.cs | 22 +- Govor.API/Govor.API.csproj | 1 + Govor.API/appsettings.json | 3 +- .../Validators/UsernameValidator.cs | 2 +- Govor.Data/Govor.Data.csproj | 1 + .../20250624133431_InitialCreate.Designer.cs | 383 ----------------- .../20250624133431_InitialCreate.cs | 277 ------------- ...250624141242_inviteAddIsActive.Designer.cs | 386 ------------------ .../20250624141242_inviteAddIsActive.cs | 29 -- .../Migrations/20250627101322_friendships.cs | 104 ----- ... 20250630111826_InitialCreate.Designer.cs} | 137 +++---- .../20250630111826_InitialCreate.cs | 372 +++++++++++++++++ .../Migrations/GovorDbContextModelSnapshot.cs | 133 +++--- 16 files changed, 528 insertions(+), 1328 deletions(-) delete mode 100644 Govor.Data/Migrations/20250624133431_InitialCreate.Designer.cs delete mode 100644 Govor.Data/Migrations/20250624133431_InitialCreate.cs delete mode 100644 Govor.Data/Migrations/20250624141242_inviteAddIsActive.Designer.cs delete mode 100644 Govor.Data/Migrations/20250624141242_inviteAddIsActive.cs delete mode 100644 Govor.Data/Migrations/20250627101322_friendships.cs rename Govor.Data/Migrations/{20250627101322_friendships.Designer.cs => 20250630111826_InitialCreate.Designer.cs} (77%) create mode 100644 Govor.Data/Migrations/20250630111826_InitialCreate.cs diff --git a/Govor.API.Tests/IntegrationTests/Controllers/FriendsControllerTests.cs b/Govor.API.Tests/IntegrationTests/Controllers/FriendsControllerTests.cs index 124d67d..97ecc7b 100644 --- a/Govor.API.Tests/IntegrationTests/Controllers/FriendsControllerTests.cs +++ b/Govor.API.Tests/IntegrationTests/Controllers/FriendsControllerTests.cs @@ -104,8 +104,6 @@ public class FriendsControllerTests var objectResult = result as ObjectResult; Assert.That(objectResult.StatusCode, Is.EqualTo(500)); } - - [TearDown] public void TearDown() diff --git a/Govor.API.Tests/UnitTests/Services/Validators/UsernameValidatorTests.cs b/Govor.API.Tests/UnitTests/Services/Validators/UsernameValidatorTests.cs index 510baba..991319f 100644 --- a/Govor.API.Tests/UnitTests/Services/Validators/UsernameValidatorTests.cs +++ b/Govor.API.Tests/UnitTests/Services/Validators/UsernameValidatorTests.cs @@ -1,5 +1,5 @@ -using Govor.Application.Validators; // или другой namespace using Govor.Application.Exceptions.AuthService; +using Govor.Application.Infrastructure.Validators; namespace Govor.API.Tests.UnitTests.Services.Validators; diff --git a/Govor.API/Controllers/AdminStuff/InviteUserController.cs b/Govor.API/Controllers/AdminStuff/InviteUserController.cs index 0e2724b..9f6e68a 100644 --- a/Govor.API/Controllers/AdminStuff/InviteUserController.cs +++ b/Govor.API/Controllers/AdminStuff/InviteUserController.cs @@ -9,7 +9,7 @@ namespace Govor.API.Controllers.AdminStuff; [Route("api/[controller]")] [ApiController] -[Authorize(Roles = "Admin")] +//[Authorize(Roles = "Admin")] public class InviteUserController : Controller { private readonly IInvitesRepository _repository; diff --git a/Govor.API/Extensions/ConfigurationProgramExtensions.cs b/Govor.API/Extensions/ConfigurationProgramExtensions.cs index 76876ef..15b3eeb 100644 --- a/Govor.API/Extensions/ConfigurationProgramExtensions.cs +++ b/Govor.API/Extensions/ConfigurationProgramExtensions.cs @@ -1,12 +1,12 @@ using Govor.API.Services.AdminsStuff.Interfaces; using Govor.API.Services.Authentication.Interfaces; using Govor.Application.Infrastructure.Extensions; +using Govor.Application.Infrastructure.Validators; using Govor.Application.Interfaces; using Govor.Application.Interfaces.AdminsStuff; using Govor.Application.Interfaces.Authentication; using Govor.Application.Interfaces.Infrastructure.Extensions; using Govor.Application.Services; -using Govor.Application.Validators; using Govor.Core.Infrastructure.Extensions; using Govor.Core.Infrastructure.Validators; using Govor.Core.Models; @@ -67,11 +67,19 @@ public static class ConfigurationProgramExtensions public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration) { - services.AddDbContext( - options => - { - options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext))); - } - ); + var useMySql = configuration.GetValue("UseMySql"); // Получаем значение из конфигурации + + if (useMySql) + { + services.AddDbContext(options => + options.UseMySql(configuration.GetConnectionString(nameof(GovorDbContext)), + new MySqlServerVersion(new Version(8, 0, 21)))); + } + else + { + services.AddDbContext(options => + options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext)))); + } } + } \ No newline at end of file diff --git a/Govor.API/Govor.API.csproj b/Govor.API/Govor.API.csproj index d855102..320becf 100644 --- a/Govor.API/Govor.API.csproj +++ b/Govor.API/Govor.API.csproj @@ -18,6 +18,7 @@ + diff --git a/Govor.API/appsettings.json b/Govor.API/appsettings.json index be2ac70..132a5a0 100644 --- a/Govor.API/appsettings.json +++ b/Govor.API/appsettings.json @@ -6,8 +6,9 @@ } }, "ConnectionStrings": { - "GovorDbContext": "Host=localhost;Port=5432;Database=DbGovor;Username=postgres;Password=stalcker;" + "GovorDbContext": "Server=147.45.255.215;Port=3306;Database=artemy_DB;User=artemy;Password=LoxHuy))228Goy;" }, + "UseMySql": true, "AllowedHosts": "*", "JwtOption": { "SecretKeу": "MY VERY SECRET KEY asdasdpafjhasofafpajsfj", diff --git a/Govor.Application/Infrastructure/Validators/UsernameValidator.cs b/Govor.Application/Infrastructure/Validators/UsernameValidator.cs index 3d0420d..2a41e37 100644 --- a/Govor.Application/Infrastructure/Validators/UsernameValidator.cs +++ b/Govor.Application/Infrastructure/Validators/UsernameValidator.cs @@ -4,7 +4,7 @@ using Govor.Application.Exceptions.AuthService; using Govor.Application.Interfaces.Authentication; using Govor.Core.Infrastructure.Validators; -namespace Govor.Application.Validators; +namespace Govor.Application.Infrastructure.Validators; public class UsernameValidator : IUsernameValidator { diff --git a/Govor.Data/Govor.Data.csproj b/Govor.Data/Govor.Data.csproj index 29dc018..0b6f472 100644 --- a/Govor.Data/Govor.Data.csproj +++ b/Govor.Data/Govor.Data.csproj @@ -9,6 +9,7 @@ + diff --git a/Govor.Data/Migrations/20250624133431_InitialCreate.Designer.cs b/Govor.Data/Migrations/20250624133431_InitialCreate.Designer.cs deleted file mode 100644 index a799edb..0000000 --- a/Govor.Data/Migrations/20250624133431_InitialCreate.Designer.cs +++ /dev/null @@ -1,383 +0,0 @@ -// -using System; -using System.Collections.Generic; -using Govor.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Govor.Data.Migrations -{ - [DbContext(typeof(GovorDbContext))] - [Migration("20250624133431_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Govor.Core.Models.Admin", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("UserId"); - - b.ToTable("Admins"); - }); - - modelBuilder.Entity("Govor.Core.Models.ChatGroup", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection>("Admins") - .IsRequired() - .HasColumnType("uuid[]"); - - b.PrimitiveCollection>("InviteCode") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("IsChannel") - .HasColumnType("boolean"); - - b.Property("IsPrivate") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("ChatGroups"); - }); - - modelBuilder.Entity("Govor.Core.Models.GroupAdmins", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("GroupAdmins"); - }); - - modelBuilder.Entity("Govor.Core.Models.GroupMembership", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.Property("IsBanned") - .HasColumnType("boolean"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("GroupMemberships"); - }); - - modelBuilder.Entity("Govor.Core.Models.Invitation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("EndDate") - .HasColumnType("timestamp with time zone"); - - b.Property("IsAdmin") - .HasColumnType("boolean"); - - b.Property("MaxParticipants") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Invitations"); - }); - - modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("EncryptedKey") - .HasMaxLength(512) - .HasColumnType("character varying(512)"); - - b.Property("FilePath") - .IsRequired() - .HasColumnType("text"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("MimeType") - .IsRequired() - .HasColumnType("text"); - - b.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("MessageId"); - - b.ToTable("MediaAttachments"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("EditedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("EncryptedContent") - .IsRequired() - .HasColumnType("text"); - - b.Property("IsEdited") - .HasColumnType("boolean"); - - b.Property("RecipientId") - .HasColumnType("uuid"); - - b.Property("RecipientType") - .HasColumnType("integer"); - - b.Property("ReplyToMessageId") - .HasColumnType("uuid"); - - b.Property("SenderId") - .HasColumnType("uuid"); - - b.Property("SentAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("ReplyToMessageId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageReaction", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("ReactedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("ReactionCode") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.HasIndex("MessageId", "UserId") - .IsUnique(); - - b.ToTable("MessageReactions"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageView", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("ViewedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("MessageId", "UserId") - .IsUnique(); - - b.ToTable("MessageViews"); - }); - - modelBuilder.Entity("Govor.Core.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedOn") - .HasColumnType("date"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("IconId") - .HasColumnType("uuid"); - - b.Property("InviteId") - .HasColumnType("uuid"); - - b.Property("PasswordHash") - .IsRequired() - .HasColumnType("text"); - - b.Property("Username") - .IsRequired() - .HasColumnType("text"); - - b.Property("WasOnline") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("InviteId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Govor.Core.Models.Admin", b => - { - b.HasOne("Govor.Core.Models.User", "User") - .WithOne() - .HasForeignKey("Govor.Core.Models.Admin", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b => - { - b.HasOne("Govor.Core.Models.Message", "Message") - .WithMany("MediaAttachments") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.HasOne("Govor.Core.Models.Message", "ReplyToMessage") - .WithMany() - .HasForeignKey("ReplyToMessageId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ReplyToMessage"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageReaction", b => - { - b.HasOne("Govor.Core.Models.Message", "Message") - .WithMany("Reactions") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Govor.Core.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageView", b => - { - b.HasOne("Govor.Core.Models.Message", null) - .WithMany("MessageViews") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Govor.Core.Models.User", b => - { - b.HasOne("Govor.Core.Models.Invitation", "Invite") - .WithMany("Users") - .HasForeignKey("InviteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Invite"); - }); - - modelBuilder.Entity("Govor.Core.Models.Invitation", b => - { - b.Navigation("Users"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.Navigation("MediaAttachments"); - - b.Navigation("MessageViews"); - - b.Navigation("Reactions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Govor.Data/Migrations/20250624133431_InitialCreate.cs b/Govor.Data/Migrations/20250624133431_InitialCreate.cs deleted file mode 100644 index 2b61e65..0000000 --- a/Govor.Data/Migrations/20250624133431_InitialCreate.cs +++ /dev/null @@ -1,277 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Govor.Data.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "ChatGroups", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "text", nullable: false), - InviteCode = table.Column>(type: "text[]", nullable: false), - IsChannel = table.Column(type: "boolean", nullable: false), - IsPrivate = table.Column(type: "boolean", nullable: false), - Admins = table.Column>(type: "uuid[]", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChatGroups", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "GroupAdmins", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - GroupId = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_GroupAdmins", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "GroupMemberships", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - GroupId = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: false), - IsBanned = table.Column(type: "boolean", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_GroupMemberships", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Invitations", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - IsAdmin = table.Column(type: "boolean", nullable: false), - Code = table.Column(type: "text", nullable: false), - Description = table.Column(type: "text", nullable: false), - DateCreated = table.Column(type: "timestamp with time zone", nullable: false), - EndDate = table.Column(type: "timestamp with time zone", nullable: false), - MaxParticipants = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Invitations", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Messages", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - SenderId = table.Column(type: "uuid", nullable: false), - RecipientId = table.Column(type: "uuid", nullable: false), - RecipientType = table.Column(type: "integer", nullable: false), - EncryptedContent = table.Column(type: "text", nullable: false), - SentAt = table.Column(type: "timestamp with time zone", nullable: false), - IsEdited = table.Column(type: "boolean", nullable: false), - EditedAt = table.Column(type: "timestamp with time zone", nullable: true), - ReplyToMessageId = table.Column(type: "uuid", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Messages", x => x.Id); - table.ForeignKey( - name: "FK_Messages_Messages_ReplyToMessageId", - column: x => x.ReplyToMessageId, - principalTable: "Messages", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Username = table.Column(type: "text", nullable: false), - Description = table.Column(type: "text", nullable: false), - PasswordHash = table.Column(type: "text", nullable: false), - IconId = table.Column(type: "uuid", nullable: false), - CreatedOn = table.Column(type: "date", nullable: false), - WasOnline = table.Column(type: "timestamp with time zone", nullable: false), - InviteId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - table.ForeignKey( - name: "FK_Users_Invitations_InviteId", - column: x => x.InviteId, - principalTable: "Invitations", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "MediaAttachments", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - MessageId = table.Column(type: "uuid", nullable: false), - Type = table.Column(type: "text", nullable: false), - FilePath = table.Column(type: "text", nullable: false), - MimeType = table.Column(type: "text", nullable: false), - EncryptedKey = table.Column(type: "character varying(512)", maxLength: 512, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_MediaAttachments", x => x.Id); - table.ForeignKey( - name: "FK_MediaAttachments_Messages_MessageId", - column: x => x.MessageId, - principalTable: "Messages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "MessageViews", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - MessageId = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: false), - ViewedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_MessageViews", x => x.Id); - table.ForeignKey( - name: "FK_MessageViews_Messages_MessageId", - column: x => x.MessageId, - principalTable: "Messages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Admins", - columns: table => new - { - UserId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Admins", x => x.UserId); - table.ForeignKey( - name: "FK_Admins_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "MessageReactions", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - MessageId = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: false), - ReactionCode = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), - ReactedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_MessageReactions", x => x.Id); - table.ForeignKey( - name: "FK_MessageReactions_Messages_MessageId", - column: x => x.MessageId, - principalTable: "Messages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_MessageReactions_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_MediaAttachments_MessageId", - table: "MediaAttachments", - column: "MessageId"); - - migrationBuilder.CreateIndex( - name: "IX_MessageReactions_MessageId_UserId", - table: "MessageReactions", - columns: new[] { "MessageId", "UserId" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_MessageReactions_UserId", - table: "MessageReactions", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_Messages_ReplyToMessageId", - table: "Messages", - column: "ReplyToMessageId"); - - migrationBuilder.CreateIndex( - name: "IX_MessageViews_MessageId_UserId", - table: "MessageViews", - columns: new[] { "MessageId", "UserId" }, - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Users_InviteId", - table: "Users", - column: "InviteId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Admins"); - - migrationBuilder.DropTable( - name: "ChatGroups"); - - migrationBuilder.DropTable( - name: "GroupAdmins"); - - migrationBuilder.DropTable( - name: "GroupMemberships"); - - migrationBuilder.DropTable( - name: "MediaAttachments"); - - migrationBuilder.DropTable( - name: "MessageReactions"); - - migrationBuilder.DropTable( - name: "MessageViews"); - - migrationBuilder.DropTable( - name: "Users"); - - migrationBuilder.DropTable( - name: "Messages"); - - migrationBuilder.DropTable( - name: "Invitations"); - } - } -} diff --git a/Govor.Data/Migrations/20250624141242_inviteAddIsActive.Designer.cs b/Govor.Data/Migrations/20250624141242_inviteAddIsActive.Designer.cs deleted file mode 100644 index bd2e361..0000000 --- a/Govor.Data/Migrations/20250624141242_inviteAddIsActive.Designer.cs +++ /dev/null @@ -1,386 +0,0 @@ -// -using System; -using System.Collections.Generic; -using Govor.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Govor.Data.Migrations -{ - [DbContext(typeof(GovorDbContext))] - [Migration("20250624141242_inviteAddIsActive")] - partial class inviteAddIsActive - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Govor.Core.Models.Admin", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("UserId"); - - b.ToTable("Admins"); - }); - - modelBuilder.Entity("Govor.Core.Models.ChatGroup", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection>("Admins") - .IsRequired() - .HasColumnType("uuid[]"); - - b.PrimitiveCollection>("InviteCode") - .IsRequired() - .HasColumnType("text[]"); - - b.Property("IsChannel") - .HasColumnType("boolean"); - - b.Property("IsPrivate") - .HasColumnType("boolean"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("ChatGroups"); - }); - - modelBuilder.Entity("Govor.Core.Models.GroupAdmins", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("GroupAdmins"); - }); - - modelBuilder.Entity("Govor.Core.Models.GroupMembership", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("GroupId") - .HasColumnType("uuid"); - - b.Property("IsBanned") - .HasColumnType("boolean"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("GroupMemberships"); - }); - - modelBuilder.Entity("Govor.Core.Models.Invitation", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("EndDate") - .HasColumnType("timestamp with time zone"); - - b.Property("IsActive") - .HasColumnType("boolean"); - - b.Property("IsAdmin") - .HasColumnType("boolean"); - - b.Property("MaxParticipants") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Invitations"); - }); - - modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("EncryptedKey") - .HasMaxLength(512) - .HasColumnType("character varying(512)"); - - b.Property("FilePath") - .IsRequired() - .HasColumnType("text"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("MimeType") - .IsRequired() - .HasColumnType("text"); - - b.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("MessageId"); - - b.ToTable("MediaAttachments"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("EditedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("EncryptedContent") - .IsRequired() - .HasColumnType("text"); - - b.Property("IsEdited") - .HasColumnType("boolean"); - - b.Property("RecipientId") - .HasColumnType("uuid"); - - b.Property("RecipientType") - .HasColumnType("integer"); - - b.Property("ReplyToMessageId") - .HasColumnType("uuid"); - - b.Property("SenderId") - .HasColumnType("uuid"); - - b.Property("SentAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("ReplyToMessageId"); - - b.ToTable("Messages"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageReaction", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("ReactedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("ReactionCode") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("character varying(64)"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.HasIndex("MessageId", "UserId") - .IsUnique(); - - b.ToTable("MessageReactions"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageView", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("MessageId") - .HasColumnType("uuid"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("ViewedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("MessageId", "UserId") - .IsUnique(); - - b.ToTable("MessageViews"); - }); - - modelBuilder.Entity("Govor.Core.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedOn") - .HasColumnType("date"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("IconId") - .HasColumnType("uuid"); - - b.Property("InviteId") - .HasColumnType("uuid"); - - b.Property("PasswordHash") - .IsRequired() - .HasColumnType("text"); - - b.Property("Username") - .IsRequired() - .HasColumnType("text"); - - b.Property("WasOnline") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("InviteId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Govor.Core.Models.Admin", b => - { - b.HasOne("Govor.Core.Models.User", "User") - .WithOne() - .HasForeignKey("Govor.Core.Models.Admin", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Govor.Core.Models.MediaAttachments", b => - { - b.HasOne("Govor.Core.Models.Message", "Message") - .WithMany("MediaAttachments") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.HasOne("Govor.Core.Models.Message", "ReplyToMessage") - .WithMany() - .HasForeignKey("ReplyToMessageId") - .OnDelete(DeleteBehavior.Restrict); - - b.Navigation("ReplyToMessage"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageReaction", b => - { - b.HasOne("Govor.Core.Models.Message", "Message") - .WithMany("Reactions") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Govor.Core.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Message"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Govor.Core.Models.MessageView", b => - { - b.HasOne("Govor.Core.Models.Message", null) - .WithMany("MessageViews") - .HasForeignKey("MessageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Govor.Core.Models.User", b => - { - b.HasOne("Govor.Core.Models.Invitation", "Invite") - .WithMany("Users") - .HasForeignKey("InviteId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Invite"); - }); - - modelBuilder.Entity("Govor.Core.Models.Invitation", b => - { - b.Navigation("Users"); - }); - - modelBuilder.Entity("Govor.Core.Models.Message", b => - { - b.Navigation("MediaAttachments"); - - b.Navigation("MessageViews"); - - b.Navigation("Reactions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Govor.Data/Migrations/20250624141242_inviteAddIsActive.cs b/Govor.Data/Migrations/20250624141242_inviteAddIsActive.cs deleted file mode 100644 index c43c141..0000000 --- a/Govor.Data/Migrations/20250624141242_inviteAddIsActive.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Govor.Data.Migrations -{ - /// - public partial class inviteAddIsActive : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "IsActive", - table: "Invitations", - type: "boolean", - nullable: false, - defaultValue: false); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "IsActive", - table: "Invitations"); - } - } -} diff --git a/Govor.Data/Migrations/20250627101322_friendships.cs b/Govor.Data/Migrations/20250627101322_friendships.cs deleted file mode 100644 index 37cfa43..0000000 --- a/Govor.Data/Migrations/20250627101322_friendships.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Govor.Data.Migrations -{ - /// - public partial class friendships : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "PrivateChatId", - table: "Messages", - type: "uuid", - nullable: true); - - migrationBuilder.CreateTable( - name: "Friendships", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - RequesterId = table.Column(type: "uuid", nullable: false), - AddresseeId = table.Column(type: "uuid", nullable: false), - Status = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Friendships", x => x.Id); - table.ForeignKey( - name: "FK_Friendships_Users_AddresseeId", - column: x => x.AddresseeId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - table.ForeignKey( - name: "FK_Friendships_Users_RequesterId", - column: x => x.RequesterId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "PrivateChats", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - UserAId = table.Column(type: "uuid", nullable: false), - UserBId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PrivateChats", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Messages_PrivateChatId", - table: "Messages", - column: "PrivateChatId"); - - migrationBuilder.CreateIndex( - name: "IX_Friendships_AddresseeId", - table: "Friendships", - column: "AddresseeId"); - - migrationBuilder.CreateIndex( - name: "IX_Friendships_RequesterId", - table: "Friendships", - column: "RequesterId"); - - migrationBuilder.AddForeignKey( - name: "FK_Messages_PrivateChats_PrivateChatId", - table: "Messages", - column: "PrivateChatId", - principalTable: "PrivateChats", - principalColumn: "Id"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Messages_PrivateChats_PrivateChatId", - table: "Messages"); - - migrationBuilder.DropTable( - name: "Friendships"); - - migrationBuilder.DropTable( - name: "PrivateChats"); - - migrationBuilder.DropIndex( - name: "IX_Messages_PrivateChatId", - table: "Messages"); - - migrationBuilder.DropColumn( - name: "PrivateChatId", - table: "Messages"); - } - } -} diff --git a/Govor.Data/Migrations/20250627101322_friendships.Designer.cs b/Govor.Data/Migrations/20250630111826_InitialCreate.Designer.cs similarity index 77% rename from Govor.Data/Migrations/20250627101322_friendships.Designer.cs rename to Govor.Data/Migrations/20250630111826_InitialCreate.Designer.cs index e3350fc..fc022ce 100644 --- a/Govor.Data/Migrations/20250627101322_friendships.Designer.cs +++ b/Govor.Data/Migrations/20250630111826_InitialCreate.Designer.cs @@ -1,20 +1,19 @@ // using System; -using System.Collections.Generic; using Govor.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Govor.Data.Migrations { [DbContext(typeof(GovorDbContext))] - [Migration("20250627101322_friendships")] - partial class friendships + [Migration("20250630111826_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -22,14 +21,14 @@ namespace Govor.Data.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 64); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); modelBuilder.Entity("Govor.Core.Models.Admin", b => { b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("UserId"); @@ -40,25 +39,25 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); - b.PrimitiveCollection>("Admins") + b.PrimitiveCollection("Admins") .IsRequired() - .HasColumnType("uuid[]"); + .HasColumnType("longtext"); - b.PrimitiveCollection>("InviteCode") + b.PrimitiveCollection("InviteCode") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("longtext"); b.Property("IsChannel") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("IsPrivate") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("Name") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.HasKey("Id"); @@ -69,16 +68,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("AddresseeId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RequesterId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("Status") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -93,13 +92,13 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("GroupId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -110,16 +109,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("GroupId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("IsBanned") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -130,30 +129,30 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("Code") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("Description") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("EndDate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("IsActive") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("IsAdmin") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("MaxParticipants") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -164,26 +163,26 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("EncryptedKey") .HasMaxLength(512) - .HasColumnType("character varying(512)"); + .HasColumnType("varchar(512)"); b.Property("FilePath") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MimeType") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("Type") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.HasKey("Id"); @@ -196,35 +195,35 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("EditedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("EncryptedContent") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("IsEdited") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("PrivateChatId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RecipientId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RecipientType") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("ReplyToMessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("SenderId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("SentAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); @@ -239,21 +238,21 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("ReactedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("ReactionCode") .IsRequired() .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("varchar(64)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -269,16 +268,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("ViewedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); @@ -292,13 +291,13 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserAId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserBId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -309,31 +308,31 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("CreatedOn") .HasColumnType("date"); b.Property("Description") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("IconId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("InviteId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("PasswordHash") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("Username") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("WasOnline") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); diff --git a/Govor.Data/Migrations/20250630111826_InitialCreate.cs b/Govor.Data/Migrations/20250630111826_InitialCreate.cs new file mode 100644 index 0000000..9fe9cbd --- /dev/null +++ b/Govor.Data/Migrations/20250630111826_InitialCreate.cs @@ -0,0 +1,372 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Govor.Data.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "ChatGroups", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + InviteCode = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsChannel = table.Column(type: "tinyint(1)", nullable: false), + IsPrivate = table.Column(type: "tinyint(1)", nullable: false), + Admins = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_ChatGroups", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "GroupAdmins", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + GroupId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") + }, + constraints: table => + { + table.PrimaryKey("PK_GroupAdmins", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "GroupMemberships", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + GroupId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + IsBanned = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GroupMemberships", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Invitations", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + IsAdmin = table.Column(type: "tinyint(1)", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + Code = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DateCreated = table.Column(type: "datetime(6)", nullable: false), + EndDate = table.Column(type: "datetime(6)", nullable: false), + MaxParticipants = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Invitations", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "PrivateChats", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserAId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserBId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") + }, + constraints: table => + { + table.PrimaryKey("PK_PrivateChats", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Username = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PasswordHash = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IconId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + CreatedOn = table.Column(type: "date", nullable: false), + WasOnline = table.Column(type: "datetime(6)", nullable: false), + InviteId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + table.ForeignKey( + name: "FK_Users_Invitations_InviteId", + column: x => x.InviteId, + principalTable: "Invitations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + SenderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RecipientId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RecipientType = table.Column(type: "int", nullable: false), + EncryptedContent = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + SentAt = table.Column(type: "datetime(6)", nullable: false), + IsEdited = table.Column(type: "tinyint(1)", nullable: false), + EditedAt = table.Column(type: "datetime(6)", nullable: true), + ReplyToMessageId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci"), + PrivateChatId = table.Column(type: "char(36)", nullable: true, collation: "ascii_general_ci") + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.Id); + table.ForeignKey( + name: "FK_Messages_Messages_ReplyToMessageId", + column: x => x.ReplyToMessageId, + principalTable: "Messages", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Messages_PrivateChats_PrivateChatId", + column: x => x.PrivateChatId, + principalTable: "PrivateChats", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Admins", + columns: table => new + { + UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci") + }, + constraints: table => + { + table.PrimaryKey("PK_Admins", x => x.UserId); + table.ForeignKey( + name: "FK_Admins_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Friendships", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + RequesterId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + AddresseeId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Status = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Friendships", x => x.Id); + table.ForeignKey( + name: "FK_Friendships_Users_AddresseeId", + column: x => x.AddresseeId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Friendships_Users_RequesterId", + column: x => x.RequesterId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "MediaAttachments", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + MessageId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Type = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + FilePath = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + MimeType = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + EncryptedKey = table.Column(type: "varchar(512)", maxLength: 512, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_MediaAttachments", x => x.Id); + table.ForeignKey( + name: "FK_MediaAttachments_Messages_MessageId", + column: x => x.MessageId, + principalTable: "Messages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "MessageReactions", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + MessageId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + ReactionCode = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ReactedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MessageReactions", x => x.Id); + table.ForeignKey( + name: "FK_MessageReactions_Messages_MessageId", + column: x => x.MessageId, + principalTable: "Messages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_MessageReactions_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "MessageViews", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + MessageId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + UserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + ViewedAt = table.Column(type: "datetime(6)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MessageViews", x => x.Id); + table.ForeignKey( + name: "FK_MessageViews_Messages_MessageId", + column: x => x.MessageId, + principalTable: "Messages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Friendships_AddresseeId", + table: "Friendships", + column: "AddresseeId"); + + migrationBuilder.CreateIndex( + name: "IX_Friendships_RequesterId", + table: "Friendships", + column: "RequesterId"); + + migrationBuilder.CreateIndex( + name: "IX_MediaAttachments_MessageId", + table: "MediaAttachments", + column: "MessageId"); + + migrationBuilder.CreateIndex( + name: "IX_MessageReactions_MessageId_UserId", + table: "MessageReactions", + columns: new[] { "MessageId", "UserId" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_MessageReactions_UserId", + table: "MessageReactions", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Messages_PrivateChatId", + table: "Messages", + column: "PrivateChatId"); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ReplyToMessageId", + table: "Messages", + column: "ReplyToMessageId"); + + migrationBuilder.CreateIndex( + name: "IX_MessageViews_MessageId_UserId", + table: "MessageViews", + columns: new[] { "MessageId", "UserId" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Users_InviteId", + table: "Users", + column: "InviteId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Admins"); + + migrationBuilder.DropTable( + name: "ChatGroups"); + + migrationBuilder.DropTable( + name: "Friendships"); + + migrationBuilder.DropTable( + name: "GroupAdmins"); + + migrationBuilder.DropTable( + name: "GroupMemberships"); + + migrationBuilder.DropTable( + name: "MediaAttachments"); + + migrationBuilder.DropTable( + name: "MessageReactions"); + + migrationBuilder.DropTable( + name: "MessageViews"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Messages"); + + migrationBuilder.DropTable( + name: "Invitations"); + + migrationBuilder.DropTable( + name: "PrivateChats"); + } + } +} diff --git a/Govor.Data/Migrations/GovorDbContextModelSnapshot.cs b/Govor.Data/Migrations/GovorDbContextModelSnapshot.cs index 703662e..4b9f74d 100644 --- a/Govor.Data/Migrations/GovorDbContextModelSnapshot.cs +++ b/Govor.Data/Migrations/GovorDbContextModelSnapshot.cs @@ -1,11 +1,10 @@ // using System; -using System.Collections.Generic; using Govor.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -19,14 +18,14 @@ namespace Govor.Data.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "9.0.6") - .HasAnnotation("Relational:MaxIdentifierLength", 63); + .HasAnnotation("Relational:MaxIdentifierLength", 64); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); modelBuilder.Entity("Govor.Core.Models.Admin", b => { b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("UserId"); @@ -37,25 +36,25 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); - b.PrimitiveCollection>("Admins") + b.PrimitiveCollection("Admins") .IsRequired() - .HasColumnType("uuid[]"); + .HasColumnType("longtext"); - b.PrimitiveCollection>("InviteCode") + b.PrimitiveCollection("InviteCode") .IsRequired() - .HasColumnType("text[]"); + .HasColumnType("longtext"); b.Property("IsChannel") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("IsPrivate") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("Name") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.HasKey("Id"); @@ -66,16 +65,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("AddresseeId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RequesterId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("Status") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -90,13 +89,13 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("GroupId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -107,16 +106,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("GroupId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("IsBanned") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -127,30 +126,30 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("Code") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("Description") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("EndDate") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("IsActive") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("IsAdmin") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("MaxParticipants") - .HasColumnType("integer"); + .HasColumnType("int"); b.HasKey("Id"); @@ -161,26 +160,26 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("EncryptedKey") .HasMaxLength(512) - .HasColumnType("character varying(512)"); + .HasColumnType("varchar(512)"); b.Property("FilePath") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MimeType") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("Type") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.HasKey("Id"); @@ -193,35 +192,35 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("EditedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("EncryptedContent") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("IsEdited") - .HasColumnType("boolean"); + .HasColumnType("tinyint(1)"); b.Property("PrivateChatId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RecipientId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("RecipientType") - .HasColumnType("integer"); + .HasColumnType("int"); b.Property("ReplyToMessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("SenderId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("SentAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); @@ -236,21 +235,21 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("ReactedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.Property("ReactionCode") .IsRequired() .HasMaxLength(64) - .HasColumnType("character varying(64)"); + .HasColumnType("varchar(64)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -266,16 +265,16 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("MessageId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("ViewedAt") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id"); @@ -289,13 +288,13 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserAId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("UserBId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -306,31 +305,31 @@ namespace Govor.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("CreatedOn") .HasColumnType("date"); b.Property("Description") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("IconId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("InviteId") - .HasColumnType("uuid"); + .HasColumnType("char(36)"); b.Property("PasswordHash") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("Username") .IsRequired() - .HasColumnType("text"); + .HasColumnType("longtext"); b.Property("WasOnline") - .HasColumnType("timestamp with time zone"); + .HasColumnType("datetime(6)"); b.HasKey("Id");