[backend/database] Cleanup tables, set delete constraints correctly on all tables (ISH-78)

This commit is contained in:
Laura Hausmann 2024-03-04 22:57:37 +01:00
parent f8e80380c1
commit e59526592c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
11 changed files with 6216 additions and 661 deletions

View file

@ -17,13 +17,10 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
: DbContext(options), IDataProtectionKeyContext
{
public virtual DbSet<AbuseUserReport> AbuseUserReports { get; init; } = null!;
public virtual DbSet<AccessToken> AccessTokens { get; init; } = null!;
public virtual DbSet<Announcement> Announcements { get; init; } = null!;
public virtual DbSet<AnnouncementRead> AnnouncementReads { get; init; } = null!;
public virtual DbSet<Antenna> Antennas { get; init; } = null!;
public virtual DbSet<App> Apps { get; init; } = null!;
public virtual DbSet<AttestationChallenge> AttestationChallenges { get; init; } = null!;
public virtual DbSet<AuthSession> AuthSessions { get; init; } = null!;
public virtual DbSet<Bite> Bites { get; init; } = null!;
public virtual DbSet<Blocking> Blockings { get; init; } = null!;
public virtual DbSet<Channel> Channels { get; init; } = null!;
@ -68,7 +65,6 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
public virtual DbSet<Relay> Relays { get; init; } = null!;
public virtual DbSet<RenoteMuting> RenoteMutings { get; init; } = null!;
public virtual DbSet<Session> Sessions { get; init; } = null!;
public virtual DbSet<Signin> Signins { get; init; } = null!;
public virtual DbSet<SwSubscription> SwSubscriptions { get; init; } = null!;
public virtual DbSet<UsedUsername> UsedUsernames { get; init; } = null!;
public virtual DbSet<User> Users { get; init; } = null!;
@ -163,22 +159,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.AbuseUserReportAssignees)
.OnDelete(DeleteBehavior.SetNull);
entity.HasOne(d => d.Reporter).WithMany(p => p.AbuseUserReportReporters);
entity.HasOne(d => d.TargetUser).WithMany(p => p.AbuseUserReportTargetUsers);
});
modelBuilder.Entity<AccessToken>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the AccessToken.");
entity.Property(e => e.Fetched).HasDefaultValue(false);
entity.Property(e => e.Permission).HasDefaultValueSql("'{}'::character varying[]");
entity.HasOne(d => d.App)
.WithMany(p => p.AccessTokens)
entity.HasOne(d => d.Reporter)
.WithMany(p => p.AbuseUserReportReporters)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.AccessTokens);
entity.HasOne(d => d.TargetUser)
.WithMany(p => p.AbuseUserReportTargetUsers)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Announcement>(entity =>
@ -193,9 +180,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the AnnouncementRead.");
entity.HasOne(d => d.Announcement).WithMany(p => p.AnnouncementReads);
entity.HasOne(d => d.Announcement)
.WithMany(p => p.AnnouncementReads)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.AnnouncementReads);
entity.HasOne(d => d.User)
.WithMany(p => p.AnnouncementReads)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Antenna>(entity =>
@ -214,28 +205,15 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.Antennas)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.Antennas);
entity.HasOne(d => d.User)
.WithMany(p => p.Antennas)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.UserList)
.WithMany(p => p.Antennas)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<App>(entity =>
{
entity.Property(e => e.CallbackUrl).HasComment("The callbackUrl of the App.");
entity.Property(e => e.CreatedAt).HasComment("The created date of the App.");
entity.Property(e => e.Description).HasComment("The description of the App.");
entity.Property(e => e.Name).HasComment("The name of the App.");
entity.Property(e => e.Permission).HasComment("The permission of the App.");
entity.Property(e => e.Secret).HasComment("The secret key of the App.");
entity.Property(e => e.UserId).HasComment("The owner ID.");
entity.HasOne(d => d.User)
.WithMany(p => p.Apps)
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity<AttestationChallenge>(entity =>
{
entity.Property(e => e.Challenge).HasComment("Hex-encoded sha256 hash of the challenge.");
@ -244,17 +222,8 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.HasDefaultValue(false)
.HasComment("Indicates that the challenge is only for registration purposes if true to prevent the challenge for being used as authentication.");
entity.HasOne(d => d.User).WithMany(p => p.AttestationChallenges);
});
modelBuilder.Entity<AuthSession>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the AuthSession.");
entity.HasOne(d => d.App).WithMany(p => p.AuthSessions);
entity.HasOne(d => d.User)
.WithMany(p => p.AuthSessions)
.WithMany(p => p.AttestationChallenges)
.OnDelete(DeleteBehavior.Cascade);
});
@ -272,9 +241,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.BlockerId).HasComment("The blocker user ID.");
entity.Property(e => e.CreatedAt).HasComment("The created date of the Blocking.");
entity.HasOne(d => d.Blockee).WithMany(p => p.IncomingBlocks);
entity.HasOne(d => d.Blockee)
.WithMany(p => p.IncomingBlocks)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Blocker).WithMany(p => p.OutgoingBlocks);
entity.HasOne(d => d.Blocker)
.WithMany(p => p.OutgoingBlocks)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Channel>(entity =>
@ -306,18 +279,26 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.FolloweeId).HasComment("The followee channel ID.");
entity.Property(e => e.FollowerId).HasComment("The follower user ID.");
entity.HasOne(d => d.Followee).WithMany(p => p.ChannelFollowings);
entity.HasOne(d => d.Followee)
.WithMany(p => p.ChannelFollowings)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Follower).WithMany(p => p.ChannelFollowings);
entity.HasOne(d => d.Follower)
.WithMany(p => p.ChannelFollowings)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<ChannelNotePin>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the ChannelNotePin.");
entity.HasOne(d => d.Channel).WithMany(p => p.ChannelNotePins);
entity.HasOne(d => d.Channel)
.WithMany(p => p.ChannelNotePins)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Note).WithMany(p => p.ChannelNotePins);
entity.HasOne(d => d.Note)
.WithMany(p => p.ChannelNotePins)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Clip>(entity =>
@ -328,7 +309,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.Name).HasComment("The name of the Clip.");
entity.Property(e => e.UserId).HasComment("The owner ID.");
entity.HasOne(d => d.User).WithMany(p => p.Clips);
entity.HasOne(d => d.User)
.WithMany(p => p.Clips)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<ClipNote>(entity =>
@ -336,9 +319,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.ClipId).HasComment("The clip ID.");
entity.Property(e => e.NoteId).HasComment("The note ID.");
entity.HasOne(d => d.Clip).WithMany(p => p.ClipNotes);
entity.HasOne(d => d.Clip)
.WithMany(p => p.ClipNotes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Note).WithMany(p => p.ClipNotes);
entity.HasOne(d => d.Note)
.WithMany(p => p.ClipNotes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<DriveFile>(entity =>
@ -417,9 +404,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.FollowerSharedInbox).HasComment("[Denormalized]");
entity.Property(e => e.RequestId).HasComment("id of Follow Activity.");
entity.HasOne(d => d.Followee).WithMany(p => p.IncomingFollowRequests);
entity.HasOne(d => d.Followee)
.WithMany(p => p.IncomingFollowRequests)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Follower).WithMany(p => p.OutgoingFollowRequests);
entity.HasOne(d => d.Follower)
.WithMany(p => p.OutgoingFollowRequests)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Following>(entity =>
@ -434,16 +425,24 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.FollowerInbox).HasComment("[Denormalized]");
entity.Property(e => e.FollowerSharedInbox).HasComment("[Denormalized]");
entity.HasOne(d => d.Followee).WithMany(p => p.IncomingFollowRelationships);
entity.HasOne(d => d.Followee)
.WithMany(p => p.IncomingFollowRelationships)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Follower).WithMany(p => p.OutgoingFollowRelationships);
entity.HasOne(d => d.Follower)
.WithMany(p => p.OutgoingFollowRelationships)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GalleryLike>(entity =>
{
entity.HasOne(d => d.Post).WithMany(p => p.GalleryLikes);
entity.HasOne(d => d.Post)
.WithMany(p => p.GalleryLikes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.GalleryLikes);
entity.HasOne(d => d.User)
.WithMany(p => p.GalleryLikes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<GalleryPost>(entity =>
@ -458,7 +457,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.UpdatedAt).HasComment("The updated date of the GalleryPost.");
entity.Property(e => e.UserId).HasComment("The ID of author.");
entity.HasOne(d => d.User).WithMany(p => p.GalleryPosts);
entity.HasOne(d => d.User)
.WithMany(p => p.GalleryPosts)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Hashtag>();
@ -501,7 +502,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.MessagingMessageRecipients)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.MessagingMessageUsers);
entity.HasOne(d => d.User)
.WithMany(p => p.MessagingMessageUsers)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Marker>(entity =>
@ -572,7 +575,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the ModerationLog.");
entity.HasOne(d => d.User).WithMany(p => p.ModerationLogs);
entity.HasOne(d => d.User)
.WithMany(p => p.ModerationLogs)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Muting>(entity =>
@ -581,9 +586,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.MuteeId).HasComment("The mutee user ID.");
entity.Property(e => e.MuterId).HasComment("The muter user ID.");
entity.HasOne(d => d.Mutee).WithMany(p => p.IncomingMutes);
entity.HasOne(d => d.Mutee)
.WithMany(p => p.IncomingMutes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Muter).WithMany(p => p.OutgoingMutes);
entity.HasOne(d => d.Muter)
.WithMany(p => p.OutgoingMutes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Note>(entity =>
@ -636,7 +645,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.InverseReply)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.Notes);
entity.HasOne(d => d.User)
.WithMany(p => p.Notes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteEdit>(entity =>
@ -645,36 +656,53 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.NoteId).HasComment("The ID of note.");
entity.Property(e => e.UpdatedAt).HasComment("The updated date of the Note.");
entity.HasOne(d => d.Note).WithMany(p => p.NoteEdits);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteEdits)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteBookmark>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the NoteBookmark.");
entity.HasOne(d => d.Note).WithMany(p => p.NoteBookmarks);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteBookmarks)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.NoteBookmarks);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteBookmarks)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteLike>(entity =>
{
entity.HasOne(d => d.Note).WithMany(p => p.NoteLikes);
entity.HasOne(d => d.User).WithMany(p => p.NoteLikes);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteLikes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteLikes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteReaction>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the NoteReaction.");
entity.HasOne(d => d.Note).WithMany(p => p.NoteReactions);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteReactions)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.NoteReactions);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteReactions)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteThreadMuting>(entity =>
{
entity.HasOne(d => d.User).WithMany(p => p.NoteThreadMutings);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteThreadMutings)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteUnread>(entity =>
@ -682,9 +710,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.NoteChannelId).HasComment("[Denormalized]");
entity.Property(e => e.NoteUserId).HasComment("[Denormalized]");
entity.HasOne(d => d.Note).WithMany(p => p.NoteUnreads);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteUnreads)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.NoteUnreads);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteUnreads)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<NoteWatching>(entity =>
@ -694,9 +726,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.NoteUserId).HasComment("[Denormalized]");
entity.Property(e => e.UserId).HasComment("The watcher ID.");
entity.HasOne(d => d.Note).WithMany(p => p.NoteWatchings);
entity.HasOne(d => d.Note)
.WithMany(p => p.NoteWatchings)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.NoteWatchings);
entity.HasOne(d => d.User)
.WithMany(p => p.NoteWatchings)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Notification>(entity =>
@ -709,10 +745,6 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.NotifierId).HasComment("The ID of sender user of the Notification.");
entity.Property(e => e.Type).HasComment("The type of the Notification.");
entity.HasOne(d => d.AppAccessToken)
.WithMany(p => p.Notifications)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.FollowRequest)
.WithMany(p => p.Notifications)
.OnDelete(DeleteBehavior.Cascade);
@ -721,7 +753,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.Notifications)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Notifiee).WithMany(p => p.NotificationNotifiees);
entity.HasOne(d => d.Notifiee)
.WithMany(p => p.NotificationNotifiees)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Notifier)
.WithMany(p => p.NotificationNotifiers)
@ -758,8 +792,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.HasComment("Whether the backend should automatically detect quote posts coming from this client")
.HasDefaultValue(true);
entity.HasOne(d => d.App).WithMany(p => p.OauthTokens);
entity.HasOne(d => d.User).WithMany(p => p.OauthTokens);
entity.HasOne(d => d.App)
.WithMany(p => p.OauthTokens)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User)
.WithMany(p => p.OauthTokens)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Page>(entity =>
@ -778,19 +817,27 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithMany(p => p.Pages)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.Pages);
entity.HasOne(d => d.User)
.WithMany(p => p.Pages)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<PageLike>(entity =>
{
entity.HasOne(d => d.Page).WithMany(p => p.PageLikes);
entity.HasOne(d => d.Page)
.WithMany(p => p.PageLikes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.PageLikes);
entity.HasOne(d => d.User)
.WithMany(p => p.PageLikes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<PasswordResetRequest>(entity =>
{
entity.HasOne(d => d.User).WithMany(p => p.PasswordResetRequests);
entity.HasOne(d => d.User)
.WithMany(p => p.PasswordResetRequests)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Poll>(entity =>
@ -800,35 +847,47 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.UserId).HasComment("[Denormalized]");
entity.Property(e => e.NoteVisibility).HasComment("[Denormalized]");
entity.HasOne(d => d.Note).WithOne(p => p.Poll);
entity.HasOne(d => d.Note)
.WithOne(p => p.Poll)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<PollVote>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the PollVote.");
entity.HasOne(d => d.Note).WithMany(p => p.PollVotes);
entity.HasOne(d => d.Note)
.WithMany(p => p.PollVotes)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.PollVotes);
entity.HasOne(d => d.User)
.WithMany(p => p.PollVotes)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<PromoNote>(entity =>
{
entity.Property(e => e.UserId).HasComment("[Denormalized]");
entity.HasOne(d => d.Note).WithOne(p => p.PromoNote);
entity.HasOne(d => d.Note)
.WithOne(p => p.PromoNote)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<PromoRead>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the PromoRead.");
entity.HasOne(d => d.Note).WithMany(p => p.PromoReads);
entity.HasOne(d => d.Note)
.WithMany(p => p.PromoReads)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.PromoReads);
entity.HasOne(d => d.User)
.WithMany(p => p.PromoReads)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<RegistrationInvite>(_ => { });
modelBuilder.Entity<RegistrationInvite>();
modelBuilder.Entity<RegistryItem>(entity =>
{
@ -841,7 +900,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.HasDefaultValueSql("'{}'::jsonb")
.HasComment("The value of the RegistryItem.");
entity.HasOne(d => d.User).WithMany(p => p.RegistryItems);
entity.HasOne(d => d.User)
.WithMany(p => p.RegistryItems)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Relay>(_ => { });
@ -852,9 +913,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.MuteeId).HasComment("The mutee user ID.");
entity.Property(e => e.MuterId).HasComment("The muter user ID.");
entity.HasOne(d => d.Mutee).WithMany(p => p.RenoteMutingMutees);
entity.HasOne(d => d.Mutee)
.WithMany(p => p.RenoteMutingMutees)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Muter).WithMany(p => p.RenoteMutingMuters);
entity.HasOne(d => d.Muter)
.WithMany(p => p.RenoteMutingMuters)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Session>(entity =>
@ -864,24 +929,21 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.CreatedAt).HasComment("The created date of the OAuth token");
entity.Property(e => e.Token).HasComment("The authorization token");
entity.HasOne(d => d.User).WithMany(p => p.Sessions);
});
modelBuilder.Entity<Signin>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the Signin.");
entity.HasOne(d => d.User).WithMany(p => p.Signins);
entity.HasOne(d => d.User)
.WithMany(p => p.Sessions)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<SwSubscription>(entity =>
{
entity.Property(e => e.SendReadMessage).HasDefaultValue(false);
entity.HasOne(d => d.User).WithMany(p => p.SwSubscriptions);
entity.HasOne(d => d.User)
.WithMany(p => p.SwSubscriptions)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UsedUsername>(_ => { });
modelBuilder.Entity<UsedUsername>();
modelBuilder.Entity<User>(entity =>
{
@ -972,7 +1034,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.IsPrivate).HasDefaultValue(false);
entity.Property(e => e.UserId).HasComment("The ID of owner.");
entity.HasOne(d => d.User).WithMany(p => p.UserGroups);
entity.HasOne(d => d.User)
.WithMany(p => p.UserGroups)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserGroupInvitation>(entity =>
@ -981,9 +1045,13 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.UserGroupId).HasComment("The group ID.");
entity.Property(e => e.UserId).HasComment("The user ID.");
entity.HasOne(d => d.UserGroup).WithMany(p => p.UserGroupInvitations);
entity.HasOne(d => d.UserGroup)
.WithMany(p => p.UserGroupInvitations)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.UserGroupInvitations);
entity.HasOne(d => d.User)
.WithMany(p => p.UserGroupInvitations)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserGroupMember>(entity =>
@ -992,12 +1060,21 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.UserGroupId).HasComment("The group ID.");
entity.Property(e => e.UserId).HasComment("The user ID.");
entity.HasOne(d => d.UserGroup).WithMany(p => p.UserGroupMembers);
entity.HasOne(d => d.UserGroup)
.WithMany(p => p.UserGroupMembers)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.UserGroupMemberships);
entity.HasOne(d => d.User)
.WithMany(p => p.UserGroupMemberships)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserKeypair>(entity => { entity.HasOne(d => d.User).WithOne(p => p.UserKeypair); });
modelBuilder.Entity<UserKeypair>(entity =>
{
entity.HasOne(d => d.User)
.WithOne(p => p.UserKeypair)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserList>(entity =>
{
@ -1008,7 +1085,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.Name).HasComment("The name of the UserList.");
entity.Property(e => e.UserId).HasComment("The owner ID.");
entity.HasOne(d => d.User).WithMany(p => p.UserLists);
entity.HasOne(d => d.User)
.WithMany(p => p.UserLists)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserListMember>(entity =>
@ -1017,21 +1096,29 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.UserId).HasComment("The user ID.");
entity.Property(e => e.UserListId).HasComment("The list ID.");
entity.HasOne(d => d.User).WithMany(p => p.UserListMembers);
entity.HasOne(d => d.User)
.WithMany(p => p.UserListMembers)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.UserList).WithMany(p => p.UserListMembers);
entity.HasOne(d => d.UserList)
.WithMany(p => p.UserListMembers)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserNotePin>(entity =>
{
entity.Property(e => e.CreatedAt).HasComment("The created date of the UserNotePins.");
entity.HasOne(d => d.Note).WithMany(p => p.UserNotePins);
entity.HasOne(d => d.Note)
.WithMany(p => p.UserNotePins)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.User).WithMany(p => p.UserNotePins);
entity.HasOne(d => d.User)
.WithMany(p => p.UserNotePins)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserPending>(_ => { });
modelBuilder.Entity<UserPending>();
modelBuilder.Entity<UserProfile>(entity =>
{
@ -1086,10 +1173,17 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
.WithOne(p => p.UserProfile)
.OnDelete(DeleteBehavior.SetNull);
entity.HasOne(d => d.User).WithOne(p => p.UserProfile);
entity.HasOne(d => d.User)
.WithOne(p => p.UserProfile)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserPublickey>(entity => { entity.HasOne(d => d.User).WithOne(p => p.UserPublickey); });
modelBuilder.Entity<UserPublickey>(entity =>
{
entity.HasOne(d => d.User)
.WithOne(p => p.UserPublickey)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserSecurityKey>(entity =>
{
@ -1100,7 +1194,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.PublicKey)
.HasComment("Variable-length public key used to verify attestations (hex-encoded).");
entity.HasOne(d => d.User).WithMany(p => p.UserSecurityKeys);
entity.HasOne(d => d.User)
.WithMany(p => p.UserSecurityKeys)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<UserSettings>(entity =>
@ -1118,7 +1214,9 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
entity.Property(e => e.On).HasDefaultValueSql("'{}'::character varying[]");
entity.Property(e => e.UserId).HasComment("The owner ID.");
entity.HasOne(d => d.User).WithMany(p => p.Webhooks);
entity.HasOne(d => d.User)
.WithMany(p => p.Webhooks)
.OnDelete(DeleteBehavior.Cascade);
});
}

View file

@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
public partial class FixupDeleteConstraints : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_notification_access_token_appAccessTokenId",
table: "notification");
migrationBuilder.DropTable(
name: "access_token");
migrationBuilder.DropTable(
name: "auth_session");
migrationBuilder.DropTable(
name: "signin");
migrationBuilder.DropTable(
name: "app");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "app",
columns: table => new
{
id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true, comment: "The owner ID."),
callbackUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true, comment: "The callbackUrl of the App."),
createdAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "The created date of the App."),
description = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false, comment: "The description of the App."),
name = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false, comment: "The name of the App."),
permission = table.Column<List<string>>(type: "character varying(64)[]", nullable: false, comment: "The permission of the App."),
secret = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false, comment: "The secret key of the App.")
},
constraints: table =>
{
table.PrimaryKey("PK_app", x => x.id);
table.ForeignKey(
name: "FK_app_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "signin",
columns: table => new
{
id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
createdAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "The created date of the Signin."),
headers = table.Column<Dictionary<string, string>>(type: "jsonb", nullable: false),
ip = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
success = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_signin", x => x.id);
table.ForeignKey(
name: "FK_signin_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "access_token",
columns: table => new
{
id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
appId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
createdAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "The created date of the AccessToken."),
description = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
fetched = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
hash = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
iconUrl = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
lastUsedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
name = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
permission = table.Column<List<string>>(type: "character varying(64)[]", nullable: false, defaultValueSql: "'{}'::character varying[]"),
session = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
token = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_access_token", x => x.id);
table.ForeignKey(
name: "FK_access_token_app_appId",
column: x => x.appId,
principalTable: "app",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_access_token_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "auth_session",
columns: table => new
{
id = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
appId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
userId = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
createdAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "The created date of the AuthSession."),
token = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_auth_session", x => x.id);
table.ForeignKey(
name: "FK_auth_session_app_appId",
column: x => x.appId,
principalTable: "app",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_auth_session_user_userId",
column: x => x.userId,
principalTable: "user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_access_token_appId",
table: "access_token",
column: "appId");
migrationBuilder.CreateIndex(
name: "IX_access_token_hash",
table: "access_token",
column: "hash");
migrationBuilder.CreateIndex(
name: "IX_access_token_session",
table: "access_token",
column: "session");
migrationBuilder.CreateIndex(
name: "IX_access_token_token",
table: "access_token",
column: "token");
migrationBuilder.CreateIndex(
name: "IX_access_token_userId",
table: "access_token",
column: "userId");
migrationBuilder.CreateIndex(
name: "IX_app_createdAt",
table: "app",
column: "createdAt");
migrationBuilder.CreateIndex(
name: "IX_app_secret",
table: "app",
column: "secret");
migrationBuilder.CreateIndex(
name: "IX_app_userId",
table: "app",
column: "userId");
migrationBuilder.CreateIndex(
name: "IX_auth_session_appId",
table: "auth_session",
column: "appId");
migrationBuilder.CreateIndex(
name: "IX_auth_session_token",
table: "auth_session",
column: "token");
migrationBuilder.CreateIndex(
name: "IX_auth_session_userId",
table: "auth_session",
column: "userId");
migrationBuilder.CreateIndex(
name: "IX_signin_userId",
table: "signin",
column: "userId");
migrationBuilder.AddForeignKey(
name: "FK_notification_access_token_appAccessTokenId",
table: "notification",
column: "appAccessTokenId",
principalTable: "access_token",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
}
}
}

View file

@ -110,93 +110,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("abuse_user_report");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AccessToken", b =>
{
b.Property<string>("Id")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("id");
b.Property<string>("AppId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("appId");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("createdAt")
.HasComment("The created date of the AccessToken.");
b.Property<string>("Description")
.HasMaxLength(512)
.HasColumnType("character varying(512)")
.HasColumnName("description");
b.Property<bool>("Fetched")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("fetched");
b.Property<string>("Hash")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("hash");
b.Property<string>("IconUrl")
.HasMaxLength(512)
.HasColumnType("character varying(512)")
.HasColumnName("iconUrl");
b.Property<DateTime?>("LastUsedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("lastUsedAt");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("name");
b.Property<List<string>>("Permission")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("character varying(64)[]")
.HasColumnName("permission")
.HasDefaultValueSql("'{}'::character varying[]");
b.Property<string>("Session")
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("session");
b.Property<string>("Token")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("token");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId");
b.HasKey("Id");
b.HasIndex("AppId");
b.HasIndex("Hash");
b.HasIndex("Session");
b.HasIndex("Token");
b.HasIndex("UserId");
b.ToTable("access_token");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AllowedInstance", b =>
{
b.Property<string>("Host")
@ -406,68 +319,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("antenna");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.App", b =>
{
b.Property<string>("Id")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("id");
b.Property<string>("CallbackUrl")
.HasMaxLength(512)
.HasColumnType("character varying(512)")
.HasColumnName("callbackUrl")
.HasComment("The callbackUrl of the App.");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("createdAt")
.HasComment("The created date of the App.");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(512)
.HasColumnType("character varying(512)")
.HasColumnName("description")
.HasComment("The description of the App.");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("name")
.HasComment("The name of the App.");
b.Property<List<string>>("Permission")
.IsRequired()
.HasColumnType("character varying(64)[]")
.HasColumnName("permission")
.HasComment("The permission of the App.");
b.Property<string>("Secret")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("secret")
.HasComment("The secret key of the App.");
b.Property<string>("UserId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId")
.HasComment("The owner ID.");
b.HasKey("Id");
b.HasIndex("CreatedAt");
b.HasIndex("Secret");
b.HasIndex("UserId");
b.ToTable("app");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AttestationChallenge", b =>
{
b.Property<string>("Id")
@ -508,46 +359,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("attestation_challenge");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AuthSession", b =>
{
b.Property<string>("Id")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("id");
b.Property<string>("AppId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("appId");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("createdAt")
.HasComment("The created date of the AuthSession.");
b.Property<string>("Token")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("token");
b.Property<string>("UserId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId");
b.HasKey("Id");
b.HasIndex("AppId");
b.HasIndex("Token");
b.HasIndex("UserId");
b.ToTable("auth_session");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Bite", b =>
{
b.Property<string>("Id")
@ -3687,46 +3498,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.ToTable("session");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Signin", b =>
{
b.Property<string>("Id")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("id");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("createdAt")
.HasComment("The created date of the Signin.");
b.Property<Dictionary<string, string>>("Headers")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("headers");
b.Property<string>("Ip")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.HasColumnName("ip");
b.Property<bool>("Success")
.HasColumnType("boolean")
.HasColumnName("success");
b.Property<string>("UserId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("userId");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("signin");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.SwSubscription", b =>
{
b.Property<string>("Id")
@ -4834,24 +4605,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("TargetUser");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AccessToken", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.App", "App")
.WithMany("AccessTokens")
.HasForeignKey("AppId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithMany("AccessTokens")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("App");
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AnnouncementRead", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Announcement", "Announcement")
@ -4896,16 +4649,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("UserList");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.App", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithMany("Apps")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.SetNull);
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AttestationChallenge", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
@ -4917,24 +4660,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AuthSession", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.App", "App")
.WithMany("AuthSessions")
.HasForeignKey("AppId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithMany("AuthSessions")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("App");
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Bite", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Bite", "TargetBite")
@ -5397,11 +5122,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Notification", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.AccessToken", "AppAccessToken")
.WithMany("Notifications")
.HasForeignKey("AppAccessTokenId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.Bite", "Bite")
.WithMany()
.HasForeignKey("BiteId");
@ -5432,8 +5152,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasForeignKey("UserGroupInvitationId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("AppAccessToken");
b.Navigation("Bite");
b.Navigation("FollowRequest");
@ -5615,17 +5333,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Signin", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
.WithMany("Signins")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.SwSubscription", b =>
{
b.HasOne("Iceshrimp.Backend.Core.Database.Tables.User", "User")
@ -5825,23 +5532,11 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.AccessToken", b =>
{
b.Navigation("Notifications");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Announcement", b =>
{
b.Navigation("AnnouncementReads");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.App", b =>
{
b.Navigation("AccessTokens");
b.Navigation("AuthSessions");
});
modelBuilder.Entity("Iceshrimp.Backend.Core.Database.Tables.Channel", b =>
{
b.Navigation("ChannelFollowings");
@ -5941,18 +5636,12 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("AbuseUserReportTargetUsers");
b.Navigation("AccessTokens");
b.Navigation("AnnouncementReads");
b.Navigation("Antennas");
b.Navigation("Apps");
b.Navigation("AttestationChallenges");
b.Navigation("AuthSessions");
b.Navigation("ChannelFollowings");
b.Navigation("Channels");
@ -6029,8 +5718,6 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
b.Navigation("Sessions");
b.Navigation("Signins");
b.Navigation("SwSubscriptions");
b.Navigation("UserGroupInvitations");

View file

@ -1,64 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("access_token")]
[Index("Hash")]
[Index("Token")]
[Index("UserId")]
[Index("Session")]
public class AccessToken
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
/// <summary>
/// The created date of the AccessToken.
/// </summary>
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("token")] [StringLength(128)] public string Token { get; set; } = null!;
[Column("hash")] [StringLength(128)] public string Hash { get; set; } = null!;
[Column("userId")] [StringLength(32)] public string UserId { get; set; } = null!;
[Column("appId")] [StringLength(32)] public string? AppId { get; set; }
[Column("lastUsedAt")] public DateTime? LastUsedAt { get; set; }
[Column("session")]
[StringLength(128)]
public string? Session { get; set; }
[Column("name")] [StringLength(128)] public string? Name { get; set; }
[Column("description")]
[StringLength(512)]
public string? Description { get; set; }
[Column("iconUrl")]
[StringLength(512)]
public string? IconUrl { get; set; }
[Column("permission", TypeName = "character varying(64)[]")]
public List<string> Permission { get; set; } = null!;
[Column("fetched")] public bool Fetched { get; set; }
[ForeignKey("AppId")]
[InverseProperty(nameof(Tables.App.AccessTokens))]
public virtual App? App { get; set; }
[InverseProperty(nameof(Notification.AppAccessToken))]
public virtual ICollection<Notification> Notifications { get; set; } = new List<Notification>();
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.AccessTokens))]
public virtual User User { get; set; } = null!;
}

View file

@ -1,74 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("app")]
[Index("CreatedAt")]
[Index("UserId")]
[Index("Secret")]
public class App
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
/// <summary>
/// The created date of the App.
/// </summary>
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
/// <summary>
/// The owner ID.
/// </summary>
[Column("userId")]
[StringLength(32)]
public string? UserId { get; set; }
/// <summary>
/// The secret key of the App.
/// </summary>
[Column("secret")]
[StringLength(64)]
public string Secret { get; set; } = null!;
/// <summary>
/// The name of the App.
/// </summary>
[Column("name")]
[StringLength(128)]
public string Name { get; set; } = null!;
/// <summary>
/// The description of the App.
/// </summary>
[Column("description")]
[StringLength(512)]
public string Description { get; set; } = null!;
/// <summary>
/// The permission of the App.
/// </summary>
[Column("permission", TypeName = "character varying(64)[]")]
public List<string> Permission { get; set; } = null!;
/// <summary>
/// The callbackUrl of the App.
/// </summary>
[Column("callbackUrl")]
[StringLength(512)]
public string? CallbackUrl { get; set; }
[InverseProperty(nameof(AccessToken.App))]
public virtual ICollection<AccessToken> AccessTokens { get; set; } = new List<AccessToken>();
[InverseProperty(nameof(AuthSession.App))]
public virtual ICollection<AuthSession> AuthSessions { get; set; } = new List<AuthSession>();
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.Apps))]
public virtual User? User { get; set; }
}

View file

@ -1,35 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("auth_session")]
[Index("Token")]
public class AuthSession
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
/// <summary>
/// The created date of the AuthSession.
/// </summary>
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("token")] [StringLength(128)] public string Token { get; set; } = null!;
[Column("userId")] [StringLength(32)] public string? UserId { get; set; }
[Column("appId")] [StringLength(32)] public string AppId { get; set; } = null!;
[ForeignKey("AppId")]
[InverseProperty(nameof(Tables.App.AuthSessions))]
public virtual App App { get; set; } = null!;
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.AuthSessions))]
public virtual User? User { get; set; }
}

View file

@ -95,10 +95,6 @@ public class Notification : IEntity
[StringLength(32)]
public string? AppAccessTokenId { get; set; }
[ForeignKey("AppAccessTokenId")]
[InverseProperty(nameof(AccessToken.Notifications))]
public virtual AccessToken? AppAccessToken { get; set; }
[ForeignKey("FollowRequestId")]
[InverseProperty(nameof(Tables.FollowRequest.Notifications))]
public virtual FollowRequest? FollowRequest { get; set; }

View file

@ -1,34 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace Iceshrimp.Backend.Core.Database.Tables;
[Table("signin")]
[Index("UserId")]
public class Signin
{
[Key]
[Column("id")]
[StringLength(32)]
public string Id { get; set; } = null!;
/// <summary>
/// The created date of the Signin.
/// </summary>
[Column("createdAt")]
public DateTime CreatedAt { get; set; }
[Column("userId")] [StringLength(32)] public string UserId { get; set; } = null!;
[Column("ip")] [StringLength(128)] public string Ip { get; set; } = null!;
[Column("headers", TypeName = "jsonb")]
public Dictionary<string, string> Headers { get; set; } = null!;
[Column("success")] public bool Success { get; set; }
[ForeignKey("UserId")]
[InverseProperty(nameof(Tables.User.Signins))]
public virtual User User { get; set; } = null!;
}

View file

@ -274,24 +274,16 @@ public class User : IEntity
[InverseProperty(nameof(AbuseUserReport.TargetUser))]
public virtual ICollection<AbuseUserReport> AbuseUserReportTargetUsers { get; set; } = new List<AbuseUserReport>();
[InverseProperty(nameof(AccessToken.User))]
public virtual ICollection<AccessToken> AccessTokens { get; set; } = new List<AccessToken>();
[InverseProperty(nameof(AnnouncementRead.User))]
public virtual ICollection<AnnouncementRead> AnnouncementReads { get; set; } = new List<AnnouncementRead>();
[InverseProperty(nameof(Antenna.User))]
public virtual ICollection<Antenna> Antennas { get; set; } = new List<Antenna>();
[InverseProperty(nameof(App.User))] public virtual ICollection<App> Apps { get; set; } = new List<App>();
[InverseProperty(nameof(AttestationChallenge.User))]
public virtual ICollection<AttestationChallenge> AttestationChallenges { get; set; } =
new List<AttestationChallenge>();
[InverseProperty(nameof(AuthSession.User))]
public virtual ICollection<AuthSession> AuthSessions { get; set; } = new List<AuthSession>();
[ForeignKey("AvatarId")]
[InverseProperty(nameof(DriveFile.UserAvatar))]
public virtual DriveFile? Avatar { get; set; }
@ -445,9 +437,6 @@ public class User : IEntity
[InverseProperty(nameof(Session.User))]
public virtual ICollection<Session> Sessions { get; set; } = new List<Session>();
[InverseProperty(nameof(Signin.User))]
public virtual ICollection<Signin> Signins { get; set; } = new List<Signin>();
[InverseProperty(nameof(SwSubscription.User))]
public virtual ICollection<SwSubscription> SwSubscriptions { get; set; } = new List<SwSubscription>();

View file

@ -187,6 +187,7 @@ public class UserService(
{
var bgDb = provider.GetRequiredService<DatabaseContext>();
var bgInstanceSvc = provider.GetRequiredService<InstanceService>();
var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(user);
await bgDb.Instances.Where(p => p.Id == dbInstance.Id)
.ExecuteUpdateAsync(p => p.SetProperty(i => i.UsersCount, i => i.UsersCount + 1));