-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1116 from spacebarchat/patch/null-message-flags
Fix message flags being null
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/util/migration/mariadb/1713116476900-messageFlagsNotNull.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
src/util/migration/mysql/1713116476900-messageFlagsNotNull.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
src/util/migration/postgres/1713116476900-messageFlagsNotNull.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |