3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Finished Starboard (Pre Override test)

This commit is contained in:
Nils Blömeke 2019-11-09 00:48:38 +01:00
parent 92402662e6
commit d82f5fbc46
9 changed files with 464 additions and 244 deletions

View file

@ -0,0 +1,103 @@
import { MigrationInterface, QueryRunner, Table, TableColumn, createQueryBuilder } from "typeorm";
export class MoveStarboardsToConfig1573248462469 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
// Create the new column for the channels id
const chanid_column = new TableColumn({
name: "starboard_channel_id",
type: "bigint",
unsigned: true,
});
await queryRunner.addColumn("starboard_messages", chanid_column);
// Since we are removing the guild_id with the starboards table, we might want it here
const guid_column = new TableColumn({
name: "guild_id",
type: "bigint",
unsigned: true,
});
await queryRunner.addColumn("starboard_messages", guid_column);
// Migrate the old starboard_id to the new starboard_channel_id
await queryRunner.query(`
UPDATE starboard_messages AS sm
JOIN starboards AS sb
ON sm.starboard_id = sb.id
SET sm.starboard_channel_id = sb.channel_id, sm.guild_id = sb.guild_id;
`);
// Drop the starboard_id column as it is now obsolete
await queryRunner.dropColumn("starboard_messages", "starboard_id");
// Set new Primary Key
await queryRunner.dropPrimaryKey("starboard_messages");
await queryRunner.createPrimaryKey("starboard_messages", ["starboard_message_id"]);
// Finally, drop the starboards channel as it is now obsolete
await queryRunner.dropTable("starboards", true);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn("starboard_messages", "starboard_channel_id");
await queryRunner.dropColumn("starboard_messages", "guild_id");
const sbId = new TableColumn({
name: "starboard_id",
type: "int",
unsigned: true,
});
await queryRunner.addColumn("starboard_messages", sbId);
await queryRunner.dropPrimaryKey("starboard_messages");
await queryRunner.createPrimaryKey("starboard_messages", ["starboard_id", "message_id"]);
await queryRunner.createTable(
new Table({
name: "starboards",
columns: [
{
name: "id",
type: "int",
unsigned: true,
isGenerated: true,
generationStrategy: "increment",
isPrimary: true,
},
{
name: "guild_id",
type: "bigint",
unsigned: true,
},
{
name: "channel_id",
type: "bigint",
unsigned: true,
},
{
name: "channel_whitelist",
type: "text",
isNullable: true,
default: null,
},
{
name: "emoji",
type: "varchar",
length: "64",
},
{
name: "reactions_required",
type: "smallint",
unsigned: true,
},
],
indices: [
{
columnNames: ["guild_id", "emoji"],
},
{
columnNames: ["guild_id", "channel_id"],
isUnique: true,
},
],
}),
);
}
}

View file

@ -0,0 +1,44 @@
import { MigrationInterface, QueryRunner, Table } from "typeorm";
export class CreateStarboardReactionsTable1573248794313 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.createTable(
new Table({
name: "starboard_reactions",
columns: [
{
name: "id",
type: "int",
isGenerated: true,
generationStrategy: "increment",
isPrimary: true,
},
{
name: "guild_id",
type: "bigint",
unsigned: true,
},
{
name: "message_id",
type: "bigint",
unsigned: true,
},
{
name: "reactor_id",
type: "bigint",
unsigned: true,
},
],
indices: [
{
columnNames: ["reactor_id", "message_id"],
},
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropTable("starboard_reactions", true, false, true);
}
}