[backend/database] Add note likes table
This commit is contained in:
parent
8ca64f5d11
commit
fde159dbec
7 changed files with 6186 additions and 2 deletions
|
@ -47,6 +47,7 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
|||
public virtual DbSet<Note> Notes { get; init; } = null!;
|
||||
public virtual DbSet<NoteEdit> NoteEdits { 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<NoteThreadMuting> NoteThreadMutings { get; init; } = null!;
|
||||
public virtual DbSet<NoteUnread> NoteUnreads { get; init; } = null!;
|
||||
|
@ -592,6 +593,11 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
|||
|
||||
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 => {
|
||||
entity.Property(e => e.CreatedAt).HasComment("The created date of the NoteReaction.");
|
||||
|
|
6018
Iceshrimp.Backend/Core/Database/Migrations/20240214175919_AddNoteLikeTable.Designer.cs
generated
Normal file
6018
Iceshrimp.Backend/Core/Database/Migrations/20240214175919_AddNoteLikeTable.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using Notification = Iceshrimp.Backend.Core.Database.Tables.Notification;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
@ -2685,6 +2686,41 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
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 =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
|
@ -2944,7 +2980,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("reaction");
|
||||
|
||||
b.Property<Core.Database.Tables.Notification.NotificationType>("Type")
|
||||
b.Property<Notification.NotificationType>("Type")
|
||||
.HasColumnType("notification_type_enum")
|
||||
.HasColumnName("type")
|
||||
.HasComment("The type of the Notification.");
|
||||
|
@ -4477,7 +4513,7 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
.HasColumnName("mutedWords")
|
||||
.HasDefaultValueSql("'[]'::jsonb");
|
||||
|
||||
b.Property<List<Core.Database.Tables.Notification.NotificationType>>("MutingNotificationTypes")
|
||||
b.Property<List<Notification.NotificationType>>("MutingNotificationTypes")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("notification_type_enum[]")
|
||||
|
@ -5215,6 +5251,25 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
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 =>
|
||||
{
|
||||
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Note", "Note")
|
||||
|
@ -5773,6 +5828,8 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
|
||||
b.Navigation("NoteFavorites");
|
||||
|
||||
b.Navigation("NoteLikes");
|
||||
|
||||
b.Navigation("NoteReactions");
|
||||
|
||||
b.Navigation("NoteUnreads");
|
||||
|
@ -5856,6 +5913,8 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
|||
|
||||
b.Navigation("NoteFavorites");
|
||||
|
||||
b.Navigation("NoteLikes");
|
||||
|
||||
b.Navigation("NoteReactions");
|
||||
|
||||
b.Navigation("NoteThreadMutings");
|
||||
|
|
|
@ -202,6 +202,9 @@ public class Note : IEntity {
|
|||
|
||||
[InverseProperty(nameof(NoteReaction.Note))]
|
||||
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))]
|
||||
public virtual ICollection<NoteUnread> NoteUnreads { get; set; } = new List<NoteUnread>();
|
||||
|
|
31
Iceshrimp.Backend/Core/Database/Tables/NoteLike.cs
Normal file
31
Iceshrimp.Backend/Core/Database/Tables/NoteLike.cs
Normal 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!;
|
||||
}
|
|
@ -381,6 +381,9 @@ public class User : IEntity {
|
|||
|
||||
[InverseProperty(nameof(NoteFavorite.User))]
|
||||
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))]
|
||||
public virtual ICollection<NoteReaction> NoteReactions { get; set; } = new List<NoteReaction>();
|
||||
|
|
Loading…
Add table
Reference in a new issue