[backend/database] Resync constraint/index differences between native .net databases and ones migrated from -js

This commit is contained in:
Laura Hausmann 2024-07-12 21:02:51 +02:00
parent 21ce68bcaa
commit b7646f4d6c
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 43 additions and 3 deletions

View file

@ -13,9 +13,10 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropIndex( migrationBuilder.Sql("""
name: "IX_user_token", ALTER TABLE "user" DROP CONSTRAINT IF EXISTS "IX_user_token";
table: "user"); DROP INDEX IF EXISTS "IX_user_token";
""");
migrationBuilder.DropColumn( migrationBuilder.DropColumn(
name: "hideOnlineStatus", name: "hideOnlineStatus",

View file

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
#nullable disable
namespace Iceshrimp.Backend.Core.Database.Migrations
{
/// <inheritdoc />
[DbContext(typeof(DatabaseContext))]
[Migration("20240712174827_ConvertConstraintsToUniqueIndicies")]
public partial class ConvertConstraintsToUniqueIndicies : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
ALTER TABLE "user" DROP CONSTRAINT IF EXISTS "IX_user_avatarId";
ALTER TABLE "user" DROP CONSTRAINT IF EXISTS "IX_user_bannerId";
ALTER TABLE "user_profile" DROP CONSTRAINT IF EXISTS "IX_user_profile_pinnedPageId";
CREATE UNIQUE INDEX IF NOT EXISTS "IX_user_avatarId" ON "user" ("avatarId");
CREATE UNIQUE INDEX IF NOT EXISTS "IX_user_bannerId" ON "user" ("bannerId");
CREATE UNIQUE INDEX IF NOT EXISTS "IX_user_profile_pinnedPageId" ON "user_profile" ("pinnedPageId");
""");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
DROP INDEX "IX_user_avatarId";
DROP INDEX "IX_user_bannerId";
DROP INDEX "IX_user_profile_pinnedPageId";
ALTER TABLE "user" ADD CONSTRAINT "IX_user_avatarId" UNIQUE ("avatarId");
ALTER TABLE "user" ADD CONSTRAINT "IX_user_bannerId" UNIQUE ("bannerId");
ALTER TABLE "user_profile" ADD CONSTRAINT "IX_user_profile_pinnedPageId" UNIQUE ("pinnedPageId");
""");
}
}
}