Iceshrimp.NET/Iceshrimp.Backend/Core/Database/Migrations/20240210151527_UserAlsoKnownAsToArray.cs
2024-02-10 16:25:16 +01:00

43 lines
1.9 KiB
C#

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";
""");
}
}
}