[backend/database] Add note likes table

This commit is contained in:
Laura Hausmann 2024-02-14 19:09:26 +01:00
parent 8ca64f5d11
commit fde159dbec
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
7 changed files with 6186 additions and 2 deletions

View file

@ -47,6 +47,7 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
public virtual DbSet<Note> Notes { get; init; } = null!; public virtual DbSet<Note> Notes { get; init; } = null!;
public virtual DbSet<NoteEdit> NoteEdits { get; init; } = null!; public virtual DbSet<NoteEdit> NoteEdits { get; init; } = null!;
public virtual DbSet<NoteFavorite> NoteFavorites { get; init; } = null!; public virtual DbSet<NoteFavorite> NoteFavorites { get; init; } = null!;
public virtual DbSet<NoteLike> NoteLikes { get; init; } = null!;
public virtual DbSet<NoteReaction> NoteReactions { get; init; } = null!; public virtual DbSet<NoteReaction> NoteReactions { get; init; } = null!;
public virtual DbSet<NoteThreadMuting> NoteThreadMutings { get; init; } = null!; public virtual DbSet<NoteThreadMuting> NoteThreadMutings { get; init; } = null!;
public virtual DbSet<NoteUnread> NoteUnreads { get; init; } = null!; public virtual DbSet<NoteUnread> NoteUnreads { get; init; } = null!;
@ -593,6 +594,11 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.HasOne(d => d.User).WithMany(p => p.NoteFavorites); entity.HasOne(d => d.User).WithMany(p => p.NoteFavorites);
}); });
modelBuilder.Entity<NoteLike>(entity => {
entity.HasOne(d => d.Note).WithMany(p => p.NoteLikes);
entity.HasOne(d => d.User).WithMany(p => p.NoteLikes);
});
modelBuilder.Entity<NoteReaction>(entity => { modelBuilder.Entity<NoteReaction>(entity => {
entity.Property(e => e.CreatedAt).HasComment("The created date of the NoteReaction."); entity.Property(e => e.CreatedAt).HasComment("The created date of the NoteReaction.");

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,64 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
public partial class AddNoteLikeTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "note_like",
columns: table => new
{
id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
createdAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
noteId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_note_like", x => x.id);
table.ForeignKey(
name: "FK_note_like_note_noteId",
column: x => x.noteId,
principalTable: "note",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_note_like_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_note_like_noteId",
table: "note_like",
column: "noteId");
migrationBuilder.CreateIndex(
name: "IX_note_like_userId",
table: "note_like",
column: "userId");
migrationBuilder.CreateIndex(
name: "IX_note_like_userId_noteId",
table: "note_like",
columns: new[] { "userId", "noteId" },
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "note_like");
}
}
}

View file

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Notification = Iceshrimp.Backend.Core.Database.Tables.Notification;
#nullable disable #nullable disable
@ -2685,6 +2686,41 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("note_favorite"); b.ToTable("note_favorite");
}); });
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteLike", b =>
{
b.Property<string>("Id")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("createdAt");
b.Property<string>("NoteId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("noteId");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId");
b.HasKey("Id");
b.HasIndex("NoteId");
b.HasIndex("UserId");
b.HasIndex("UserId", "NoteId")
.IsUnique();
b.ToTable("note_like");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteReaction", b => modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteReaction", b =>
{ {
b.Property<string>("Id") b.Property<string>("Id")
@ -2944,7 +2980,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnType("character varying(128)") .HasColumnType("character varying(128)")
.HasColumnName("reaction"); .HasColumnName("reaction");
b.Property<Core.Database.Tables.Notification.NotificationType>("Type") b.Property<Notification.NotificationType>("Type")
.HasColumnType("notification_type_enum") .HasColumnType("notification_type_enum")
.HasColumnName("type") .HasColumnName("type")
.HasComment("The type of the Notification."); .HasComment("The type of the Notification.");
@ -4477,7 +4513,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnName("mutedWords") .HasColumnName("mutedWords")
.HasDefaultValueSql("'[]'::jsonb"); .HasDefaultValueSql("'[]'::jsonb");
b.Property<List<Core.Database.Tables.Notification.NotificationType>>("MutingNotificationTypes") b.Property<List<Notification.NotificationType>>("MutingNotificationTypes")
.IsRequired() .IsRequired()
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("notification_type_enum[]") .HasColumnType("notification_type_enum[]")
@ -5215,6 +5251,25 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteLike", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Note", "Note")
.WithMany("NoteLikes")
.HasForeignKey("NoteId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithMany("NoteLikes")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Note");
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteReaction", b => modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.NoteReaction", b =>
{ {
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Note", "Note") b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Note", "Note")
@ -5773,6 +5828,8 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("NoteFavorites"); b.Navigation("NoteFavorites");
b.Navigation("NoteLikes");
b.Navigation("NoteReactions"); b.Navigation("NoteReactions");
b.Navigation("NoteUnreads"); b.Navigation("NoteUnreads");
@ -5856,6 +5913,8 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("NoteFavorites"); b.Navigation("NoteFavorites");
b.Navigation("NoteLikes");
b.Navigation("NoteReactions"); b.Navigation("NoteReactions");
b.Navigation("NoteThreadMutings"); b.Navigation("NoteThreadMutings");

View file

@ -203,6 +203,9 @@ public class Note : IEntity {
[InverseProperty(nameof(NoteReaction.Note))] [InverseProperty(nameof(NoteReaction.Note))]
public virtual ICollection<NoteReaction> NoteReactions { get; set; } = new List<NoteReaction>(); public virtual ICollection<NoteReaction> NoteReactions { get; set; } = new List<NoteReaction>();
[InverseProperty(nameof(NoteLike.Note))]
public virtual ICollection<NoteLike> NoteLikes { get; set; } = new List<NoteLike>();
[InverseProperty(nameof(NoteUnread.Note))] [InverseProperty(nameof(NoteUnread.Note))]
public virtual ICollection<NoteUnread> NoteUnreads { get; set; } = new List<NoteUnread>(); public virtual ICollection<NoteUnread> NoteUnreads { get; set; } = new List<NoteUnread>();

View file

@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("note_like")]
[Index("UserId")]
[Index("NoteId")]
[Index("UserId", "NoteId", IsUnique = true)]
public class NoteLike {
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("userId")] [StringLength(32)] public string UserId { get; set; } = null!;
[Column("noteId")] [StringLength(32)] public string NoteId { get; set; } = null!;
[ForeignKey("NoteId")]
[InverseProperty(nameof(Tables.Note.NoteLikes))]
public virtual Note Note { get; set; } = null!;
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.NoteLikes))]
public virtual User User { get; set; } = null!;
}

View file

@ -382,6 +382,9 @@ public class User : IEntity {
[InverseProperty(nameof(NoteFavorite.User))] [InverseProperty(nameof(NoteFavorite.User))]
public virtual ICollection<NoteFavorite> NoteFavorites { get; set; } = new List<NoteFavorite>(); public virtual ICollection<NoteFavorite> NoteFavorites { get; set; } = new List<NoteFavorite>();
[InverseProperty(nameof(NoteReaction.User))]
public virtual ICollection<NoteLike> NoteLikes { get; set; } = new List<NoteLike>();
[InverseProperty(nameof(NoteReaction.User))] [InverseProperty(nameof(NoteReaction.User))]
public virtual ICollection<NoteReaction> NoteReactions { get; set; } = new List<NoteReaction>(); public virtual ICollection<NoteReaction> NoteReactions { get; set; } = new List<NoteReaction>();