Reorganize project. Add folder for shared code between backend/dashboard. Switch from jest to ava for tests.
This commit is contained in:
parent
80a82fe348
commit
16111bbe84
162 changed files with 11056 additions and 9900 deletions
112
backend/src/migrations/1540519249973-CreatePreTypeORMTables.ts
Normal file
112
backend/src/migrations/1540519249973-CreatePreTypeORMTables.ts
Normal file
|
@ -0,0 +1,112 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class CreatePreTypeORMTables1540519249973 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`archives\` (
|
||||
\`id\` VARCHAR(36) NOT NULL,
|
||||
\`guild_id\` VARCHAR(20) NOT NULL,
|
||||
\`body\` MEDIUMTEXT NOT NULL,
|
||||
\`created_at\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`expires_at\` DATETIME NULL DEFAULT NULL,
|
||||
PRIMARY KEY (\`id\`)
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`cases\` (
|
||||
\`id\` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
\`guild_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`case_number\` INT(10) UNSIGNED NOT NULL,
|
||||
\`user_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`user_name\` VARCHAR(128) NOT NULL,
|
||||
\`mod_id\` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
|
||||
\`mod_name\` VARCHAR(128) NULL DEFAULT NULL,
|
||||
\`type\` INT(10) UNSIGNED NOT NULL,
|
||||
\`audit_log_id\` BIGINT(20) NULL DEFAULT NULL,
|
||||
\`created_at\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`),
|
||||
UNIQUE INDEX \`mod_actions_guild_id_case_number_unique\` (\`guild_id\`, \`case_number\`),
|
||||
UNIQUE INDEX \`mod_actions_audit_log_id_unique\` (\`audit_log_id\`),
|
||||
INDEX \`mod_actions_user_id_index\` (\`user_id\`),
|
||||
INDEX \`mod_actions_mod_id_index\` (\`mod_id\`),
|
||||
INDEX \`mod_actions_created_at_index\` (\`created_at\`)
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`case_notes\` (
|
||||
\`id\` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
\`case_id\` INT(10) UNSIGNED NOT NULL,
|
||||
\`mod_id\` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
|
||||
\`mod_name\` VARCHAR(128) NULL DEFAULT NULL,
|
||||
\`body\` TEXT NOT NULL,
|
||||
\`created_at\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`id\`),
|
||||
INDEX \`mod_action_notes_mod_action_id_index\` (\`case_id\`),
|
||||
INDEX \`mod_action_notes_mod_id_index\` (\`mod_id\`),
|
||||
INDEX \`mod_action_notes_created_at_index\` (\`created_at\`)
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`mutes\` (
|
||||
\`guild_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`user_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`created_at\` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
\`expires_at\` DATETIME NULL DEFAULT NULL,
|
||||
\`case_id\` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
PRIMARY KEY (\`guild_id\`, \`user_id\`),
|
||||
INDEX \`mutes_expires_at_index\` (\`expires_at\`),
|
||||
INDEX \`mutes_case_id_foreign\` (\`case_id\`),
|
||||
CONSTRAINT \`mutes_case_id_foreign\` FOREIGN KEY (\`case_id\`) REFERENCES \`cases\` (\`id\`)
|
||||
ON DELETE SET NULL
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`persisted_data\` (
|
||||
\`guild_id\` VARCHAR(20) NOT NULL,
|
||||
\`user_id\` VARCHAR(20) NOT NULL,
|
||||
\`roles\` VARCHAR(1024) NULL DEFAULT NULL,
|
||||
\`nickname\` VARCHAR(255) NULL DEFAULT NULL,
|
||||
\`is_voice_muted\` INT(11) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (\`guild_id\`, \`user_id\`)
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`reaction_roles\` (
|
||||
\`guild_id\` VARCHAR(20) NOT NULL,
|
||||
\`channel_id\` VARCHAR(20) NOT NULL,
|
||||
\`message_id\` VARCHAR(20) NOT NULL,
|
||||
\`emoji\` VARCHAR(20) NOT NULL,
|
||||
\`role_id\` VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (\`guild_id\`, \`channel_id\`, \`message_id\`, \`emoji\`),
|
||||
INDEX \`reaction_roles_message_id_emoji_index\` (\`message_id\`, \`emoji\`)
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
CREATE TABLE IF NOT EXISTS \`tags\` (
|
||||
\`guild_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`tag\` VARCHAR(64) NOT NULL,
|
||||
\`user_id\` BIGINT(20) UNSIGNED NOT NULL,
|
||||
\`body\` TEXT NOT NULL,
|
||||
\`created_at\` DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (\`guild_id\`, \`tag\`)
|
||||
)
|
||||
COLLATE = 'utf8mb4_general_ci'
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
// No down function since we're migrating (hehe) from another migration system (knex)
|
||||
}
|
||||
}
|
72
backend/src/migrations/1543053430712-CreateMessagesTable.ts
Normal file
72
backend/src/migrations/1543053430712-CreateMessagesTable.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateMessagesTable1543053430712 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "messages",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "is_bot",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "data",
|
||||
type: "mediumtext",
|
||||
},
|
||||
{
|
||||
name: "posted_at",
|
||||
type: "datetime(3)",
|
||||
},
|
||||
{
|
||||
name: "deleted_at",
|
||||
type: "datetime(3)",
|
||||
isNullable: true,
|
||||
default: null,
|
||||
},
|
||||
{
|
||||
name: "is_permanent",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
default: 0,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{ columnNames: ["guild_id"] },
|
||||
{ columnNames: ["channel_id"] },
|
||||
{ columnNames: ["user_id"] },
|
||||
{ columnNames: ["is_bot"] },
|
||||
{ columnNames: ["posted_at"] },
|
||||
{ columnNames: ["deleted_at"] },
|
||||
{ columnNames: ["is_permanent"] },
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("messages");
|
||||
}
|
||||
}
|
70
backend/src/migrations/1544877081073-CreateSlowmodeTables.ts
Normal file
70
backend/src/migrations/1544877081073-CreateSlowmodeTables.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateSlowmodeTables1544877081073 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "slowmode_channels",
|
||||
columns: [
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "slowmode_seconds",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
},
|
||||
],
|
||||
indices: [],
|
||||
}),
|
||||
);
|
||||
await queryRunner.createPrimaryKey("slowmode_channels", ["guild_id", "channel_id"]);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "slowmode_users",
|
||||
columns: [
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "expires_at",
|
||||
type: "datetime",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["expires_at"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
await queryRunner.createPrimaryKey("slowmode_users", ["guild_id", "channel_id", "user_id"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await Promise.all([
|
||||
queryRunner.dropTable("slowmode_channels", true),
|
||||
queryRunner.dropTable("slowmode_users", true),
|
||||
]);
|
||||
}
|
||||
}
|
85
backend/src/migrations/1544887946307-CreateStarboardTable.ts
Normal file
85
backend/src/migrations/1544887946307-CreateStarboardTable.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateStarboardTable1544887946307 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
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,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "starboard_messages",
|
||||
columns: [
|
||||
{
|
||||
name: "starboard_id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "message_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "starboard_message_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
await queryRunner.createPrimaryKey("starboard_messages", ["starboard_id", "message_id"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("starboards", true);
|
||||
await queryRunner.dropTable("starboard_messages", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateTagResponsesTable1546770935261 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "tag_responses",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "command_message_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "response_message_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id"],
|
||||
},
|
||||
],
|
||||
foreignKeys: [
|
||||
{
|
||||
columnNames: ["command_message_id"],
|
||||
referencedTableName: "messages",
|
||||
referencedColumnNames: ["id"],
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
{
|
||||
columnNames: ["response_message_id"],
|
||||
referencedTableName: "messages",
|
||||
referencedColumnNames: ["id"],
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("tag_responses");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateNameHistoryTable1546778415930 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "name_history",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "type",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "value",
|
||||
type: "varchar",
|
||||
length: "128",
|
||||
isNullable: true,
|
||||
},
|
||||
{
|
||||
name: "timestamp",
|
||||
type: "datetime",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "user_id"],
|
||||
},
|
||||
{
|
||||
columnNames: ["type"],
|
||||
},
|
||||
{
|
||||
columnNames: ["timestamp"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("name_history");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class MakeNameHistoryValueLengthLonger1546788508314 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`name_history\`
|
||||
CHANGE COLUMN \`value\` \`value\` VARCHAR(160) NULL DEFAULT NULL COLLATE 'utf8mb4_swedish_ci' AFTER \`type\`;
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`name_history\`
|
||||
CHANGE COLUMN \`value\` \`value\` VARCHAR(128) NULL DEFAULT NULL COLLATE 'utf8mb4_swedish_ci' AFTER \`type\`;
|
||||
`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateAutoReactionsTable1547290549908 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "auto_reactions",
|
||||
columns: [
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "reactions",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
await queryRunner.createPrimaryKey("auto_reactions", ["guild_id", "channel_id"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("auto_reactions", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreatePingableRolesTable1547293464842 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "pingable_roles",
|
||||
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: "role_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "channel_id"],
|
||||
},
|
||||
{
|
||||
columnNames: ["guild_id", "channel_id", "role_id"],
|
||||
isUnique: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("pingable_roles", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import { MigrationInterface, QueryRunner, TableColumn, TableIndex } from "typeorm";
|
||||
|
||||
export class AddIndexToArchivesExpiresAt1547392046629 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createIndex(
|
||||
"archives",
|
||||
new TableIndex({
|
||||
columnNames: ["expires_at"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropIndex(
|
||||
"archives",
|
||||
new TableIndex({
|
||||
columnNames: ["expires_at"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
25
backend/src/migrations/1547393619900-AddIsHiddenToCases.ts
Normal file
25
backend/src/migrations/1547393619900-AddIsHiddenToCases.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { MigrationInterface, QueryRunner, TableColumn, TableIndex } from "typeorm";
|
||||
|
||||
export class AddIsHiddenToCases1547393619900 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.addColumn(
|
||||
"cases",
|
||||
new TableColumn({
|
||||
name: "is_hidden",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
default: 0,
|
||||
}),
|
||||
);
|
||||
await queryRunner.createIndex(
|
||||
"cases",
|
||||
new TableIndex({
|
||||
columnNames: ["is_hidden"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropColumn("cases", "is_hidden");
|
||||
}
|
||||
}
|
19
backend/src/migrations/1549649586803-AddPPFieldsToCases.ts
Normal file
19
backend/src/migrations/1549649586803-AddPPFieldsToCases.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddPPFieldsToCases1549649586803 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`cases\`
|
||||
ADD COLUMN \`pp_id\` BIGINT NULL,
|
||||
ADD COLUMN \`pp_name\` VARCHAR(128) NULL
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`cases\`
|
||||
DROP COLUMN \`pp_id\`,
|
||||
DROP COLUMN \`pp_name\`
|
||||
`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class FixEmojiIndexInReactionRoles1550409894008 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
// In utf8mb4_swedish_ci, different native emojis are counted as the same char for indexes, which means we can't
|
||||
// have multiple native emojis on a single message since the emoji field is part of the primary key
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`reaction_roles\`
|
||||
CHANGE COLUMN \`emoji\` \`emoji\` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_bin' AFTER \`message_id\`
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`reaction_roles\`
|
||||
CHANGE COLUMN \`emoji\` \`emoji\` VARCHAR(64) NOT NULL AFTER \`message_id\`
|
||||
`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateSelfGrantableRolesTable1550521627877 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "self_grantable_roles",
|
||||
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: "role_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "aliases",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "channel_id", "role_id"],
|
||||
isUnique: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("self_grantable_roles", true);
|
||||
}
|
||||
}
|
53
backend/src/migrations/1550609900261-CreateRemindersTable.ts
Normal file
53
backend/src/migrations/1550609900261-CreateRemindersTable.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateRemindersTable1550609900261 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "reminders",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "remind_at",
|
||||
type: "datetime",
|
||||
},
|
||||
{
|
||||
name: "body",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "user_id"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("reminders", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateUsernameHistoryTable1556908589679 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "username_history",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "username",
|
||||
type: "varchar",
|
||||
length: "160",
|
||||
isNullable: true,
|
||||
},
|
||||
{
|
||||
name: "timestamp",
|
||||
type: "datetime",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["user_id"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("username_history", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
const BATCH_SIZE = 200;
|
||||
|
||||
export class MigrateUsernamesToNewHistoryTable1556909512501 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
// Start by ending the migration transaction because this is gonna be a looooooooot of data
|
||||
await queryRunner.query("COMMIT");
|
||||
|
||||
const migratedUsernames = new Set();
|
||||
|
||||
await new Promise(async resolve => {
|
||||
const stream = await queryRunner.stream("SELECT CONCAT(user_id, '-', username) AS `key` FROM username_history");
|
||||
stream.on("result", row => {
|
||||
migratedUsernames.add(row.key);
|
||||
});
|
||||
stream.on("end", resolve);
|
||||
});
|
||||
|
||||
const migrateNextBatch = (): Promise<{ finished: boolean; migrated?: number }> => {
|
||||
return new Promise(async resolve => {
|
||||
const toInsert = [];
|
||||
const toDelete = [];
|
||||
|
||||
const stream = await queryRunner.stream(
|
||||
`SELECT * FROM name_history WHERE type=1 ORDER BY timestamp ASC LIMIT ${BATCH_SIZE}`,
|
||||
);
|
||||
stream.on("result", row => {
|
||||
const key = `${row.user_id}-${row.value}`;
|
||||
|
||||
if (!migratedUsernames.has(key)) {
|
||||
migratedUsernames.add(key);
|
||||
toInsert.push([row.user_id, row.value, row.timestamp]);
|
||||
}
|
||||
|
||||
toDelete.push(row.id);
|
||||
});
|
||||
stream.on("end", async () => {
|
||||
if (toInsert.length || toDelete.length) {
|
||||
await queryRunner.query("START TRANSACTION");
|
||||
|
||||
if (toInsert.length) {
|
||||
await queryRunner.query(
|
||||
"INSERT INTO username_history (user_id, username, timestamp) VALUES " +
|
||||
Array.from({ length: toInsert.length }, () => "(?, ?, ?)").join(","),
|
||||
toInsert.flat(),
|
||||
);
|
||||
}
|
||||
|
||||
if (toDelete.length) {
|
||||
await queryRunner.query(
|
||||
"DELETE FROM name_history WHERE id IN (" + Array.from("?".repeat(toDelete.length)).join(", ") + ")",
|
||||
toDelete,
|
||||
);
|
||||
}
|
||||
|
||||
await queryRunner.query("COMMIT");
|
||||
|
||||
resolve({ finished: false, migrated: toInsert.length });
|
||||
} else {
|
||||
resolve({ finished: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
while (true) {
|
||||
const result = await migrateNextBatch();
|
||||
if (result.finished) {
|
||||
break;
|
||||
} else {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(`Migrated ${result.migrated} usernames`);
|
||||
}
|
||||
}
|
||||
|
||||
await queryRunner.query("START TRANSACTION");
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-empty
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||
|
||||
export class TurnNameHistoryToNicknameHistory1556913287547 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropColumn("name_history", "type");
|
||||
|
||||
// As a raw query because of some bug with renameColumn that generated an invalid query
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`name_history\`
|
||||
CHANGE COLUMN \`value\` \`nickname\` VARCHAR(160) NULL DEFAULT 'NULL' COLLATE 'utf8mb4_swedish_ci' AFTER \`user_id\`;
|
||||
`);
|
||||
|
||||
// Drop unneeded timestamp column index
|
||||
await queryRunner.dropIndex("name_history", "IDX_6bd0600f9d55d4e4a08b508999");
|
||||
|
||||
await queryRunner.renameTable("name_history", "nickname_history");
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.addColumn(
|
||||
"nickname_history",
|
||||
new TableColumn({
|
||||
name: "type",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
}),
|
||||
);
|
||||
|
||||
// As a raw query because of some bug with renameColumn that generated an invalid query
|
||||
await queryRunner.query(`
|
||||
ALTER TABLE \`nickname_history\`
|
||||
CHANGE COLUMN \`nickname\` \`value\` VARCHAR(160) NULL DEFAULT 'NULL' COLLATE 'utf8mb4_swedish_ci' AFTER \`user_id\`
|
||||
`);
|
||||
|
||||
await queryRunner.renameTable("nickname_history", "name_history");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateScheduledPostsTable1556973844545 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "scheduled_posts",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "author_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "author_name",
|
||||
type: "varchar",
|
||||
length: "160",
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "content",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "attachments",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "post_at",
|
||||
type: "datetime",
|
||||
},
|
||||
{
|
||||
name: "enable_mentions",
|
||||
type: "tinyint",
|
||||
unsigned: true,
|
||||
default: 0,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "post_at"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("scheduled_posts", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateDashboardLoginsTable1558804433320 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "dashboard_logins",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "varchar",
|
||||
length: "36",
|
||||
isPrimary: true,
|
||||
collation: "ascii_bin",
|
||||
},
|
||||
{
|
||||
name: "token",
|
||||
type: "varchar",
|
||||
length: "64",
|
||||
collation: "ascii_bin",
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
},
|
||||
{
|
||||
name: "user_data",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "logged_in_at",
|
||||
type: "DATETIME",
|
||||
},
|
||||
{
|
||||
name: "expires_at",
|
||||
type: "DATETIME",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["user_id"],
|
||||
},
|
||||
{
|
||||
columnNames: ["expires_at"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("dashboard_logins", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";
|
||||
|
||||
export class CreateDashboardUsersTable1558804449510 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "dashboard_users",
|
||||
columns: [
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
},
|
||||
{
|
||||
name: "username",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
},
|
||||
{
|
||||
name: "role",
|
||||
type: "varchar",
|
||||
length: "32",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createPrimaryKey("dashboard_users", ["guild_id", "user_id"]);
|
||||
await queryRunner.createIndex(
|
||||
"dashboard_users",
|
||||
new TableIndex({
|
||||
columnNames: ["user_id"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("dashboard_users", true);
|
||||
}
|
||||
}
|
51
backend/src/migrations/1561111990357-CreateConfigsTable.ts
Normal file
51
backend/src/migrations/1561111990357-CreateConfigsTable.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";
|
||||
|
||||
export class CreateConfigsTable1561111990357 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "configs",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "key",
|
||||
type: "varchar",
|
||||
length: "48",
|
||||
},
|
||||
{
|
||||
name: "config",
|
||||
type: "mediumtext",
|
||||
},
|
||||
{
|
||||
name: "is_active",
|
||||
type: "tinyint",
|
||||
},
|
||||
{
|
||||
name: "edited_by",
|
||||
type: "bigint",
|
||||
},
|
||||
{
|
||||
name: "edited_at",
|
||||
type: "datetime",
|
||||
default: "now()",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["key", "is_active"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("configs", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateAllowedGuildsTable1561117545258 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "allowed_guilds",
|
||||
columns: [
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
},
|
||||
{
|
||||
name: "icon",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
collation: "ascii_general_ci",
|
||||
isNullable: true,
|
||||
},
|
||||
{
|
||||
name: "owner_id",
|
||||
type: "bigint",
|
||||
},
|
||||
],
|
||||
indices: [{ columnNames: ["owner_id"] }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("allowed_guilds", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class RenameBackendDashboardStuffToAPI1561282151982 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE dashboard_users RENAME api_users`);
|
||||
await queryRunner.query(`ALTER TABLE dashboard_logins RENAME api_logins`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE api_users RENAME dashboard_users`);
|
||||
await queryRunner.query(`ALTER TABLE api_logins RENAME dashboard_logins`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class RenameAllowedGuildGuildIdToId1561282552734 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query("ALTER TABLE `allowed_guilds` CHANGE COLUMN `guild_id` `id` BIGINT(20) NOT NULL FIRST;");
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query("ALTER TABLE `allowed_guilds` CHANGE COLUMN `id` `guild_id` BIGINT(20) NOT NULL FIRST;");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class CreateApiUserInfoTable1561282950483 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "api_user_info",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "bigint",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "data",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "updated_at",
|
||||
type: "datetime",
|
||||
default: "now()",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("api_user_info", true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class RenameApiUsersToApiPermissions1561283165823 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE api_users RENAME api_permissions`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(`ALTER TABLE api_permissions RENAME api_users`);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class DropUserDataFromLoginsAndPermissions1561283405201 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query("ALTER TABLE `api_logins` DROP COLUMN `user_data`");
|
||||
await queryRunner.query("ALTER TABLE `api_permissions` DROP COLUMN `username`");
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.query(
|
||||
"ALTER TABLE `api_logins` ADD COLUMN `user_data` TEXT NOT NULL COLLATE 'utf8mb4_swedish_ci' AFTER `user_id`",
|
||||
);
|
||||
await queryRunner.query(
|
||||
"ALTER TABLE `api_permissions` ADD COLUMN `username` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_swedish_ci' AFTER `user_id`",
|
||||
);
|
||||
}
|
||||
}
|
58
backend/src/migrations/1561391921385-AddVCAlertTable.ts
Normal file
58
backend/src/migrations/1561391921385-AddVCAlertTable.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { MigrationInterface, QueryRunner, Table } from "typeorm";
|
||||
|
||||
export class AddVCAlertTable1561391921385 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "vc_alerts",
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "int",
|
||||
unsigned: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "guild_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "requestor_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "user_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "channel_id",
|
||||
type: "bigint",
|
||||
unsigned: true,
|
||||
},
|
||||
{
|
||||
name: "expires_at",
|
||||
type: "datetime",
|
||||
},
|
||||
{
|
||||
name: "body",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
{
|
||||
columnNames: ["guild_id", "user_id"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
await queryRunner.dropTable("vc_alerts", true, false, true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
import { MigrationInterface, QueryRunner, TableIndex } from "typeorm";
|
||||
|
||||
export class AddMoreIndicesToVCAlerts1562838838927 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
const table = await queryRunner.getTable("vc_alerts");
|
||||
await table.addIndex(
|
||||
new TableIndex({
|
||||
columnNames: ["requestor_id"],
|
||||
}),
|
||||
);
|
||||
await table.addIndex(
|
||||
new TableIndex({
|
||||
columnNames: ["expires_at"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
const table = await queryRunner.getTable("vc_alerts");
|
||||
await table.removeIndex(
|
||||
new TableIndex({
|
||||
columnNames: ["requestor_id"],
|
||||
}),
|
||||
);
|
||||
await table.removeIndex(
|
||||
new TableIndex({
|
||||
columnNames: ["expires_at"],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue