[backend/database] Fixup User.alsoKnownAs

This commit is contained in:
Laura Hausmann 2024-02-10 16:19:27 +01:00
parent 357f11d513
commit 9680921711
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 6012 additions and 7 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,43 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
public partial class UserAlsoKnownAsToArray : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<List<string>>(name: "alsoKnownAs_new",
table: "user",
type: "text[]",
nullable: true,
comment: "URIs the user is known as too");
migrationBuilder.Sql("""
UPDATE "user" SET "alsoKnownAs_new" = string_to_array("alsoKnownAs", ',') WHERE "alsoKnownAs" IS NOT NULL;
ALTER TABLE "user" DROP COLUMN "alsoKnownAs";
ALTER TABLE "user" RENAME COLUMN "alsoKnownAs_new" TO "alsoKnownAs";
""");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(name: "alsoKnownAs_new",
table: "user",
type: "text",
nullable: true,
comment: "URIs the user is known as too");
migrationBuilder.Sql("""
UPDATE "user" SET "alsoKnownAs_new" = array_to_string("alsoKnownAs", ',') WHERE "alsoKnownAs" IS NOT NULL;
ALTER TABLE "user" DROP COLUMN "alsoKnownAs";
ALTER TABLE "user" RENAME COLUMN "alsoKnownAs_new" TO "alsoKnownAs";
""");
}
}
}

View file

@ -3760,8 +3760,8 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
.HasColumnType("character varying(32)") .HasColumnType("character varying(32)")
.HasColumnName("id"); .HasColumnName("id");
b.Property<string>("AlsoKnownAs") b.Property<List<string>>("AlsoKnownAs")
.HasColumnType("text") .HasColumnType("text[]")
.HasColumnName("alsoKnownAs") .HasColumnName("alsoKnownAs")
.HasComment("URIs the user is known as too"); .HasComment("URIs the user is known as too");

View file

@ -226,7 +226,7 @@ public class User : IEntity {
/// URIs the user is known as too /// URIs the user is known as too
/// </summary> /// </summary>
[Column("alsoKnownAs")] [Column("alsoKnownAs")]
public string? AlsoKnownAs { get; set; } public List<string>? AlsoKnownAs { get; set; }
/// <summary> /// <summary>
/// Whether to speak as a cat if isCat. /// Whether to speak as a cat if isCat.

View file

@ -93,8 +93,7 @@ public class ASActor : ASObject {
public ASLink? MovedTo { get; set; } public ASLink? MovedTo { get; set; }
[J("https://www.w3.org/ns/activitystreams#alsoKnownAs")] [J("https://www.w3.org/ns/activitystreams#alsoKnownAs")]
[JC(typeof(ASLinkConverter))] public List<ASLink>? AlsoKnownAs { get; set; } = [];
public ASLink? AlsoKnownAs { get; set; }
[J("http://joinmastodon.org/ns#featured")] [J("http://joinmastodon.org/ns#featured")]
[JC(typeof(ASLinkConverter))] [JC(typeof(ASLinkConverter))]

View file

@ -75,7 +75,7 @@ public class UserService(
UsernameLower = actor.Username!.ToLowerInvariant(), UsernameLower = actor.Username!.ToLowerInvariant(),
Host = AcctToTuple(acct).Host, Host = AcctToTuple(acct).Host,
MovedToUri = actor.MovedTo?.Link, MovedToUri = actor.MovedTo?.Link,
AlsoKnownAs = actor.AlsoKnownAs?.Link, AlsoKnownAs = actor.AlsoKnownAs?.Where(p => p.Link != null).Select(p => p.Link!).ToList(),
IsExplorable = actor.IsDiscoverable ?? false, IsExplorable = actor.IsDiscoverable ?? false,
Inbox = actor.Inbox?.Link, Inbox = actor.Inbox?.Link,
SharedInbox = actor.SharedInbox?.Link ?? actor.Endpoints?.SharedInbox?.Id, SharedInbox = actor.SharedInbox?.Link ?? actor.Endpoints?.SharedInbox?.Id,
@ -137,7 +137,7 @@ public class UserService(
user.IsLocked = actor.IsLocked ?? false; user.IsLocked = actor.IsLocked ?? false;
user.IsBot = actor.IsBot; user.IsBot = actor.IsBot;
user.MovedToUri = actor.MovedTo?.Link; user.MovedToUri = actor.MovedTo?.Link;
user.AlsoKnownAs = actor.AlsoKnownAs?.Link; user.AlsoKnownAs = actor.AlsoKnownAs?.Where(p => p.Link != null).Select(p => p.Link!).ToList();
user.IsExplorable = actor.IsDiscoverable ?? false; user.IsExplorable = actor.IsDiscoverable ?? false;
user.FollowersUri = actor.Followers?.Id; user.FollowersUri = actor.Followers?.Id;
user.IsCat = actor.IsCat ?? false; user.IsCat = actor.IsCat ?? false;