From dc32bf91f09dcf4ade42cea850249a65f479e585 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 7 Jan 2024 16:54:36 +0100 Subject: [PATCH] Temporarily add denormalized enums for initial migration --- .../Core/Database/DatabaseContext.cs | 14 +++++--------- Iceshrimp.Backend/Core/Database/Tables/Poll.cs | 12 +++++++++++- .../Core/Database/Tables/UserProfile.cs | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Iceshrimp.Backend/Core/Database/DatabaseContext.cs b/Iceshrimp.Backend/Core/Database/DatabaseContext.cs index 3639017a..422df327 100644 --- a/Iceshrimp.Backend/Core/Database/DatabaseContext.cs +++ b/Iceshrimp.Backend/Core/Database/DatabaseContext.cs @@ -132,10 +132,10 @@ public class DatabaseContext : DbContext { dataSourceBuilder.MapEnum(); dataSourceBuilder.MapEnum(); dataSourceBuilder.MapEnum(); - //dataSourceBuilder.MapEnum(); // FIXME: WHY IS THIS ITS OWN ENUM + dataSourceBuilder.MapEnum(); // FIXME: WHY IS THIS ITS OWN ENUM dataSourceBuilder.MapEnum(); dataSourceBuilder.MapEnum(); - //dataSourceBuilder.MapEnum(); // FIXME: WHY IS THIS ITS OWN ENUM + dataSourceBuilder.MapEnum(); // FIXME: WHY IS THIS ITS OWN ENUM optionsBuilder.UseNpgsql(dataSourceBuilder.Build()); } @@ -143,18 +143,14 @@ public class DatabaseContext : DbContext { protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder .HasPostgresEnum() - //.HasPostgresEnum("log_level_enum", ["error", "warning", "info", "success", "debug"]) // TODO: not in use, add migration that removes this if it exists + .HasPostgresEnum("log_level_enum", ["error", "warning", "info", "success", "debug"]) // TODO: not in use, add migration that removes this if it exists .HasPostgresEnum() .HasPostgresEnum() .HasPostgresEnum() - .HasPostgresEnum("poll_notevisibility_enum", ["public", "home", "followers", "specified", "hidden"]) + .HasPostgresEnum() //TODO: merge with regular notevisibility enum .HasPostgresEnum() .HasPostgresEnum() - .HasPostgresEnum("user_profile_mutingnotificationtypes_enum", - [ - "follow", "mention", "reply", "renote", "quote", "reaction", "pollVote", "pollEnded", - "receiveFollowRequest", "followRequestAccepted", "groupInvited", "app" - ]) + .HasPostgresEnum() //TODO: merge with regular notification types enum .HasPostgresExtension("pg_trgm"); modelBuilder.Entity(entity => { diff --git a/Iceshrimp.Backend/Core/Database/Tables/Poll.cs b/Iceshrimp.Backend/Core/Database/Tables/Poll.cs index aa7b81e5..128bce94 100644 --- a/Iceshrimp.Backend/Core/Database/Tables/Poll.cs +++ b/Iceshrimp.Backend/Core/Database/Tables/Poll.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; +using NpgsqlTypes; namespace Iceshrimp.Backend.Core.Database.Tables; @@ -44,5 +45,14 @@ public class Poll { /// [Denormalized] /// [Column("noteVisibility")] - public Note.NoteVisibility NoteVisibility { get; set; } + public PollNoteVisibility NoteVisibility { get; set; } + + [PgName("poll_notevisibility_enum")] + public enum PollNoteVisibility { + [PgName("public")] Public, + [PgName("home")] Home, + [PgName("followers")] Followers, + [PgName("specified")] Specified, + [PgName("hidden")] Hidden + } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Core/Database/Tables/UserProfile.cs b/Iceshrimp.Backend/Core/Database/Tables/UserProfile.cs index d2ae7db2..5190ced1 100644 --- a/Iceshrimp.Backend/Core/Database/Tables/UserProfile.cs +++ b/Iceshrimp.Backend/Core/Database/Tables/UserProfile.cs @@ -168,4 +168,20 @@ public class UserProfile { [PgName("followers")] Followers, [PgName("private")] Private, } + + [PgName("user_profile_mutingnotificationtypes_enum")] + public enum MutingNotificationType { + [PgName("follow")] Follow, + [PgName("mention")] Mention, + [PgName("reply")] Reply, + [PgName("renote")] Renote, + [PgName("quote")] Quote, + [PgName("reaction")] Reaction, + [PgName("pollVote")] PollVote, + [PgName("pollEnded")] PollEnded, + [PgName("receiveFollowRequest")] FollowRequestReceived, + [PgName("followRequestAccepted")] FollowRequestAccepted, + [PgName("groupInvited")] GroupInvited, + [PgName("app")] App, + } } \ No newline at end of file