From 881b914c6a7bdf73ed16194e71aa779b27de074e Mon Sep 17 00:00:00 2001
From: MeiMei <30769358+mei23@users.noreply.github.com>
Date: Wed, 18 Aug 2021 22:04:04 +0900
Subject: [PATCH] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB?=
 =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B?=
 =?UTF-8?q?=E3=81=A8=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E3=82=92?=
 =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=81=AE?=
 =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20(#7653)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* チャンネルを作成しているとアカウントを削除できないのを修正

* CHANGELOG

* nullable
---
 CHANGELOG.md                                  |  7 +++++++
 migration/1629288472000-fix-channel-userId.ts | 14 ++++++++++++++
 src/models/entities/channel.ts                |  3 ++-
 src/models/repositories/channel.ts            |  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 migration/1629288472000-fix-channel-userId.ts

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6d782c519..2ce3065a10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@
 
 -->
 
+## 12.x.x (unreleased)
+
+### Improvements
+
+### Bugfixes
+- チャンネルを作成しているとアカウントを削除できないのを修正
+
 ## 12.88.0 (2021/08/17)
 
 ### Features
diff --git a/migration/1629288472000-fix-channel-userId.ts b/migration/1629288472000-fix-channel-userId.ts
new file mode 100644
index 0000000000..cd8f81bb01
--- /dev/null
+++ b/migration/1629288472000-fix-channel-userId.ts
@@ -0,0 +1,14 @@
+import {MigrationInterface, QueryRunner} from "typeorm";
+
+export class fixChannelUserId1629288472000 implements MigrationInterface {
+    name = 'fixChannelUserId1629288472000'
+
+    public async up(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`ALTER TABLE "channel" ALTER COLUMN "userId" DROP NOT NULL;`);
+    }
+
+    public async down(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`ALTER TABLE "channel" ALTER COLUMN "userId" SET NOT NULL;`);
+    }
+
+}
diff --git a/src/models/entities/channel.ts b/src/models/entities/channel.ts
index 1868f75143..f2d713612d 100644
--- a/src/models/entities/channel.ts
+++ b/src/models/entities/channel.ts
@@ -23,9 +23,10 @@ export class Channel {
 	@Index()
 	@Column({
 		...id(),
+		nullable: true,
 		comment: 'The owner ID.'
 	})
-	public userId: User['id'];
+	public userId: User['id'] | null;
 
 	@ManyToOne(type => User, {
 		onDelete: 'SET NULL'
diff --git a/src/models/repositories/channel.ts b/src/models/repositories/channel.ts
index 3a6bd4c923..007b110015 100644
--- a/src/models/repositories/channel.ts
+++ b/src/models/repositories/channel.ts
@@ -90,7 +90,7 @@ export const packedChannelSchema = {
 		},
 		userId: {
 			type: 'string' as const,
-			nullable: false as const, optional: false as const,
+			nullable: true as const, optional: false as const,
 			format: 'id',
 		},
 	},
-- 
GitLab