mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
Fix race conditions and duplicate stars in starboard
This commit is contained in:
parent
1484f6b9a7
commit
e1e1854041
5 changed files with 63 additions and 9 deletions
|
@ -0,0 +1,26 @@
|
|||
import { MigrationInterface, QueryRunner, TableIndex, TableUnique } from "typeorm";
|
||||
|
||||
export class FixStarboardReactionsIndices1608692857722 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
// Remove previously-added duplicate stars
|
||||
await queryRunner.query(`
|
||||
DELETE r1.* FROM starboard_reactions AS r1
|
||||
INNER JOIN starboard_reactions AS r2
|
||||
ON r2.guild_id = r1.guild_id AND r2.message_id = r1.message_id AND r2.reactor_id = r1.reactor_id AND r2.id < r1.id
|
||||
`);
|
||||
|
||||
await queryRunner.dropIndex("starboard_reactions", "IDX_dd871a4ef459dd294aa368e736");
|
||||
await queryRunner.createIndex(
|
||||
"starboard_reactions",
|
||||
new TableIndex({
|
||||
isUnique: true,
|
||||
columnNames: ["guild_id", "message_id", "reactor_id"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropIndex("starboard_reactions", "IDX_d08ee47552c92ec8afd1a5bd1b");
|
||||
await queryRunner.createIndex("starboard_reactions", new TableIndex({ columnNames: ["reactor_id", "message_id"] }));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue