diff --git a/Iceshrimp.Backend/Core/Database/Migrations/20240605135805_FixupPollVotersCounts.cs b/Iceshrimp.Backend/Core/Database/Migrations/20240605135805_FixupPollVotersCounts.cs new file mode 100644 index 00000000..f1cc67b5 --- /dev/null +++ b/Iceshrimp.Backend/Core/Database/Migrations/20240605135805_FixupPollVotersCounts.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Infrastructure; + +#nullable disable + +namespace Iceshrimp.Backend.Core.Database.Migrations +{ + /// + [DbContext(typeof(DatabaseContext))] + [Migration("20240605135805_FixupPollVotersCounts")] + public partial class FixupPollVotersCounts : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql($"""UPDATE "poll" SET "votersCount" = NULL;"""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Iceshrimp.Backend/Core/Services/PollService.cs b/Iceshrimp.Backend/Core/Services/PollService.cs index a82d7fac..446da458 100644 --- a/Iceshrimp.Backend/Core/Services/PollService.cs +++ b/Iceshrimp.Backend/Core/Services/PollService.cs @@ -20,7 +20,7 @@ public class PollService( { if (!updateVotersCount) return; await db.Database - .ExecuteSqlAsync($"""UPDATE "poll" SET "votersCount" = (SELECT COUNT(*) FROM (SELECT DISTINCT "userId" FROM "poll_vote" WHERE "noteId" = {poll.NoteId}));"""); + .ExecuteSqlAsync($"""UPDATE "poll" SET "votersCount" = (SELECT COUNT(*) FROM (SELECT DISTINCT "userId" FROM "poll_vote" WHERE "noteId" = {poll.NoteId})) WHERE "noteId" = {poll.NoteId};"""); return; }