Fix message flags being null

This commit is contained in:
Puyodead1 2024-04-14 14:02:22 -04:00
parent 29df169c81
commit ee59ee7e1c
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
4 changed files with 75 additions and 2 deletions

View File

@ -192,8 +192,8 @@ export class Message extends BaseClass {
party_id: string; party_id: string;
}; };
@Column({ nullable: true }) @Column({ default: 0 })
flags?: number; flags: number;
@Column({ type: "simple-json", nullable: true }) @Column({ type: "simple-json", nullable: true })
message_reference?: { message_reference?: {

View File

@ -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.");
}
}

View File

@ -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.");
}
}

View File

@ -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.");
}
}