summary refs log tree commit diff
diff options
context:
space:
mode:
authorPuyodead1 <puyodead@proton.me>2024-04-14 14:02:22 -0400
committerPuyodead1 <puyodead@proton.me>2024-04-14 14:02:22 -0400
commitee59ee7e1cf4c5b9ae749745471a1f98053c3c58 (patch)
treef4014c5b2d82752e41355816374ae51f50229486
parentAdd nix flake to repo (#1111) (diff)
downloadserver-ee59ee7e1cf4c5b9ae749745471a1f98053c3c58.tar.xz
Fix message flags being null
-rw-r--r--src/util/entities/Message.ts4
-rw-r--r--src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts25
-rw-r--r--src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts25
-rw-r--r--src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts23
4 files changed, 75 insertions, 2 deletions
diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts
index b519099a..4a9cff4a 100644
--- a/src/util/entities/Message.ts
+++ b/src/util/entities/Message.ts
@@ -192,8 +192,8 @@ export class Message extends BaseClass {
 		party_id: string;
 	};
 
-	@Column({ nullable: true })
-	flags?: number;
+	@Column({ default: 0 })
+	flags: number;
 
 	@Column({ type: "simple-json", nullable: true })
 	message_reference?: {
diff --git a/src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts b/src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts
new file mode 100644
index 00000000..7be2ad70
--- /dev/null
+++ b/src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts
@@ -0,0 +1,25 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class MessageFlagsNotNull1713116476900 implements MigrationInterface {
+	name = "MessageFlagsNotNull1713116476900";
+
+	public async up(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(
+			"ALTER TABLE `messages` CHANGE flags flags_old integer;",
+		);
+		await queryRunner.query(
+			"ALTER TABLE `messages` ADD flags integer NOT NULL DEFAULT 0;",
+		);
+		await queryRunner.query(
+			"UPDATE `messages` SET flags = IFNULL(flags_old, 0);",
+		);
+		await queryRunner.query(
+			"ALTER TABLE `messages` DROP COLUMN flags_old;",
+		);
+	}
+
+	public async down(): Promise<void> {
+		// dont care
+		throw new Error("Migration down is not implemented.");
+	}
+}
diff --git a/src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts b/src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts
new file mode 100644
index 00000000..7be2ad70
--- /dev/null
+++ b/src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts
@@ -0,0 +1,25 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class MessageFlagsNotNull1713116476900 implements MigrationInterface {
+	name = "MessageFlagsNotNull1713116476900";
+
+	public async up(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(
+			"ALTER TABLE `messages` CHANGE flags flags_old integer;",
+		);
+		await queryRunner.query(
+			"ALTER TABLE `messages` ADD flags integer NOT NULL DEFAULT 0;",
+		);
+		await queryRunner.query(
+			"UPDATE `messages` SET flags = IFNULL(flags_old, 0);",
+		);
+		await queryRunner.query(
+			"ALTER TABLE `messages` DROP COLUMN flags_old;",
+		);
+	}
+
+	public async down(): Promise<void> {
+		// dont care
+		throw new Error("Migration down is not implemented.");
+	}
+}
diff --git a/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts b/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts
new file mode 100644
index 00000000..026b069b
--- /dev/null
+++ b/src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts
@@ -0,0 +1,23 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class MessageFlagsNotNull1713116476900 implements MigrationInterface {
+	name = "MessageFlagsNotNull1713116476900";
+
+	public async up(queryRunner: QueryRunner): Promise<void> {
+		await queryRunner.query(
+			"ALTER TABLE messages RENAME COLUMN flags TO flags_old;",
+		);
+		await queryRunner.query(
+			"ALTER TABLE messages ADD COLUMN flags integer NOT NULL DEFAULT 0;",
+		);
+		await queryRunner.query(
+			"UPDATE messages SET flags = COALESCE(flags_old, 0);",
+		);
+		await queryRunner.query("ALTER TABLE messages DROP COLUMN flags_old;");
+	}
+
+	public async down(): Promise<void> {
+		// dont care
+		throw new Error("Migration down is not implemented.");
+	}
+}