Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix message flags being null #1116

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/util/entities/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand Down
25 changes: 25 additions & 0 deletions src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts
Original file line number Diff line number Diff line change
@@ -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.");
}
}
25 changes: 25 additions & 0 deletions src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts
Original file line number Diff line number Diff line change
@@ -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.");
}
}
23 changes: 23 additions & 0 deletions src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Loading