From e8a6629cb5b8e10ec3d6d15dfc5d13d220883f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 5 Mar 2025 16:49:49 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E3=82=B7=E3=82=B9=E3=83=86?= =?UTF-8?q?=E3=83=A0=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E7=B3=BB?= =?UTF-8?q?=E3=81=AE=E3=83=9E=E3=82=A4=E3=82=B0=E3=83=AC=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E4=B8=8D=E8=B6=B3=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20(#15586)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(backend): プロキシアカウントのロールバック用マイグレーションを追加 * fix * separate newly-added `up` command * drop backwards-compatibility * docs --- .../1740129169650-system-accounts-2.js | 4 ++++ .../1740133121105-system-accounts-3.js | 8 ++++---- .../1740993126937-system-accounts-4.js | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 packages/backend/migration/1740993126937-system-accounts-4.js diff --git a/packages/backend/migration/1740129169650-system-accounts-2.js b/packages/backend/migration/1740129169650-system-accounts-2.js index 07270855b..c03f0337a 100644 --- a/packages/backend/migration/1740129169650-system-accounts-2.js +++ b/packages/backend/migration/1740129169650-system-accounts-2.js @@ -13,6 +13,10 @@ export class SystemAccounts21740129169650 { async down(queryRunner) { await queryRunner.query(`ALTER TABLE "meta" ADD "proxyAccountId" character varying(32)`); + const proxyAccountId = await queryRunner.query(`SELECT "userId" FROM "system_account" WHERE "type" = 'proxy' ORDER BY "id" DESC LIMIT 1`); + if (proxyAccountId && proxyAccountId.length >= 1) { + await queryRunner.query(`UPDATE "meta" SET "proxyAccountId" = '${proxyAccountId[0].userId}'`); + } await queryRunner.query(`ALTER TABLE "meta" ADD CONSTRAINT "FK_ab1bc0c1e209daa77b8e8d212ad" FOREIGN KEY ("proxyAccountId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); } } diff --git a/packages/backend/migration/1740133121105-system-accounts-3.js b/packages/backend/migration/1740133121105-system-accounts-3.js index 02f9207cd..a1f8c996f 100644 --- a/packages/backend/migration/1740133121105-system-accounts-3.js +++ b/packages/backend/migration/1740133121105-system-accounts-3.js @@ -10,10 +10,10 @@ export class SystemAccounts31740133121105 { await queryRunner.query(`ALTER TABLE "meta" ADD "rootUserId" character varying(32)`); await queryRunner.query(`ALTER TABLE "meta" ADD CONSTRAINT "FK_c80e4079d632f95eac06a9d28cc" FOREIGN KEY ("rootUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); - const users = await queryRunner.query(`SELECT "id" FROM "user" WHERE "isRoot" = true LIMIT 1`); - if (users.length > 0) { - await queryRunner.query(`UPDATE "meta" SET "rootUserId" = $1`, [users[0].id]); - } + const users = await queryRunner.query(`SELECT "id" FROM "user" WHERE "isRoot" = true LIMIT 1`); + if (users.length > 0) { + await queryRunner.query(`UPDATE "meta" SET "rootUserId" = $1`, [users[0].id]); + } } async down(queryRunner) { diff --git a/packages/backend/migration/1740993126937-system-accounts-4.js b/packages/backend/migration/1740993126937-system-accounts-4.js new file mode 100644 index 000000000..83654aca8 --- /dev/null +++ b/packages/backend/migration/1740993126937-system-accounts-4.js @@ -0,0 +1,17 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export class SystemAccounts41740993126937 { + name = 'SystemAccounts41740993126937' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isRoot"`); + } + + async down(queryRunner) { + // down 実行時は isRoot = true のユーザーが存在しなくなるため手動で対応する必要あり + await queryRunner.query(`ALTER TABLE "user" ADD "isRoot" boolean NOT NULL DEFAULT false`); + } +}